%trace
domains
subject = string*
database-teacher
teacher_subject(string,subject)
database-lectures
subject_lectures(string,integer)
predicates
insert_details
find_total_lectures(string)
find_lecture_count(subject,integer,integer)
clauses
insert_details:-
retractall(teacher_subject(_,_)),
retractall(subject_lectures(_,_)),
assert(teacher_subject(btsir,[ai,nt])),
assert(teacher_subject(harshalsir,[cg,ss])),
assert(subject_lectures(ai,10)),
assert(subject_lectures(nt,20)),
assert(subject_lectures(cg,5)),
assert(subject_lectures(ss,9)).
find_lecture_count([],Start,Start).
find_lecture_count([Head|Tail],Start,Count):-
subject_lectures(Head,Num),
NewCount = Num + Start,
find_lecture_count(Tail,NewCount,Count).
find_total_lectures(Teacher):-
teacher_subject(Teacher,Subjects),
find_lecture_count(Subjects,0,Count),
write("Total Lectures for ",Teacher," are ",Count).
goal
clearwindow,
makewindow(1,2,3,"Teacher Lecture Count",0,0,25,80),
insert_details,
find_total_lectures(btsir),
nl,
find_total_lectures(harshalsir).
Output
+-----------------------------Teacher Lecture Count---------------------------+
¦Total Lectures for btsir are 30 ¦
¦Total Lectures for harshalsir are 14 ¦
¦Press the SPACE bar ¦
¦ ¦
¦ ¦
+-----------------------------------------------------------------------------+