We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 2
4 Computer Sclences
i pat.tatek scp
Dr. Negm Shawky Nee
3204 Logic Programming (Final Exam)
Try all questions
Question 4 (20 points)
Consider the giving Prolog KB:
7 parents (child, father, mother) */
parents(bart, omer, marge).
parents(is, homer, marge).
parents(magate, homer, marge)
female(mnarge),
|
female(tisa).
female(magaie).
sisterOW(X,¥) = female(Y), parents(YM, W), parentsM,W).
1+ Forthe above KB: Dravv the search tre for the query? -sisterOf{ban, 2), in the order they are produced,
all the answers Prolog would give. (S points)
From the above KB find the Predict the resus of the following query?
2 sisterOf{bart,Z), (5 points) salary[ahmed,1400).
3+ Complete the opposite KB to calculate and show: (5 points) falarylmal 2300).
a. The average selary forthe employees tainad7,
b. A listof salaries (not sorted). salaryla 2400),
c. Alistofnames (sorted), satarylgamal2600).
4+ Write Prolog program has a knowledge base for E-Shorouk Academy studens, and write te following
queries: (S points) -
4. Total number of students by gender.
€. Listof students from a giving govemorate
Average students age
Question 2 (20 points
= The predicate maximum(X, Y,M)is tue if and only if there is only one solution M which i the maximum
integer of X and Y. The following is a variation ofthe definition: (S points)
‘maximum(%, YM) =X>=¥,M=X.
maximum(X, Y,M):=¥ >=X,M= Y.
Js the predicate correct? Are there any cireurmstances when it may fil to give the expected answer? it
does fil, correct the definition inthe simplest possible way,
2- Write predicate fi/2 which represent te following function (using cut predicate): (S points)
ifX<3 then Y=0
if3 =< X and X <6 then ¥=2
i