Create a Prolog database by typing the facts listed below in
Create a Prolog database by typing the facts listed below in a .pro file. Consult the file in Amzi Prolog. We have a person relation to keep track of the person’s id number, name, gender and age.
The facts for this relation are:
person (1, john, M, 20).
person (2, mary, F, 22).
person (3, jack, M, 21).
person (4, tina, F, 30).
person (5, ted, M, 19).
We have an activities relation to keep track of an activity’s id number, name, hours per session and cost.
The facts for this relation are:
activity (a1, swimming, 1, 40).
activity (a2, yoga, 2, 80).
activity (a3, origami, 1, 25).
activity (a4, tennis, 2, 90).
Finally, we have a volunteers relation which keeps track of the id of a person volunteering to help with an activity, the id of the activity and the day in which the person volunteers.
The facts for this relation are:
volunteers (1, a1, tuesday).
volunteers (2, a2, wednesday).
volunteers (3, a1, monday).
volunteers (4, a2, thursday).
volunteers (5, a1, wednesday).
volunteers (1, a2, tuesday).
volunteers (2, a1, wednesday).
volunteers (3, a2, thursday).
volunteers (4, a1, monday).
volunteers (5, a2, thursday).
volunteers (1, a3, friday).
volunteers (2, a4, thursday).
volunteers (3, a3, monday).
volunteers (4, a4, saturday).
volunteers (5, a3, tuesday).
Write the following predicates and test them in Amzi Prolog:
The predicate listPersonIds should return the ids and names of all persons who have indicated that they are willing to volunteer.
The predicate findVolunteerDay will ask the user (using read) to enter a person’s name and an activity and will print (using write) the day that the person volunteers for the activity.
Thanks a lot for your help!!!
Solution
Prolog mainly has four types of data manipulation commands. They are as follows:
prolog database by using facts for this relations:
Id(1)
Id(2)
Id(3)
Id(4)
Id(5)
name(1, john)
name(2,mary)
name(3,jack)
name(4,tina)
name(5,ted)
gender(john, M)
gender(mary, F)
gender(jack, M)
gender(tina, F)
gender(ted, M)
age(john,20)
age(mary,22)
age(jack,21)
age(tina,30)
age(ted,19)
activity(a1, swimming)
activity(a2, yoga)
activity(a3, origami)
activity(a4, tennis)
hours per session(a1,1)
hours per session(a2,2)
hours per session(a3,1)
hours per session(a4,2)
activity cost(a1,40)
activity cost(a2,80)
activity cost(a3,25)
activity cost(a4,90)
volunteers for activities(1, a1,a2,a3)
volunteers for activities(2,a1,a2,a4)
volunteers for activities(3,a1,a2,a3)
volunteers for activities(4,a1,a2,a4)
volunteers for activities(5,a1,a2,a3)
working day for id (monday,3,4)
working day for id (tuesday,1,5)
working day for id (wednesday, 2,5)
working day for id (thursday, 2,3,5)
working day for id (friday ,1)
working day for id (saturday, 4)
activity working day( a1,monday,tuesday,wednesday)
activity working day (a2,tuesday,wednesday,thursday)
activity working day (a3,monday,tuesday,friday)
activity working day(a4,thursday,saturday)


