Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to create a database of Employees containing EmpNo, EmpName, Emp Spouse Name, children and print Employee children having a given age

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

Create a database of Employees containing EmpNo, EmpName, Emp Spouse Name, List containing name of children of the employee and the age of it. Now, print Employee children having a given age.

Code for Prolog program to create a database of Employees containing EmpNo, EmpName, Emp Spouse Name, children and print Employee children having a given age in Artificial Intelligence


%trace
domains
    child_details = child(string,integer)
    children = child_details*
    
database
    employee(integer,string,string,children)

predicates
    print_employee(integer)
    insert_details
    find_children(children,integer)
clauses

    insert_details:-
        retractall(employee(_,_,_,_)),
        assert(employee(1,emp1,emp3,[child(e1child1,10), child(e1child2,20)])),
        assert(employee(2,emp2,emp4,[child(e2child2,20)])),
        assert(employee(3,emp5,emp6,[child(e2child3,10)])).

    find_children([],ChildAge):- fail.
    
    find_children([child(Name,Age)|Tail],ChildAge):-
        Age = ChildAge.
    
    find_children([child(Name,Age)|Tail],ChildAge):-
        Age <> ChildAge,
        find_children(Tail,ChildAge).
        
        
    print_employee(ChildAge):-
        employee(EmpNo,EmpName,SpouseName,ChildrenList),
        find_children(ChildrenList,ChildAge),
        write(EmpName),
        nl,
        fail.
        
    print_employee(ChildAge).
        
goal
    clearwindow,
    makewindow(1,2,3,"Employee Children",0,0,25,80),
    insert_details,
    write("Following are the employees whose children are of age 10"),
    nl,
    print_employee(10).


Output

+-------------------------------Employee Children-----------------------------+
¦Following are the employees whose children are of age 10                     ¦
¦emp1                                                                         ¦
¦emp5                                                                         ¦
¦                                                                             ¦
¦Press the SPACE bar                                                          ¦
¦                                                                             ¦
¦                                                                             ¦
+-----------------------------------------------------------------------------+

  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to create a database of Employees containing EmpNo, EmpName, Emp Spouse Name, children and print Employee children having a given age 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!