59.3k views
0 votes
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. ?- schedule (122,C,B,T) C= python B= owen 102 T=10 T= calculus I C= kec 1001 T=13. 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. ?- schedule (122, N,C) N= mary C= python N = mary C= calculus I. 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. 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. ?- conflict (410,X,Y) X=1621 Y=7822; X=7822, Y=1621; false. ?- conflict (122,X,Y) false. ?- conflict (122,2421,Y) false. 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, ?− meet (122, SID ) SID =150; SID =300; SID =310; SID =212; SID =175; SID =410; false. 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). ?- roster (3522, Sname). Sname = pat Sname = amy ; Sname = zoe 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, ? - highCredits(Cname). Cname = calculusI ; Cname = data structures Cname = algori i thms ; false.

User Jagat
by
8.2k points

1 Answer

3 votes

Final answer:

Predicates are descriptive terms that help clarify statements in a database about courses, sections, times, classrooms, and student enrollment. Derived Prolog predicates can be defined to provide information such as a student's schedule, course offerings, schedule conflicts, meeting possibilities, student rosters, and high-credit courses.

Step-by-step explanation:

Predicates are descriptive terms that can help us clarify statements by identifying the right predicates for analysis and clarifying the relationship between them. In a database about courses, sections, times, classrooms, and student enrollment, we can define several derived Prolog predicates:

  1. schedule/4 - gives the course name, building, and time of the classes a student is taking.
  2. schedule/3 - gives the student's name and the names of the courses the student is taking.
  3. offer/4 - gives the course number, course name, CRNs for sections, and times the sections of the course are offered.
  4. conflict/3 - computes conflicts in a student's schedule, checking if the student is enrolled in two classes that are scheduled to meet at the same time.
  5. meet/2 - determines pairs of students that can meet in a classroom by either attending the same class or having classes back to back in the same classroom.
  6. roster/2 - produces a list of all students taking a section of a course.
  7. highCredits/1 - produces a list of courses that are 4 or more credits.

User Matt Hyde
by
7.6k points