(1) Type the following program into a file and load it into Prolog.
/* Animals Database */
animal(mammal,tiger,carnivore,stripes).
animal(mammal,hyena,carnivore,ugly).
animal(mammal,lion,carnivore,mane).
animal(mammal,zebra,herbivore,stripes).
animal(bird,eagle,carnivore,large).
animal(bird,sparrow,scavenger,small).
animal(reptile,snake,carnivore,long).
animal(reptile,lizard,scavenger,small).
Devise and test goals to find
(a) all the mammals,
(b) all the carnivores that are mammals,
(c) all the mammals with stripes,
(d) whether there is a reptile that has a mane.
and it's the Solution
1. First,You have to type all those words in notepad and then save it with .pl in the end of it's name.
2. Open your prolog program and then consult that notepad.
3. To solve the (a) problem you have to type animal(mammal,A,_,_). and then press Enter and don't forget to press ( ; ) button until it's end.
4. To solve the (b) problem you have to type animal(mammal,B,carnivore,_).and then press Enter and don't forget to press ( ; ) button until it's end.
5. To Solve problem (c),you can type animal(mammal,C,_,stripes). and press Enter and like i said before,
Don't forget to press button ( ; ).
6. And for the last Problem,You can type animal(reptile,D,_mane). after you press Enter there will be answer NO in your program.

(*) And It's the Problem no.2
Type the following program into a file
/* Dating Agency Database */
person(bill,male).
person(george,male).
person(alfred,male).
person(carol,female).
person(margaret,female).
person(jane,female).
Extend the program with a rule that defines a predicate couple with two arguments, the first being the name of a man and the second the name of a woman.
1. You must type
" person(bill,male).
person(george,male).
person(alfred,male).
person(carol,female).
person(margaret,female).
person(jane,female). "
plus the rule "couple(X,Y) :- person(X,male),person(Y,female)."to the notepad first and save it with .pl in the end of the file name.
2. After you have done the first step,you have to open your prolog program and consult the notepad you've saved.type couple(X,Y). and press Enter,after that you have to press button ";" until word "NO" appeared.
Enjoy the Programming and Thanks for Coming,...^^





Tidak ada komentar:
Posting Komentar