Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to create a database of teachers containing, TeacherName, List of subjects taught and for given teacher, display no of lectures require

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 4433

Create a database of teachers containing, TeacherName, List of subjects taught Also create a database containing Subject, No of lectures required for that
subject in a week. Now for given teacher, display no of lectures required to be taken by him/her.

Code for Prolog program to create a database of teachers containing, TeacherName, List of subjects taught and for given teacher, display no of lectures require in Artificial Intelligence

%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                                                          ¦
¦                                                                             ¦
¦                                                                             ¦
+-----------------------------------------------------------------------------+

  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to create a database of teachers containing, TeacherName, List of subjects taught and for given teacher, display no of lectures require is from India.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!