PAPoUCH Super Elite Lv2: Jr. Vet
Number of posts : 1860 Age : 37 Mood : Points : 298 Registration date : 2007-10-12
Character sheet Weapon: Crowbar Class: Thief HP: (50/50)
| Subject: test Tue Nov 02, 2010 9:08 pm | |
| question 1 - Code:
-
get_info:- nl, write('Enter the patients name: '), nl, read(Name), nl, write('Enter the patients age: '), nl, read(Age), nl, write('Enter Score 1: '), nl, read(Score1), nl, write('Enter Score 2: '), nl, read(Score2), nl, write('Enter Score 3: '), nl, read(Score3), patient_status(Name, Age, Score1, Score2 , Score3).
patient_status(Name, Age, Score1, Score2 , Score3):- Avg_Score is (Score1 + Score2 + Score3)/3, FSAvg is ((Score1 + Score3)/2), (Avg_Score >= 90 -> Cat is 1, Stat = 'Good Health'; ((Avg_Score >= 75, Avg_Score < 90) -> (FSAvg > 90 -> (Cat is 1, Stat = 'Good Health'); (Cat is 2, Stat = 'Good Health')); ((Avg_Score >= 50, Avg_Score < 75)-> (Score3 > 65 -> (Cat is 3, Stat = 'Good Health'); (Cat is 4, Stat = 'Poor Health')); (Cat is 5, Stat = 'Poor Health')))), nl, write('STATUS REPORT'), nl, nl, write('Name: '), write(Name), nl, write('Age: '), write(Age), nl, write('Health Category: '), write(Cat), nl, write('Status: '), write(Stat), nl, write('Would you like to calculate another patients status (Y/N)'), nl, read(Opt), loop(Opt).
loop(Opt):- ((Opt == 'Y'; Opt == 'y'; Opt == 'Yes'; Opt == 'yes') -> get_info; (Opt == 'N'; Opt == 'n'; Opt == 'No'; Opt == 'no') -> nl, write('GOODBYE'); write(Opt), write(' is not a valid option.'), nl, write('Enter Yes/ Y/ No/ N')),nl, read(Opt1), loop(Opt1).
question 2 - Code:
-
dealer('Greentree', 'reasonable'). dealer('Lotano', 'reasonable'). dealer('Titan', 'expensive'). origin('Greentree', 'Detroit'). origin('Titan', 'Vancouver'). origin('Lotano', 'Osaka'). ships_to('Greentree', 'Toronto'). ships_to('Greentree', 'Osaka'). ships_to('Greentree', 'Detroit'). ships_to('Titan', 'Osaka'). ships_to('Titan', 'Bridgetown'). ships_to('Lotano', 'Bridgetown'). ships_to('Lotano', 'Detroit'). sells('Lotano','Dell'). sells('Lotano','Acer'). sells('Greentree','Dell'). sells('Greentree','Acer'). sells('Titan','Gateway'). located('Osaka','Japan'). located('Toronto','Canada'). located('Vancouver','Canada'). located('Detroit','USA'). located('Bridgetown','Barbados').
purchase1(X):- X== lisa, dealer(Y, 'reasonable'), (sells(Y, 'Dell'); sells(Y, 'Acer')), origin(Y, Z), not(located(Z, 'Japan')), ships_to(Y, A), (located(A, 'USA'); located(A, 'Barbados')), nl, write(X), write(' can purchase a Dell or an Acer from '), write(Y), fail. purchase2(X):- X== tanya, dealer(Y, 'reasonable'), (sells(Y, 'Dell'); sells(Y, 'Acer')), ships_to(Y, A), located(A, 'Barbados'), nl, write(X), write(' can purchase a Dell or an Acer from '), write(Y), fail.
purchase3(X):- X== thomas, dealer(Y, _), sells(Y, 'Gateway'), ships_to(Y, A), located(A, 'Barbados'), nl, write(X), write(' can purchase a Gateway from '), write(Y), fail.
question 3 - Code:
-
parent('Hortense', 'Joan'). parent('Hortense', 'Paul'). parent('David', 'Paul'). parent('Joan', 'Vaughn'). parent('Joan', 'John'). parent('Paul', 'John'). parent('Paul', 'Mary'). parent('John', 'Raymond'). parent('John', 'Nadine'). parent('Mary', 'Byron'). parent('Mary', 'Peter').
ancestor(X, Y):- parent(X, Y). ancestor(X, Y):- parent(X, Z), ancestor(Z, Y). | |
|