/* PROGRAM TO SHOW ARITHMETIC OPERATIONS*/
domains
A,B,C=real
predicates
add
subtract
multiply
divide
clauses
add:-
write("Enter two numbers \n"),
readInt(A),
readInt(B),
C=A+B,
write("Sum is ",C,"\n").
subtract:-
write("Enter two numbers \n"),
readInt(A),
readInt(B),
C=A-B,
write("Difference is ",C,"\n").
multiply:-
write("Enter two numbers \n"),
readInt(A),
readInt(B),
C=A*B,
write("Product is ",C,"\n").
divide:-
write("Enter two numbers \n"),
readInt(A),
readInt(B),
C=A/B,
write("Result is ",C,"\n").
****************************************OUTPUT****************************************
Goal : add
Enter two numbers
12
34
Sum is 46
Yes
Goal : subtract
Enter two numbers
67
33
Difference is 44
Yes
Goal : multiply
Enter two numbers
6
3
Product is 18
Yes
Goal : divide
Enter two numbers
56
8
Result is 7
Yes
Goal : divide
Enter two numbers
22
7
Result is 3.1428571429
Yes
/*PROGRAM OF HOSPITAL DATABASE */
domains
Disease,Indication=symbol
Patient=string
predicates
hypothesis(Patient,Disease)
symptom(Patient,Indication)
clauses
symptom(sam,fever).
symptom(sam,headache).
symptom(sam,runny_nose).
symptom(sam,rash).
symptom(ram,fever).
symptom(ram,cough).
symptom(ram,conjunctivities).
symptom(ram,runny_nose).
symptom(ram ,rash).
symptom(himanshu,fever).
symptom(himanshu,headache).
symptom(himanshu,body_ache).
symptom(himanshu,conjunctivities).
symptom(himanshu,chills).
symptom(himanshu,sore_throat).
symptom(himanshu,cough).
symptom(himanshu,runny_nose).
symptom(himanshu,rash).
symptom(neha,headache).
symptom(neha ,sneezing).
symptom(neha,sore_throat).
symptom(neha ,chills).
symptom(neha,runny_nose).
symptom(harsh,fever).
symptom(harsh,swollen_glands).
hypothesis(ram,measles):-
symptom(ram,fever),
symptom(ram,cough),
symptom(ram,conjunctivities),
symptom(ram,runny_nose),
symptom(ram ,rash).
hypothesis(sam,german_measles):-
symptom(sam,fever),
symptom(sam,headache),
symptom(sam,runny_nose),
symptom(sam,rash).
hypothesis(himanshu,flu):-
symptom(himanshu,fever),
symptom(himanshu,headache),
symptom(himanshu,body_ache),
symptom(himanshu,conjunctivities),
symptom(himanshu,chills),
symptom(himanshu,sore_throat),
symptom(himanshu,cough),
symptom(himanshu,runny_nose).
hypothesis(neha,common_cold):-
symptom(neha,headache),
symptom(neha ,sneezing),
symptom(neha,sore_throat),
symptom(neha ,chills),
symptom(neha,runny_nose).
hypothesis(harsh,mumps):-
symptom(harsh,fever),
symptom(harsh,swollen_glands).
hypothesis(himanshu,german_measles):-
symptom(himanshu,fever),
symptom(himanshu,headache),
symptom(himanshu,runny_nose),
symptom(himanshu,rash).
****************************************OUTPUT****************************************
Goal : hypothesis(neha,common_cold)
Yes
Goal : hypothesis(ram,german_measles)
No
Goal : hypothesis(himanshu,W)
W=flu
W=german_measles
2 Solutions
Goal : hypothesis(W,mumps)
W=harsh
1 Solution
Goal: symptom(neha,cough)
No
Goal: symptom(harsh,fever)
Yes
Goal: symptom(W,cough)
W=ram
W=himanshu
2 Solutions
Goal: symptom(harsh,W)
W=fever
W=swollen_glands
2 Solutions
/* PROGRAM TO PERFORM STRING OPERATIONS */
domains
A,B,C=string
I,X,Y =integer
predicates
length
concatenation
clauses
length:-
write("Enter the string: "),
readln(A),
str_len(A,I),
write("Length of string : ",I),nl.
concatenation:-
write("Enter the first string: "),
readln(A),
write("Enter the second string: "),
readln(B),
concat(A,B,C),
write("Concatenated string: ",C),nl,
str_len(A,I),
write("Length of first string : ",I),nl,
str_len(B,X),
write("Length of second string : ",X),nl,
str_len(C,Y),
write("Length of concatenated string : ",Y),nl.
******************************OUTPUT********************************
Goal : length
Enter the string: himanshu
Length of string : 8
Yes
Goal : concatenation
Enter the first string: himanshu
Length of second string : singal
Concatenated string: himanshusingal
Length of first string : 8
Length of second string : 6
Length of concatenated string : 14
Yes
/*PROGRAM SHOWING USE OF CUT AND FAIL */
domains
City,State,S=symbol
predicates
location(symbol,symbol)
check_state(symbol)
go
find
clauses
location(hisar,haryana).
location(hansi,haryana).
location(tohana,haryana).
location(chandigarh ,haryana).
location(mumbai,maharashtra).
location(nagpur ,maharashtra).
location(pune,maharashtra).
location(patna ,bihar).
location(jaipur,rajasthan).
go:-
writef("%-10 %-13 ","City","State"),
location(City,State),
check_state(State),
writef("%-10 %-13",City,State),
fail.
check_state("maharashtra"):-
!,
fail.
check_state(_).
find:-
write( "Enter name of city :"),
readln(City),
location(City,S),
write("State :",S),nl.
*************************OUTPUT******************************
Goal: go
City State
hisar haryana
hansi haryana
tohana haryana
jaipur rajasthan
No
Goal: find
Enter name of city : patna
State :bihar
Yes
/* PROGRAM OF USER LOGIN WITH RECURSION */
domains
Name,Password=symbol
predicates
login(Name,Password)
logon
user(Name,Password)
clauses
user(himanshu,superman).
user(onkar,happy).
user(gaurav,bigfoot).
logon:-
login(Name,Password),
user(Name,Password),
write("You are now logged on."),nl.
logon:-
write("\nSorry, you are not permitted access."),nl,
write("Please try again.\n"),
logon.
login(Name,Password):-
write("\nPlease enter your name:\n"),
readln(Name),nl,
write("Please enter your password:\n"),
readln(Password),nl.
****************************OUTPUT***************************
Goal:logon
Please enter your name:
himanshu
Please enter your password:
superman
You are now logged on.
Yes
Goal:logon
Please enter your name:
onkar
Please enter your password:
taneja
Sorry, you are not permitted access.
Please try again.
Please enter your name:
onkar
Please enter your password:
happy
You are now logged on.
Yes
No comments:
Post a Comment