Create a program i Prolog. You can either invent your own problem to solve or use one of the ideas described below. The program should include facts and rules. Also a set of meaningful questions to the program should be presented. Please push to github and supply a README.md file.
Create a program that models students, classes, rooms, dates, and their relations.
class(a, mo).
class(a, hallur) .
class(b, lars).
class(b, jens).
class(c, ali).
class(d, tom).
class(a, kasper).
class_date(date(2019, 7, 30), a).
class_date(date(2019, 5, 30), b).
class_date(date(2019, 3, 30), c).
class_date(date(2019, 3, 30), d).
room(a).
room(b).
room(c).
room(d).
student(mo).
student(hallur).
student(jens).
student(lars).
student(kasper).
student(ali).
student(tom).
Secondly, we wrote down some ideas for methods, that had the requirement of including facts and rules
- get all information on a student
- does student a go in the same class as student b
- does student a go to class at the same date as student b
- get all students
- get all classes
- get all dates
To see the original file, click here 📃
Open the ass2.pl file in SWI then run those commands :
- getStudentInfo(hallur) .
getStudentInfo(A):- class(Class, A), writeln(Class), class_date(D, Class), writeln(D).
- sameClass(mo, hallur) .
<li>sameClass(mo,hallur) . sameClass(A,B):- class(Class, A), class(Class,B), writeln(Class).
- sameDate(ali, tom) .
sameDate(A,B):- class(ClassA, A), class(ClassB,B), class_date(StudentDate, ClassA), class_date(StudentDate, ClassB), writeln(StudentDate).
- getAllDates() .
getAllDates():- forall(class_date(ClassDates, S), writeln(ClassDates)) .
- getAllStudents() .
getAllStudents():- forall(student(Student) , writeln(Student)) .
- getAllClasses() .
getAllClasses():- forall(room(Name), writeln(Name)) .