Sale!

Assignment 2 CSI 2120 Solved

Original price was: $40.00.Current price is: $35.00. $29.75

Category:

Description

5/5 - (1 vote)

Assignment 2 CSI 2120

Instructions:
• This assignment will assess your knowledge and understanding of the Prolog programming
language
• You must submit a zip file of your answers.
• This is an individual assignment. Strict measures to ensure academic integrity will be enforced.

Question 1. [1+2+2+3=8 points]

Write a Prolog program to implement a family tree. Your program should allow the user to define
relationships between family members, such as parent-child and sibling relationships, and should be
able to answer queries about these relationships.
Your program should include the following predicates:
• parent(Parent, Child) (1 point): This predicate should be true if Parent is a parent of Child.
• sibling(Sibling1, Sibling2) (2 points): This predicate should be true if Sibling1 is a sibling of
Sibling2.

• grandparent(Grandparent, Grandchild) (2 points): This predicate should be true if Grandparent
is a grandparent of Grandchild.
• ancestor(Ancestor, Descendant) (3 points): This predicate should be true if Ancestor is an
ancestor of Descendant.

Your program should include the following facts about a sample family tree:

parent(john, mary).
parent(john, tom).
parent(mary, ann).
parent(mary, fred).
parent(tom, liz).
male(john).
male(tom).
male(fred).
Assignment 2 CSI 2120 page 2
_________________________________________________________________________________________________
female(mary).
female(ann).
female(liz).
You can assume that each person in the family tree has a unique name.

Question 2. (1+2+3 = 6 points)

Write a Prolog program that implements a simple knowledge base for a pet store. Your program
should allow the user to define facts about pets, such as their name, species, and age, and should be
able to answer queries about these facts.

Your program should include the following predicates:

pet(Name, Species, Age) (1 point) : This predicate should be true if a pet with the given Name,
Species, and Age exists in the pet store.
species(Species, Count) (2 points) : This predicate should be true if there are Count pets of the given
Species in the pet store.
age_range(MinAge, MaxAge, Count) (3 points) : This predicate should be true if there are Count pets
in the pet store whose age is between MinAge and MaxAge.

Your program should include the following facts about pets in the pet store:

pet(fido, dog, 3).
pet(spot, dog, 5).
pet(mittens, cat, 2).
pet(tweety, bird, 1).
male(fido).
male(spot).
female(mittens).

Question 3. (3 points)

Given a list of integers, write a Prolog predicate sum_odd_numbers(List, Sum) that recursively sums all
odd numbers in the list and returns the result in Sum.