Homework Assignment # 6
Due Tuesday November 20, 2012 by 11:59 pm + 1 minute (Midnight). Use turnin to submit your homework (i.e., turnin -submit [MW use swati, TTh use benself] CS345_HW6 HW6.pl)


Run the following sql queries in SQLDeveloper and put the results in a file named PrologDB.pl. (you'll need to load Student.sql from the class website into your user account first.) This will give you a subset of the Student Database (sufficient for this homework) as Prolog Facts (Relations).

select 'student(' || STUDENT_ID
|| ', ''' || SALUTATION
|| ''', ''' || FIRST_NAME
|| ''', ''' || LAST_NAME
|| ''', ''' || STREET_ADDRESS
|| ''', ' || ZIP
|| ', ''' || PHONE
|| ''', ''' || EMPLOYER
|| ''', ''' || REGISTRATION_DATE || ''').' from student;

select 'zipcode(' || ZIP
|| ', ''' || CITY
|| ''', ''' || STATE || ''').' from ZIPCODE;

select 'enrollment(' || STUDENT_ID
|| ', ' || SECTION_ID
|| ', ''' || ENROLL_DATE
|| ''', ' || nvl(FINAL_GRADE, 0)|| ').' from ENROLLMENT;

select 'section(' || SECTION_ID
|| ', ' || COURSE_NO
|| ', ' || SECTION_NO
|| ', ''' || START_DATE_TIME
|| ''', ''' || LOCATION
|| ''', ' || INSTRUCTOR_ID
|| ', ' || CAPACITY || ').' from SECTION;

select 'course(' || Course_NO
|| ', ''' || DESCRIPTION
|| ''', ' || nvl(COST, 0)
|| ', ' || nvl(PREREQUISITE, 0) || ').' from COURSE;

select 'instructor(' || INSTRUCTOR_ID
|| ', ''' || SALUTATION
|| ''', ''' || FIRST_NAME
|| ''', ''' || LAST_NAME
|| ''', ''' || STREET_ADDRESS
|| ''', ' || nvl(ZIP, 0)
|| ', ''' || PHONE || ''').' from INSTRUCTOR;

[10 Points] For the Prolog database in PrologDB.pl, re-write the following SQL queries in Prolog and put them in HW6.pl.

1. select s.student_id, last_name, section_id

from student s, enrollment e

where s.student_id = e.student_id and

first_name = 'Fred'

2. select s.student_id, last_name, e.section_id, course_no, instructor_id

from student s, enrollment e, section c

where s.student_id = e.student_id and

e.section_id = c.section_id and

first_name = 'Fred'

3. select s.student_id, last_name, e.section_id, r.course_no, instructor_id, description

from student s, enrollment e, section c, course r

where s.student_id = e.student_id and

e.section_id = c.section_id and

c.course_no = r.course_no and

first_name = 'Fred'

4. select s.student_id, s.last_name, e.section_id, r.course_no,

i.instructor_id, description, i.first_name, i.last_name

from student s, enrollment e, section c, course r, instructor i

where s.student_id = e.student_id and

e.section_id = c.section_id and

c.course_no = r.course_no and

c.instructor_id = i.instructor_id and

s.first_name = 'Fred'

5. select i.instructor_id, c.course_no, description, section_id

from instructor i, section s, course c

where i.instructor_id = s.instructor_id and

s.course_no = c.course_no and

first_name = 'Nina' and last_name = 'Schorin'

6. select c.course_no, first_name, last_name, i.instructor_id, s.section_id

from course c, section s, instructor i

where c.course_no = s.course_no and

s.instructor_id = i.instructor_id

and description = 'Hands-On Windows'

7. select c.course_no, p.first_name, p.last_name, i.instructor_id, s.section_id

from course c, section s, instructor i, enrollment e, student p

where c.course_no = s.course_no and

s.instructor_id = i.instructor_id and

e.student_id = p.student_id and

s.section_id = e.section_id

and description = 'Hands-On Windows' and

i.first_name = 'Anita' and i.last_name = 'Morris'

8. select c.description, c.prerequisite

from course c, course p

where c.prerequisite = p.course_no

9. select cost, description

from course

where cost < 1100

10. Look at the ancestor rules in the file 11Prolog Examples.p and

write a set of rules for prereq that will find all of the prerequisite courses for a course such as prereq(P, 430) would give:

A = 350 ? ;

A = 0 ? ;

A = 204 ? ;

A = 80 ? ;

A = 120 ? ;

A = 122 ? ;

A = 20 ? ;

A = 125 ? ;

Please structure the HW6.pl file as follows:

% 1. prolog query 1.
% 2. prolog query 2.
% 3. prolog query 3.
% 4. prolog query 4.
% 5. prolog query 5.
% 6. prolog query 6.
% 7. prolog query 7.
% 8. prolog query 8.
% 9. prolog query 9.
% 10.
prolog rules for prereq

% prereq(X,430).