2
votes

Write Prolog program for following. I wrote every thing and I need to know final two are correct or not which I wrote.

1. saman likes maths.
2. saman likes science.
3. udara likes maths.
4. fazal likes science.
5. fazal likes music.
6. geetha likes history.
7. geetha likes science.
8. geetha likes music.
9. those who like maths and science will follow engineering for advance level.
10. those who likes history or music will follow art for advance level.

Is this correct for final two?

student(X):- like(X,maths_and_science),follow(X,engineering).
student(X):- likes(X,history_or_music), follow(X,art).
  1. I don't know how to write a Prolog queries for following.

    1) Does saman like maths or music?
    
    2) Who likes science and music?
    
    3) who will do engineering?
    

Please help me.

1
I think before you implement the rules, you first need to define the predicates and functors with the corresponding semantics. But the last two are - as far as I can see - not correct. - Willem Van Onsem

1 Answers

0
votes
  1. those who like maths and science will follow engineering for advance level.
  2. those who likes history or music will follow art for advance level.

Is this correct for final two?

No. It could be:

will_follow(Student, engineering) :-
    likes(Student, maths),
    likes(Student, science).

will_follow(Student, art) :-
    likes(Student, history)  ;
    likes(Student, music).

1) Does saman like maths or music?

likes(saman, art) ; likes(saman, music).     % intentionally incorrect

2) Who likes science and music?

likes( Who, science) , likes( Who, maths).   % intentionally incorrect

3) who will do engineering?

will_follow( Who, arts ).                    % intentionally incorrect

Since this looks like an assignment, I've intentionally used wrong names here and there. You will have to correct those.