Laborator 12

Test...

:-dynamic(student/1).

:-dynamic(student/2).

student(john, 8).

student(nick, 9).

student(joe, 7).

menu :- write("Your option:\n

1. Insert a student\n

2. Delete a student\n

3. Show the students\n

4. Show the students in descending order\n

5. Exit\n"),

read(Opt),

option(Opt).

option(1) :- write("Type the name of the student you want to insert:\n"),

read(Name),

write("Type the grade of the student you want to insert:\n"),

read(Grade),

assert(student(Name, Grade)),

menu.

option(2) :- write("Type the name of the student you want to delete:\n"),

read(Name),

retractall(student(Name,_)),

menu.

option(3) :- findall([X,Y],student(X,Y),List),

write(List),nl,

menu.

option(4) :- findall([X,Y], student(X,Y),List),

sort(1, @>=, List, Sorted),

write(Sorted),nl,

menu.

option(5).