Sale!

CS 381 – Homework 7

$30.00

Category:
Rate this product

CS 381 – Homework 7
Problem 1. Database Application
Consider a database about courses, sections, times, classrooms and student enrollment, given in the
form of Prolog facts below. The entire database in in hw7.pl.
 course(course_number, course_name, credits)
 section(CRN, course_number)
 place(CRN, building, time)
 enroll(sid, CRN)
 student(sid, student_name, major)
Define the following derived Prolog predicates by one or more rules. Note that the shown goals are just
examples. You should define the predicates so that it is possible to formulate goals with variables or
constants at any argument position.
a) Define a predicate schedule/4 that gives for a student (by sid) the course name, building and time of
the classes the student is taking. For example if you evaluate the schedule(122,C,B,T), Prolog should
give the following results.
b) Define a predicate schedule/3 that gives for a student (by sid), the students name and the names of
the courses the student is taking. For example if you evaluate the schedule(122,N,C), Prolog should give
the following results.
c) Define a predicate offer/4 that gives, the course number, course name, CRNs for sections and times
the sections of the course are offered. For example, the goal offer(mth210,N,C,T) should yield the
following result.
CS 381 – Homework 7.
d) Define a predicate conflict/3 that can compute conflicts in a student’s schedule. A conflict exists if a
student is enrolled in two classes that are scheduled to meet at the same time. The arguments of
conflict are a student’s sid and two CRNs for sections of classes. If the students is not enrolled in the
section then a false is returned.
e) Define a predicate meet/2 that can determine pairs of students that can meet in a classroom by
either attending the same class or by having classes that are back to back in the same classroom. Meet
will take a two student sids as arguments. For example,
f) Define a predicate roster/3 that produces a list of all students talking a section of a course. The
arguments to roster are roster(CRN, Student_name).
g) Define a predicate highCredits/1 that produces a list of courses that are 4 or more credits. The
argument to highCredits is a course_name. For example,
CS 381 – Homework 7.
Problem 2: List Predicates and Arthmetic
Note: Do not use the predefined flatten and nth. You are allowed to use predefined predicates append
and member.
a) Define a Prolog predicate rdup(L,M) to remove duplicates from an ordered list L. The resulting list
should be bound to M. Note that M must contain each element of L exactly once and in the same order
as in L. You can assume that L is an ordered list. Some examples are given below:
b) Define a Prolog predicate flat(L,F) that binds to F the flat list of all elemets in L ( where L can be a
possibly nexted list). For example flat( [a,b, [c,d],[],[[e]],f], L) yields L = [a,b,c,d,e,f]. For example:
c) Define a Prolog predicate project/3 that selects elements from a list by their position and collects
them in a result list. For example, the goal of project( [2,4],[a,b,c,d],L) should produce the answer
L=[b,d]. You can assume that the numbers in the first list are strictly increasing, that is, your
implementation does not have to care about situations like project([1,1,2],..) or project([2,5,3],..). For
example:

Scroll to Top