Beruflich Dokumente
Kultur Dokumente
CONFIDENTIAL
COURSE
COURSE CODE
CSC563
EXAMINATION
JANUARY 2012
TIME
3 HOURS
INSTRUCTIONS TO CANDIDATES
1.
2.
Answer ALL questions in the Answer Booklet. Start each answer on a new page.
3.
Do not bring any material into the examination room unless permission is given by the
invigilator.
Please check to make sure that this examination pack consists of:
i)
ii)
CONFIDENTIAL
CONFIDENTIAL
CS/JAN 2012/CSC563
QUESTION 1
a)
Describe THREE (3) differences between Prolog and Java programming language.
(6 marks)
b)
Declarative
Procedural
Backtracking
Recursive
Cut
(10 marks)
QUESTION 2
Give the answer for the queries below:
a)
?- w = 10+11+12.
b)
C)
d)
e)
f)
g)
? - X i s 13 + 14 + 1 5 .
? - Y == 16 + 17 + 1 8 .
?- var(Z) , Z= 9.
?- 0.9*1000 =:= 9*100.
? - [ 1 , 2 | [3 | [ 4 ] ] ] = [A| [ B , C | [ D ] ] ] , C i s
?- t p , q , r , s ] = [Z,_|T] .
A+B.
?-
[[w,x] , [ y , z ] ] = [A,B|T] .
(10 marks)
QUESTION 3
Assume a Prolog database contains facts for male/1, female/1 and parent/2. Define the
following relations in Prolog.
a)
b)
c)
d)
e)
mother/2
son/2
brother/2
grandfather/2
granddaughter/2
(18 marks)
CONFIDENTIAL
CONFIDENTIAL
CS/JAN 2012/CSC563
QUESTION 4
Consider the following Prolog program:
q(6) .
q(7) :q(10) .
!.
?- q(X) .
? - q(X) , q(Y) .
? - q(X) , ! , q(Y) .
(18 marks)
QUESTION 5
Write a Prolog program to determine whether an integer input is an ODD or an EVEN
number. The program will terminate if the user enter 0. The program should correspond as
follows:
?- s t a r t .
Enter a number: 5.
5 is an odd number.
Enter a number: 4.
4 is an even number.
Enter a number: 0.
Exiting...
(13 marks)
CONFIDENTIAL
CONFIDENTIAL
CS/JAN 2012/CSC563
QUESTION 6
Suppose that a Prolog database contains the following rules and facts:
f ( B , C, D, E) : g ( C , D) , h ( B , A) , i ( A ,
g(C, D ) : j(D), k(C,
E) .
D).
h ( B , A) : k(A, B ) .
h ( B , A) : j(C), j(D),
B is
C+D, k ( B ,
A).
i(C,m(D)):D i s C+l.
j (2) .
j (3) .
k(2,3) .
k(4,4) .
k(5,8) .
f(B,
C,
D,
E).
(25 marks)
CONFIDENTIAL