Prolog Program 3
Prolog Program 3
domains
name,password=symbol
predicates
getinput(name,password)
logon
user(name,password)
clauses
logon:-
clearwindow,
getinput(_,_),
write("\n You are now Logged on."),nl.
logon:-
write("\n Sorry, You are not permitted access."),nl.
getinput(Name,Password):-
user(john,superman).
user(sue,happy).
user(bill,bigfoot).
/* Exp No:07*/
/* Logon example with repeat predicate */
domains
name,password=symbol
predicates
getinput(name,password)
logon
user(name,password)
repeat
clauses
repeat.
repeat:-
repeat.
logon:-
clearwindow,
getinput(_,_),
write("\n You are now logged on."),nl.
logon:-
repeat,
write("\n Sorry, you are not permitted access."),nl,
write("Please try again.\n"),
getinput(_,_),
write("\n You are now logged on."),nl.
getinput(Name,Password):-
write("\n Please enter your name: "),
readln(Name),nl,
write("\n Please enter your password: "),
readln(Password),nl,
user(Name,Password).
user(john,superman).
user(sue,happy).
user(bill,bigfoot).
/* Exp No:08 */
/* Logon example with recurtion and no repeat predicate */
domains
name,password=symbol
predicates
getinput(name,password)
logon
user(name,password)
clauses
logon:-
clearwindow,
getinput(Name,Password),
user(Name,Password),
logon:-
write("\n Sorry, you are not permitted access."),nl,
write("Please try again.\n"),
logon.
getinput(Name,Password):-
write("\n Please enter your name: "),
readln(Name),nl,
write(" Please enter your password: "),
readln(Password),nl.
user(john,superman).
user(sue,happy).
user(bill,bigfoot).
/*EXP NO:09 */
/*EXP NAME: Medical diagnostic system using the cut */
domains
disease,indication=symbol
name=string
predicates
hypothesis(name,disease)
symptom(name,indication)
response(char)
go
go_once
repeat
clauses
go:-
clearwindow,
repeat,
go_once,
write("Would you like to try again (y/n) ?"),
response(Reply),
Reply='n'.
go.
repeat.
repeat:-
repeat.
go_once:-
write("What is the patient's name?"),nl,
readln(Patient),
hypothesis(Patient,Disease),!,
write(Patient," probably has ",Disease,"."),nl.
go_once:-
write("Sorry,I don't seen to be able to "),nl,
write("diagnose the disease."),nl.
symptom(Patient,fever):-
write("Does ",Patient," have a fever (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,rash):-
write("Dose ",Patient," have a rash (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,headache):-
write("Dose ",Patient," have a headache (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,runny_nose):-
write("Dose ",Patient," have a runny nose (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,conjunctivities):-
write("Dose ",Patient," have conjunctivities (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,cough):-
write("Dose ",Patient," have a cough (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,body_ache):-
write("Dose ",Patient," have a body ache (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,chills):-
write("Dose ",Patient," have chills (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,sore_throat):-
write("Dose ",Patient," have a sore throat (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,sneezing):-
write("Is ",Patient," sneezing (y/n)?"),
response(Reply),
Reply='y'.
symptom(Patient,swollen_glands):-
write("Dose ",Patient," have swollen glands (y/n)?"),
response(Reply),
Reply='y'.
hypothesis(Patient,measles):-
symptom(Patient,fever),
symptom(Patient,cough),
symptom(Patient,conjunctivities),
symptom(Patient,runny_nose),
symptom(Patient,rash).
hypothesis(Patient,german_measles):-
symptom(Patient,fever),
symptom(Patient,headache),
symptom(Patient,runny_nose),
symptom(Patient,rash).
hypothesis(Patient,flu):-
symptom(Patient,fever),
symptom(Patient,headache),
symptom(Patient,body_ache),
symptom(Patient,conjunctivities),
symptom(Patient,chills),
symptom(Patient,sore_throat),
symptom(Patient,cough),
symptom(Patient,runny_nose).
hypothesis(Patient,common_cold):-
symptom(Patient,headache),
symptom(Patient,sneezing),
symptom(Patient,sore_throat),
symptom(Patient,chills),
symptom(Patient,runny_nose).
hypothesis(Patient,mumps):-
symptom(Patient,fever),
symptom(Patient,swollen_glands).
hypothesis(Patient,chicken_pox):-
symptom(Patient,fever),
symptom(Patient,rash),
symptom(Patient,body_ache),
symptom(Patient,chills).
hypothesis(Patient,whooping_cough):-
symptom(Patient,cough),
symptom(Patient,sneezing),
symptom(Patient,runny_nose).
response(Reply):-
readchar(Reply),
write(Reply),nl.
domains
name=string
predicates
getname(name)
go
clauses
go:-
clearwindow,
getname(Name),
write(Name),nl,
write("\nIs the name OK (y/n)?"),nl,
readchar(Reply),
Reply='y',!.
go:-
getname(Name):-