Académique Documents
Professionnel Documents
Culture Documents
PROGRAM CODE:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class water
{
public:
int j1,j2,f1,f2,h,l,a;
void getdata();
void jug_fill(int,int,int,int,int,int);
};
void water::getdata()
{
water o;
cout<<"water jug problem \n";
cout<<"enter the jug size:";
cin>>j1;
cin>>j2;
cout<<"enter the final stage of the jug:\n";
cin>>f1;
cin>>f2;
cout<<"initial stage:0 0\n";
l=j2;
h=0;
a=0;
cout<<"next stage"<<h<<" "<<l<<endl;
o.jug_fill(j1,j2,f1,h,l,a);
}
void main()
{
clrscr();
water o;
o.getdata();
getch();
}
SAMPLE INPUT AND OUTPUT:
PROGRAM CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int tmp,no=0;
class single
{
public:
int i,j;
int arr[10][10];
int h_no;
void h_fn();
void get();
void print();
void copy(int);
void find_sol();
int find_min();
void path();
}temp[100],start,goal,visited[30];
void single::get()
{
cout<<"Enter the starting array:\n";
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
cin>>start.arr[i][j];
start.h_fn();
cout<<"Enter the ending array:\n";
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
cin>>goal.arr[i][j];
goal.h_fn();
}
void single::h_fn()
{
int temp=0;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
if(arr[i][j]!=goal.arr[i][j])
++temp;
h_no=temp;
}
void single::copy(int t)
{
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
temp[t].arr[i][j]=arr[i][j];
}
void single::find_sol()
{
tmp=0;
int si,sj;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
if(arr[i][j]==0)
{
si=i;
sj=j;
break;
}
if(sj<3)
{
++tmp;
copy(tmp);
temp[tmp].arr[si][sj]=arr[si][sj+1];
temp[tmp].arr[si][sj+1]=0;
temp[tmp].h_fn();
}
if(sj>1)
{
++tmp;
copy(tmp);
temp[tmp].arr[si][sj]=arr[si][sj-1];
temp[tmp].arr[si][sj-1]=0;
temp[tmp].h_fn();
}
if(si>1)
{
++tmp;
copy(tmp);
temp[tmp].arr[si][sj]=arr[si-1][sj];
temp[tmp].arr[si-1][sj]=0;
temp[tmp].h_fn();
}
if(si<3)
{
++tmp;
copy(tmp);
temp[tmp].arr[si][sj]=arr[si+1][sj];
temp[tmp].arr[si+1][sj]=0;
temp[tmp].h_fn();
}
}
void single::print()
{
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
if(arr[i][j]==0)
cout<<"0"<<" ";
else
cout<<arr[i][j]<<" ";
}
cout<<"\n";
}
h_fn();
getch();
cout<<endl<<endl;
}
int single::find_min()
{
int min=1;
for(i=1;i<tmp;i++)
if(temp[i].h_no>temp[i+1].h_no)
min=i+1;
return min;
}
void single::path()
{
++no;
for(i=1;i<=3;i++)
for(j=1;j<=3;j++)
visited[no].arr[i][j]=arr[i][j];
visited[no].print();
if(visited[no].h_no==0)
{
printf("SOLUTION FOUND!");
getch();
exit(0);
}
visited[no].find_sol();
next_min:int min_h=0;
min_h=find_min();
int flag=0;
for(i=1;i<=no;i++)
{
flag=0;
if(visited[i].h_no==temp[min_h].h_no)
{
for(j=1;j<=3;j++)
for(int k=1;k<=3;k++)
if(visited[i].arr[j][k]!=temp[min_h].arr[j][k])
{
flag=1;
}
if(flag==0)
{
flag=2;
break;
}
}
}
if(flag==0||flag==1)
{
temp[min_h].path();
}
else if(flag==2)
{
temp[min_h].h_no=99;
goto next_min;
}
}
void main()
{
single p[20];
clrscr();
start.get();
cout<<"\n Solution:\n";
start.path();
}
SAMPLE INPUT AND OUTPUT:
Solution:
283
164
705
283
104
765
283
014
765
083
214
765
803
214
765
813
204
765
813
023
765
013
824
765
123
804
765
SOLUTION FOUND!
//TWO PLAYER GAME//
PROGRAM CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void printstate(int s[3][3])
{
cout<<"\n\n\t\t\t";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<s[i][j]<<"\t";
}
cout<<endl<<"\t\t\t";
}
}
case 2:
for(j=0;j<3;j++)
{
if(arr[2][j]==0)
{
arr[2][j]=5;
break;
}
}
break;
case 3:
for(j=0;j<3;j++)
{
if(arr[j][0]==0)
{
arr[j][0]=5;
break;
}
}
break;
case 4:
for(j=0;j<3;j++)
{
if(arr[j][1]==0)
{
arr[j][1]=5;
break;
}
}
break;
case 5:
for(j=0;j<3;j++)
{
if(arr[j][2]==0)
{
arr[j][2]=5;
break;
}
}
break;
case 6:
for(j=0;j<3;j++)
{
if(arr[j][j]==0)
{
arr[j][j]=5;
break;
}
}
break;
case 7:
for(j=0,k=2;j<3&&k>0;j++,k--)
{
if(arr[j][k]==0)
{
arr[j][k]=5;
break;
}
}
break;
}
}
void main()
{
clrscr();
int arr[3][3],a[8],x,y,over=0,movemade=0;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
arr[i][j]=0;
cout<<"Instructions:"<<endl;
cout<<"---------------:"<<endl;
cout<<"\t 0 indicates that the cell is free"<<endl;
cout<<"\t 3 indicates the move of the user"<<endl;
cout<<"\t 5 indicates the move of computer"<<endl;
while(1)
{
movemade=0;
printstate(arr);
cout<<"make your move"<<endl;
cout<<"-----------"<<endl;
cout<<"Enter the row number:";
cin>>x;
cout<<"Enter the column number:";
cin>>y;
if((arr[x-1][y-1]==3)||arr[x-1][y-1]==5)
{
cout<<"\n\n\t\t\t The cell is not free\a\n";
cout<<"\n\t\t Make another choice\n";
continue;
}
else
arr[x-1][y-1]=3;
a[0]=arr[0][0]+arr[0][1]+arr[0][2];
a[1]=arr[1][0]+arr[1][1]+arr[1][2];
a[2]=arr[2][0]+arr[2][1]+arr[2][2];
a[3]=arr[0][0]+arr[1][0]+arr[2][0];
a[4]=arr[0][1]+arr[1][1]+arr[2][1];
a[5]=arr[0][2]+arr[1][2]+arr[2][2];
a[6]=arr[0][0]+arr[1][1]+arr[2][2];
a[7]=arr[0][2]+arr[1][1]+arr[2][0];
for(int i=0;i<8;i++)
{
if(a[i]==15)
{
printstate(arr);
cout<<"Computer won.Better luck next time";
over=1;
break;
}
if(a[i]==9)
{
printstate(arr);
cout<<"You won.Well done";
over=1;
break;
}
}
if(over==1)
break;
for(i=0;i<8;i++)
{
if(a[i]==10)
{
makemove(arr,i);
printstate(arr);
cout<<"\n\nComputer won.Better luck next time";
movemade=1;
break;
}
}
if(movemade==1)
break;
for(i=0;i<8;i++)
{
if(a[i]==6)
{
makemove(arr,i);
movemade=1;
break;
}
}
if(movemade==1)
continue;
for(i=0;i<8;i++)
{
if(a[i]==8)
{
makemove(arr,i);
movemade=1;
break;
}
}
if(movemade==1)
continue;
for(i=0;i<8;i++)
{
if(a[i]==3)
{
makemove(arr,i);
movemade=1;
break;
}
}
if(movemade==1)
continue;
printstate(arr);
cout<<"\n\n Game is draw.Better luck next time";
break;
}
getch();
}
SAMPLE INPUT AND OUTPUT:
Instructions:
-------------
0 indicates that the cell is free
3 indicates the move of the user
5 indicates the move of the computer
000
000
000
000
530
000
500
530
003
500
530
353
Make your move
--------------------
Enter the row number:1
Enter the column number:3
503
530
353
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node
{
char name;
int g;
int h;
int f;
char parent;
}open[20],closed[20],temp[10];
void next()
{
int i,j;
printf("\n\n\t Enter the number of childs:");
scanf("%d",&n);
pos=0;
for(i=0;i<n;i++)
{
printf("\n\n\t Enter the next node of %c:",closed[current]);
temp[pos].name=getche();
printf("\n\n\t Enter its heuristic value:");
scanf("%d",&temp[pos].h);
temp[pos].g=closed[current].g+1;
temp[pos].f=temp[pos].g+temp[pos].h;
temp[pos].parent=closed[current].name;
pos++;
}
}
void add_open()
{
int i;
char temp1;
for(i=0;i<n;i++)
{
temp1=temp[i].name;
if(check(temp1))
{
open[open_rear].name=temp[i].name;
open[open_rear].g=temp[i].g;
open[open_rear].h=temp[i].h;
open[open_rear].f=temp[i].f;
open[open_rear].parent=temp[i].parent;
open_rear++;
}
}
}
void swap(int i,int j)
{
node t;
t.name=open[i].name;
t.h=open[i].h;
t.g=open[j].g;
t.f=open[i].f;
t.parent=open[i].parent;
open[i].name=open[j].name;
open[i].h=open[j].h;
open[i].g=open[j].g;
open[i].f=open[j].f;
open[i].parent=open[j].parent;
open[j].name=t.name;
open[j].h=t.h;
open[j].g=t.g;
open[j].f=t.f;
open[j].parent=t.parent;
}
void find_min()
{
int i,j,min;
for(i=open_front;i<open_rear-1;i++)
{
for(j=i+1;j<open_rear;j++)
{
if(open[i].f>open[i].f)
swap(i,j);
}
}
}
void goal()
{
int i,dist=0;
clrscr();
printf("\n\n\tthe optimal path is :");
for(i=closed_front;i<closed_rear;i++)
{
printf("\t%c->",closed[i].name);
dist+=closed[i].h;
}
printf("\n\n\tThe optimal path is %d",dist);
printf("\t%c",closed[i].name);
getch();
exit(0);
}
void add_closed()
{
char temp;
closed[closed_rear].name=open[open_front].name;
closed[closed_rear].h=open[open_front].h;
closed[closed_rear].g=open[open_front].g;
closed[closed_rear].f=open[open_front].f;
closed[closed_rear].parent=open[open_front].parent;
open_front++;
current=closed_front;
closed_rear++;
s1:printf("\n\n\t do you want to continue(y/n)?");
temp=getche();
if(temp=='y'||temp=='Y')
{
astar();
}
else if(temp=='n'||temp=='N')
goal();
else
goto s1;
}
void astar()
{
next();
add_open();
find_min();
add_closed();
}
void main()
{
int i,j,temp;
char name;
clrscr();
printf("\n\n\t A* algorithm");
printf("\n\n\t enter the root node");
scanf("%c",&name);
printf("\n\n\tenter its heuristic value:");
scanf("%d",&temp);
getch();
closed[closed_rear].name=name;
closed[closed_rear].h=temp;
closed[closed_rear].parent='0';
closed[closed_rear].f=temp;
closed_rear++;
current=closed_front;
astar();
}
SAMPLE INPUT AND OUTPUT:
A* ALGORITHM
Enter the root node: A
Enter its heuristic value: 10
PROGRAM CODE:
#include<conio.h>
#include<string.h>
int s1=0,s2=0;
char new1[50],new2[50],arg1[25],arg2[25];
main()
{
char l1[50],l2[15];
clrscr();
printf("\nUNIFICATION ALGORITHM");
printf("\n____________________\n");
printf("\nEnter the first literal:");
scanf("%s",l1);
printf("Enter the second literal:");
scanf("%s",l2);
unify(l1,l2);
getch();
}
else
{
if(strcmp(arg1,arg2)==0)
printf("\nUnification not needed!”);
printf(“\n Both the predicate and literals are same!");
else
{
printf("Unification possible");
chksub(l1,l2);
}
return;
}
}
}
for(i=0;i<strlen(l2);i++)
{
if(l2[i]!='(')
{
c++;
x[0]=l2[s2];
x[1]='\0';
strcat(new2,x);
s2++;
}
if(l2[i]=='(')
break;
}
if(strcmp(new1,new2)==0)
return 1;
else
return 0;
}
UNIFICATION ALGORITHM
--------------------------------------
Enter the first literal: abc(p,q)
Enter the second literal: abc(x,y)
Unification possible!
Substitution: x / p
Substitution: y / q
UNIFICATION ALGORITHM
--------------------------------------
Enter the first literal: abc(p,q)
Enter the second literal: abcd(x,y)
The function name does not match. Unification cannot be done!
UNIFICATION ALGORITHM
--------------------------------------
Enter the first literal: abc(p,q)
Enter the second literal: abc(x)
The number of arguments does not match. Unification cannot be done!
UNIFICATION ALGORITHM
--------------------------------------
Enter the first literal: abc(p,q)
Enter the second literal: abc(p,q)
Unification not needed. Both the predicate and literals are same!
//N-QUEENS PROBLEM //
PROGRAM CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
int x[10],n,count=0;
unsigned char a[10][10];
void nqueens(int,int);
void main()
{
int i,j,k,n;
clrscr();
cout<<"\n\n N-QUEENS PROBLEM";
cout<<"\n\t Enter the number of queens:";
cin>>n;
nqueens(1,n);
cout<<"\t The number of solutions are:"<<count;
getch();
}
N-QUEENS PROBLEM
Enter the number of queens:4
Solution1:
- Q - -
- - - Q
Q - - -
- - Q -
Solution2:
- - Q -
Q - - -
- - - Q
- Q - -
PROGRAM CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct expert
{
char *name;
int bit[17];
}p[17];
void comp();
void check(int);
int ques,ans[17];
char *rep;
void setrules()
{
p[1].name="Measles";
p[1].bit[1]=1;
p[1].bit[2]=1;
p[1].bit[3]=0;
p[1].bit[4]=1;
p[1].bit[5]=1;
p[1].bit[6]=1;
p[1].bit[7]=0;
p[2].name="German Measles";
p[2].bit[1]=1;
p[2].bit[2]=1;
p[2].bit[3]=1;
p[2].bit[4]=1;
p[2].bit[5]=0;
p[2].bit[6]=0;
p[2].bit[7]=0;
p[3].name="Flu";
p[3].bit[1]=1;
p[3].bit[2]=0;
p[3].bit[3]=1;
p[3].bit[4]=1;
p[3].bit[5]=1;
p[3].bit[6]=1;
p[3].bit[7]=1;
p[4].name="Mumps";
p[4].bit[1]=1;
p[4].bit[2]=0;
p[4].bit[3]=0;
p[4].bit[4]=0;
p[4].bit[5]=0;
p[4].bit[6]=0;
p[4].bit[7]=0;
p[5].name="Chicken pox";
p[5].bit[1]=1;
p[5].bit[2]=1;
p[5].bit[3]=0;
p[5].bit[4]=0;
p[5].bit[5]=0;
p[5].bit[6]=0;
p[5].bit[7]=1;
p[6].name="Typhoid";
p[6].bit[1]=1;
p[6].bit[2]=0;
p[6].bit[3]=0;
p[6].bit[4]=0;
p[6].bit[5]=0;
p[6].bit[6]=1;
p[6].bit[7]=0;
p[7].name="Cholera";
p[7].bit[1]=1;
p[7].bit[2]=0;
p[7].bit[3]=0;
p[7].bit[4]=0;
p[7].bit[5]=1;
p[7].bit[6]=1;
p[7].bit[7]=0;
}
void getinput()
{
cout<<"\nGuess the Disease!!!\n";
ques=1;
void comp()
{
int j,k,flag=0,flag1=0;
for(j=1;j<=7;j++)
{
for(k=1;k<=7;k++)
{
if(p[j].bit[k]==ans[k])
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
{
flag1=1;
cout<<"The person is suffering from "<<p[j].name<< " disease!";
continue;
}
}
if(flag1==0)
cout<<"None of the symptoms matches the given condition";
}
void display()
{
cout<<"\n Expert sstem for medical diagnosis";
cout<<"\n The diseases are:";
cout<<"\nMeasles \n German measles \n Flu \n Mumps \n Chicken pox \n
Typhoid \n Cholera \n";
}
void main()
{
clrscr();
setrules();
display();
getinput();
getch();
}
SAMPLE INPUT AND OUTPUT:
PROGRAM CODE:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct expert
{
char *name;
int bit[17];
}p[17];
void comp();
void check(int);
int ques,ans[17];
char *rep;
void setrules()
{
p[1].name="Kapil dev";
p[1].bit[1]=1;
p[1].bit[2]=1;
p[1].bit[3]=1;
p[1].bit[4]=0;
p[1].bit[5]=1;
p[1].bit[6]=0;
p[1].bit[7]=0;
p[2].name="Latha Mangeshkar";
p[2].bit[1]=1;
p[2].bit[2]=0;
p[2].bit[3]=1;
p[2].bit[4]=0;
p[2].bit[5]=0;
p[2].bit[6]=0;
p[2].bit[7]=1;
p[3].name="Amitab bachan";
p[3].bit[1]=1;
p[3].bit[2]=1;
p[3].bit[3]=0;
p[3].bit[4]=0;
p[3].bit[5]=0;
p[3].bit[6]=0;
p[3].bit[7]=1;
p[4].name="Sachin Tendulkar";
p[4].bit[1]=1;
p[4].bit[2]=1;
p[4].bit[3]=0;
p[4].bit[4]=0;
p[4].bit[5]=0;
p[4].bit[6]=1;
p[4].bit[7]=0;
p[5].name="Abdul Kalam";
p[5].bit[1]=1;
p[5].bit[2]=1;
p[5].bit[3]=1;
p[5].bit[4]=0;
p[5].bit[5]=1;
p[5].bit[6]=0;
p[5].bit[7]=0;
p[6].name="Shabana Azmi";
p[6].bit[1]=1;
p[6].bit[2]=0;
p[6].bit[3]=0;
p[6].bit[4]=0;
p[6].bit[5]=0;
p[6].bit[6]=0;
p[6].bit[7]=1;
p[7].name="Rahul Dravid";
p[7].bit[1]=1;
p[7].bit[2]=1;
p[7].bit[3]=0;
p[7].bit[4]=0;
p[7].bit[5]=0;
p[7].bit[6]=1;
p[7].bit[7]=1;
}
void getinput()
{
cout<<"\nGuess the Personality!!!\n";
ques=1;
void comp()
{
int j,k,flag=0,flag1=0;
for(j=1;j<=7;j++)
{
for(k=1;k<=7;k++)
{
if(p[j].bit[k]==ans[k])
flag=1;
else
{
flag=0;
break;
}
}
if(flag==1)
{
flag1=1;
cout<<"The personality name is "<<p[j].name<<"";
continue;
}
}
if(flag1==0)
cout<<"None of the personality matches the given condition";
}
void display()
{
cout<<"\n The personalities are:";
cout<<"\n Kapil dev \n Latha Mangeshkar \n Amitab bachan \n sachin tendulkar
\n Abdul kalam \n Shabana Azmi \n Rahul dravid \n";
}
void main()
{
clrscr();
setrules();
display();
getinput();
getch();
}
SAMPLE INPUT AND OUTPUT:
PROGRAM CODE:
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
int conj(char *);
int noun(char *);
int article(char *);
int prep(char *);
int aux(char *);
void process(char *);
int length=0;
char ans[100];
void main()
{
char a[90],s[30];
int i,j;
clrscr();
printf("\nEnter the fact:");
gets(a);
i=0;
while((a[i]!='\n')&&(a[i]!='\0'))
{
j=0;
while((a[i]!=' ')&&(a[i]!='\0')&&(a[i]!='\n'))
{
s[j]=a[i];
i++;
j++;
}
while(a[i]==' ')
i++;
s[j]='\0';
printf("\n %s",s);
process(s);
}
printf("\n prepositional logic:%s",ans);
getch();
}
else if(!strcmpi(s,"then"))
{
ans[length]='-';
length++;
}
else if(conj(s))
{
i=conj(s);
if(i==1)ans[length]='&';
if(i==2)ans[length]='|';
if(i==3)ans[length]='~';
length++;
}
else
{
i=0;
while(s[i]!='\0')
{
ans[length]=s[i];
length++;
i++;
}
ans[length]='\0';
}
}
if
it
not
raining
then
it
is
not
sunny
PROGRAM CODE:
#include <iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
void adjs();
static char sent[116];
char* st = sent;
int s()
{
if(np())
return vp();
return 0;
}
int np()
{
char the[10];
sscanf (st , "%s" , the);
if(!strcmp(the, "the"))
{
st+=strlen("the")+1;
return np1();
}
else if(pro())
return 1;
else if(pn())
return 1;
else if(np1())
return 1;
return 0;
}
int np1()
{
adjs();
return n();
}
void adjs()
{
if(adj())
{
adjs();
}
}
int vp()
{
if(v())
return 1;
if(n())
return np();
return 0;
}
int n()
{
char t[10];
sscanf(st , "%s" , t);
if(!(strcmp(t,"file")) || !(strcmp(t,"printer")))
{
st+=strlen(t)+1;
return 1;
}
return 0;
}
int pn()
{
char t[10];
sscanf(st, "%s" , t);
if( !(strcmp(t,"bill") ))
{
st+=strlen(t)+1;
return 1;
}
return 0;
}
int pro()
{
char t[10];
sscanf(st, "%s" , t);
if( !(strcmp(t,"I") ))
{
st+=strlen(t)+1;
return 1;
}
return 0;
}
int adj()
{
char t[10];
sscanf(st , "%s" , t);
if( !(strcmp(t,"short")) || !(strcmp(t,"fast")) || !(strcmp(t,"long")))
{
st+=strlen(t)+1;
return 1;
}
return 0;
}
int v()
{
char t[10];
sscanf(st , "%s" , t);
if( !(strcmp(t,"printed")) || !(strcmp(t,"created")) || !(strcmp(t,"want")))
{
st+=strlen(t)+1;
return 1;
}
return 0;
}
void main()
{
int i=0;
else if(!st[0])
cout<<"\n YOUR SENTENCE IS CORRECT";
else
cout<<"THERE ARE EXTRA TOKENS IN YOUR SENTENCE";
getch();
}
SAMPLE INPUT AND OUTPUT:
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
#include<string.h>
char clause[15][50];
char token[15][15];
int N;
void main()
{
int i;
clrscr();
printf("\nPREDICATE TO CLAUSE CONVERSION");
printf("\nEnter the input in predicate conversion:");
split();
printf("\n");
printf("\n The clause form for the given predicate is:");
for(i=0;i<N;i++)
{
printf("\n %d: %s\n",i+1,clause[i]);
}
getch();
}
split()
{
FILE*fp;
char str[100];
int n;
fp=fopen("input.txt","r");
if(!fp)
printf("\nCannot open the input file!");
n=-1;
do
{
++n;
str[n]=fgetc(fp);
if(str[n]=='\n')
{
str[n]='\0';
printf("\n%s",str);
scan(str);
n=-1;
}
}while(str[n]!=EOF);
str[n]='\0';
printf("\n%s",str);
scan(str);
fclose(fp);
return 0;
}
replace(int k)
{
if(match("&",token[k]))
{
token[k][0]='|';
token[k][1]='\0';
}
else if(match("|",token[k]))
{
token[k][0]='&';
token[k][1]='\0';
}
else
if(!remove_not(token[k]))
insert(token[k]);
return 5
}
insert(char *m)
{
char *temp;
int i=0,j=1,flag=0;
int l=strlen(m);
temp=(char*)malloc(l);
strcpy(temp,m);
m[0]='7';
for(i=0;i<1;i++)
if(temp[i]!=' ')
{
m[j]=temp[i];
j++;
}
}
trim(char *s)
{
int i=0,j=0;
int l=strlen(s);
for(i=0;i<1;i++)
{
s[j]=s[i];
if(s[i]!=' ')
j++;
}
}
SAMPLE INPUT AND OUTPUT:
2: 7ruler(y) | 7loyalto(x,y)
3: 7pompean(x) | roman(x)
4: man(marcus)
5: loyalto(x,y)
6: lucky(x)
STUDY OF PROLOG
AIM:
DOMAIN:
The notation of the domain corresponds exactly to that of type in typed programs.
PREDICATES:
Here the two classes together define the condition same one to be the parent together
they form a procedure.
GOALS:
PRIMITIVE DATATYPES:
STRUCTURED DATATYPES:
SEQUENCE CONTROL:
Prolog uses unification with backtracking. There is no need of real concept of local
or global environment. All the ways have local context. Because of the way unification
has been implemented a query such as q1,q2,q3….qn. First evaluate q1 and q2 and so on.
Rules are stored in the order they are being entered in the database.
EXPRESSIONS:
Arithmetic expressions +,-,*,/ are defined. Relations such as =-,<.>,<=,>= are also
defined. The equality operator = means ‘same as’. The operate ‘is’ means ‘evaluate’.
STATEMENTS:
Facts: Facts are relationships that are stated during a consult operation, which adds
new facts and rules to the database. There are n tuples f(a1,a2,a3,..an) and such states
the relationship among n arguments according to relationship f.
Rules: Rules are implications that are stored/started during a consult operation.
not(X):= -X ! fail
not (-)
This is not the same as return true if X is false. If X is true, then not(X) will process X
as true. If X is false, then the first rule fails, but not(-) succeeds.
The default output of the defined variables is sufficient for writing out answers.
However a ‘write’ function also exists to write out any results.
Eg. : write(‘abc’)
- - - ->abc
STANDARD FUNCTION: