domains
st=st(string,real,real,real,real)
st1=st1(string,real)
List1=st1*
List=st*
database
dstudent(st)
predicates
result
repeat
menu
point(char)
print_av_down(List1)
max_el(List1,st1)
del_el(List1,st1,List1)
av_mark(List1,real,integer)
preobr(List,List1)
print_al_down(List1,real)
sort(List1,List1)
ins(st1,List1,List1)
retract_all
print_bad
clauses
repeat.
repeat:-repeat.
retract_all:-retract(dstudent(_)),fail.
retract_all.
menu:-clearwindow,
write(«Main menu»),nl,
write(«1-Add students to database»),nl,
write(«2-View list of students by average mark»),nl,
write(«3-View list of students sorted by alphabet with marks higher average mark»),nl,
write(«4-View list of students with bad marks»),nl,
write(«5-View database»),nl,
write(«6-About program»),nl,
write(«0-Exit from program»),nl,
write(«Your choice is: «),readchar(X),point(X),!,fail.
point('1'):-clearwindow,write(«Input student's surname: «),
readln(Surname),write(«Input first mark: «),readint(Mark1),
write(«Input second mark:»),readint(Mark2),
write(«Input third mark: «),readint(Mark3),
write(«Input fourth mark: «),readint(Mark4),
assertz(dstudent(st(Surname,Mark1,Mark2,Mark3,Mark4))),fail.
point('2'):-clearwindow,write(«Surname \t Average mark»),nl,
findall(S,dstudent(S),List1),preobr(List1,List),print_av_down(List),
nl,nl,write(«Press any key»),readchar(_).
point('3'):-clearwindow,write(«Surname \t Average mark»),nl,
findall(S,dstudent(S),List1),preobr(List1,List),av_mark(List,Sum,N),
sort(List,List2),
AvMark=Sum/N,print_al_down(List2,AvMark),nl,nl,
write(«Average mark is:»,AvMark),nl,nl,
write(«Press any key»),
readchar(_).
point('4'):-clearwindow,write(«Surname \t marks»),nl,print_bad,nl,nl,
write(«Press any key»),readchar(_).
point('5'):-clearwindow,save(«Database»),file_str(«Database»,Str),
write(«Surname \t Average marks»),nl,write(Str),nl,nl,
write(«Press any key»),readchar(_).
point('6'):-clearwindow,
write(«This program has been made by student of BSPA Khramtsov V.V. group 107219»),
nl,nl,write(«Press any key»),readchar(_).
point('0'):-save(«Database»),retract_all,removewindow,exit.
print_bad:-dstudent(st(Surname,Mark1,Mark2,Mark3,Mark4)),Mark1=2,
write(Surname,»\t»,Mark1,» «,Mark2,» «,Mark3,» «,Mark4),nl,fail.
print_bad:-dstudent(st(Surname,Mark1,Mark2,Mark3,Mark4)),Mark2=2,
write(Surname,»\t»,Mark1,» «,Mark2,» «,Mark3,» «,Mark4),nl,fail.
print_bad:-dstudent(st(Surname,Mark1,Mark2,Mark3,Mark4)),Mark3=2,
write(Surname,»\t»,Mark1,» «,Mark2,» «,Mark3,» «,Mark4),nl,fail.
print_bad:-dstudent(st(Surname,Mark1,Mark2,Mark3,Mark4)),Mark4=2,
write(Surname,»\t»,Mark1,» «,Mark2,» «,Mark3,» «,Mark4),nl,fail.
print_bad.
print_av_down([]).
print_av_down(List):-max_el(List,El),del_el(List,El,List1),
El=st1(Surname,AvMark),write(Surname,» «,AvMark),nl,
print_av_down(List1).
max_el([H],H).
max_el([H|T],El):-max_el(T,El1),El1=st1(_,AvMark),H=st1(_,AvMark1),
AvMark>AvMark1,El=El1.
max_el([H|T],El):-max_el(T,El1),El1=st1(_,AvMark),H=st1(_,AvMark1),
AvMark<=AvMark1,El=H.
del_el([],_,[]):-!.
del_el([H|T],El,T):-H=El,!.
del_el([H|T],El,[H|T1]):-del_el(T,El,T1).
preobr([],[]).
preobr([H|T],[H1|T1]):-preobr(T,T1),H=st(Surname,Mark1,Mark2,Mark3,Mark4),
AvMark=(Mark1+Mark2+Mark3+Mark4)/4,H1=st1(Surname,AvMark).
av_mark([],0,0).
av_mark([H|T],Sum,N):-av_mark(T,Sum1,N1),N=N1+1,H=st1(_,AvMark),
Sum=Sum1+AvMark.
print_al_down([],_).
print_al_down([H|T],AvMark):-H=st1(Surname,AvMark1),AvMark1>AvMark,
write(Surname,»\t»,AvMark1),nl,print_al_down(T,AvMark).
print_al_down([_|T],AvMark):-print_al_down(T,AvMark).
sort([],[]).
sort([H|T],After):-sort(T,Before),ins(H,Before,After).
ins(E,[],[E]).
ins(E,[H|T],[H|T1]):-H=st1(Surname,_),E=st1(Surname1,_),
Surname<Surname1,ins(E,T,T1).
ins(E,[H|T],[E,H|T]).
result:-existfile(«Database»),consult(«Database»),
makewindow(1,7,7,»Database»,0,0,25,80),repeat,menu.
result:-makewindow(1,7,7,»Database»,0,0,25,80),repeat,menu.
goal
result.