predicates
male(symbol).
female(symbol).
father(symbol,symbol).
husband(symbol,symbol).
brother(symbol,symbol).
sister(symbol,symbol).
listbrothers(symbol).
listsisters(symbol).
mother(symbol,symbol).
grandfather(symbol).
grandmother(symbol).
uncle(symbol).
aunt(symbol).
cousin(symbol).
listgrandsons(symbol).
listgranddaughters(symbol).
printmenu.
action(integer).
repeat.
clauses
male(dashrath).
male(ram).
male(laxman).
male(bharat).
male(luv).
male(kush).
male(son_of_laxman).
female(kaushalya).
female(sita).
female(urmila).
female(daughter_of_dashrath).
father(dashrath,ram).
father(dashrath,laxman).
father(dashrath,bharat).
father(ram,luv).
father(ram,kush).
father(laxman,son_of_laxman).
father(dashrath,daughter_of_dashrath).
husband(dashrath,kaushalya).
husband(ram,sita).
husband(laxman,urmila).
mother(X,Y):- husband(Z,X),
father(Z,Y).
brother(X,Y):- father(Z,X),
father(Z,Y),
X<>Y,
male(X).
sister(X,Y):- father(Z,X),
father(Z,Y),
X<>Y,
female(X).
listbrothers(X) :- brother(Z,X),
write(Z).
listsisters(X):- sister(Z,X),
write(Z).
grandfather(X):- father(Y, Z),
father(Z,X),
write(Y, " is the grandfather of ",X,"\n").
grandmother(X):- husband(Z,X),
father(Z,V),
father(V,Y),
write(Y, " is the grandmother of ",X,"\n").
listgrandsons(X):- father(X,Z),
father(Z,Y),
male(Y),
write(Y,"\n"),
fail.
listgrandsons(X):- husband(Y,X),
father(Y,V),
father(V,Z),
male(Z),
write(Z,"\n"),
fail.
listgranddaughters(X):- father(X,Z),
father(Z,Y),
female(Y),
write(Y,"\n"),
fail.
listgranddaughters(X):- husband(Y,X),
father(Y,V),
father(V,Z),
female(Z),
write(Z,"\n"),
fail.
uncle(X):- brother(Z,Y),
father(Z,X),
male(Y),
write(Y,"\n"),
fail.
aunt(X):- husband(Z,Y),
brother(Z,V),
father(V,X),
write(Y,"\n"),
fail.
cousin(X):- father(Z,X),
father(V,Y),
Z<>V,
brother(V,Z),
write(Y,"\n").
repeat.
repeat:- repeat.
action(1):- write("\nEnter name of person whose father is to be found : "),
readln(X),
write("\n"),
write("Father of ",X," is:"),
father(Z,X),
write(Z,"\n"),
fail.
action(2):- write("\nEnter name of person whose mother is to be found : "),
readln(X),
write("\n"),
write("Mother of ",X," is:"),
mother(Z,X),
write(Z,"\n"),
fail.
action(3):- write("\nEnter name of person whose brothers are to be found : "),
readln(X),
write("\n"),
write("Brothers of ",X," are:\n"),
listbrothers(X),
write("\n"),
fail.
action(4):- write("\nEnter name of person whose sisters are to be found : "),
readln(X),
write("\n"),
write("Sisters of ",X," are:\n"),
listsisters(X),
write("\n"),
fail.
action(5):- write("\nEnter name of person whose grandsons are to be found : "),
readln(X),
write("\n"),
write("Grandsons of ",X," are:\n"),
listgrandsons(X),
write("\n"),
fail.
action(6):- write("\nEnter name of person whose granddaughters are to be found : "),
readln(X),
write("\n"),
write("Granddaughters of ",X," are:\n"),
listgranddaughters(X),
write("\n"),
fail.
action(7):- write("\nEnter name of person whose uncles are to be found : "),
readln(X),
write("\n"),
write("Uncles of ",X," are:\n"),
uncle(X),
write("\n"),
fail.
action(8):- write("\nEnter name of person whose aunties are to be found : "),
readln(X),
write("\n"),
write("Aunties of ",X," are:\n"),
aunt(X),
write("\n"),
fail.
action(9):- write("\nEnter name of person whose cousins are to be found : "),
readln(X),
write("\n"),
write("Cousins of ",X," are:\n"),
cousin(X),
write("\n"),
fail.
action(0).
printmenu :-
repeat,
write("\n1. Display Father of?\n"),
write("2. Display Mother of?\n"),
write("3. List all brothers of?\n"),
write("4. List all sisters of?\n"),
write("5. List all grandson of?\n"),
write("6. List all granddaughter of?\n"),
write("7. List all uncles of?\n"),
write("8. List all aunty of?\n"),
write("9. list all cousins of?\n"),
write("0. exit\n"),
write("Enter your choice : "),
readInt(Choice),
action(Choice),
write("\n"),
repeat.
goal
makewindow(1,2,3,"Family Tree",0,0,25,80),
printmenu.
Output
+----------------------------------Family Tree--------------------------------+
¦ ¦
¦1. Display Father of? ¦
¦2. Display Mother of? ¦
¦3. List all brothers of? ¦
¦4. List all sisters of? ¦
¦5. List all grandson of? ¦
¦6. List all granddaughter of? ¦
¦7. List all uncles of? ¦
¦8. List all aunty of? ¦
¦9. list all cousins of? ¦
¦0. exit ¦
¦Enter your choice : 1 ¦
¦ ¦
¦Enter name of person whose father is to be found : ram ¦
¦ ¦
¦Father of ram is:dashrath ¦
¦ ¦
¦1. Display Father of? ¦
¦2. Display Mother of? ¦
¦3. List all brothers of? ¦
¦4. List all sisters of? ¦
¦5. List all grandson of? ¦
¦6. List all granddaughter of? ¦
¦7. List all uncles of? ¦
¦8. List all aunty of? ¦
¦9. list all cousins of? ¦
¦0. exit ¦
¦Enter your choice : 3 ¦
¦ ¦
¦Enter name of person whose brothers are to be found : ram ¦
¦ ¦
¦Brothers of ram are: ¦
¦laxman ¦
¦bharat ¦
¦ ¦
¦1. Display Father of? ¦
¦2. Display Mother of? ¦
¦3. List all brothers of? ¦
¦4. List all sisters of? ¦
¦5. List all grandson of? ¦
¦6. List all granddaughter of? ¦
¦7. List all uncles of? ¦
¦8. List all aunty of? ¦
¦9. list all cousins of? ¦
¦0. exit ¦
¦Enter your choice : 5 ¦
¦ ¦
¦Enter name of person whose grandsons are to be found : dashrath ¦
¦ ¦
¦Grandsons of dashrath are: ¦
¦luv ¦
¦kush ¦
¦son_of_laxman ¦
¦ ¦
¦1. Display Father of? ¦
¦2. Display Mother of? ¦
¦3. List all brothers of? ¦
¦4. List all sisters of? ¦
¦5. List all grandson of? ¦
¦6. List all granddaughter of? ¦
¦7. List all uncles of? ¦
¦8. List all aunty of? ¦
¦9. list all cousins of? ¦
¦0. exit ¦
¦Enter your choice : 7 ¦
¦ ¦
¦Enter name of person whose uncles are to be found : kush ¦
¦ ¦
¦Uncles of kush are: ¦
¦laxman ¦
¦bharat ¦
¦ ¦
¦1. Display Father of? ¦
¦2. Display Mother of? ¦
¦3. List all brothers of? ¦
¦4. List all sisters of? ¦
¦5. List all grandson of? ¦
¦6. List all granddaughter of? ¦
¦7. List all uncles of? ¦
¦8. List all aunty of? ¦
¦9. list all cousins of? ¦
¦0. exit ¦
¦Enter your choice : 0 ¦
¦ ¦
¦ ¦
¦Press the SPACE bar ¦
+-----------------------------------------------------------------------------+