Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## AOSTAR
- #include<iostream.h>
- #include<conio.h>
- void mapping();
- int map[15][4],flag[10],n,tc=0,cost[10];
- void main()
- {
- int i,j,k,z,r;
- clrscr();
- cout<<"Enter the no. of nodes: ";
- cin>>n;
- mapping();
- for(i=1;i<=n;i++)
- {
- cout<<endl;
- for(j=0;j<4;j++)
- cout<<map[i][j]<<" ";
- }
- cout<<"Enter the no. of goals: ";
- cin>>z;
- for(i=0;i<z;i++)
- cin>>flag[i];
- for(i=n;i>0;i--)
- {
- if(map[i][1]!=0||map[i][2]!=0)
- {
- z=0;
- r=0;
- while(flag[z]!=0)
- z++;
- for(k=0;k<z;k++)
- {
- if(map[i][1]==flag[k])//|| (map[i][2]==flag[k]&&map[i][3]==flag[k+1])||(map[i][2]==flag[k+1]&&map[i][3]==flag[k]))
- {
- flag[z]=i;
- break;
- }
- else if(map[i][2]==flag[k])
- {
- for(k=0;k<z;k++)
- {
- if(map[i][3]==flag[k])
- {
- r=1;
- flag[z]=i;
- }
- }
- }
- if(r==1)
- break;
- }//for
- }}
- for(i=0;i<z+1;i++)
- {
- tc+=cost[flag[i]];
- cout<<" "<<flag[i]<<" ";
- if(flag[i]==1)
- cout<<"\nSolvable";
- }
- cout<<"\nTotal cost: "<<tc;
- getch();
- }
- void mapping()
- {
- int i,j;
- for(i=1;i<10;i++)
- {
- cout<<"Enter nodes such that succ1 ir OR rel and succ2 and succ3 is in AND relation\n";
- for(j=0;j<4;j++)
- cin>>map[i][j];
- cout<<"\nEnter the cost of parent node: ";
- cin>>cost[i];
- }
- }
- ## MAGIC SQR EVEN
- #include<iostream.h>
- #include<conio.h>
- void init_mat();
- void disp_mat();
- void alloc();
- void do_magic();
- void check();
- int magic[20][20], even=0;
- void main()
- {
- clrscr();
- cout<<"Enter the dimension of the magic square:"; cin>>even;
- init_mat();
- alloc();
- do_magic();
- disp_mat();
- check();
- getch();
- }
- void init_mat()
- {
- for(int i=0; i<20; i++)
- for(int j=0; j<20; j++)
- magic[i][j]=0;
- }
- void alloc()
- {
- int x=1;
- for(int i=0; i<even; i++)
- for(int j=0; j<even; j++)
- {
- magic[i][j]=x++;
- }
- }
- void do_magic()
- {
- int i=0, j=0, x=0, temp=0;
- while(x<(even/2))
- {
- x++;
- temp = magic[i][j];
- magic[i][j] = magic[even-1-i][even-1-j];
- magic[even-1-i][even-1-j] = temp;
- i++; j++;
- }
- i=0, j=even-1;
- x=0;
- while(x<(even/2))
- {
- x++;
- temp = magic[i][j];
- magic[i][j] = magic[even-1-i][even-1-j];
- magic[even-1-i][even-1-j] = temp;
- i++; j--;
- }
- }
- void disp_mat()
- {
- for(int i=0; i<even; i++)
- {
- cout<<endl;
- for(int j=0; j<even; j++)
- {
- cout<<magic[i][j]<<" ";
- if(magic[i][j]<10) cout<<" ";
- }
- }
- }
- void check()
- {
- int sum=0;
- int i=(even/2)-1;
- for(int j=0; j<even; j++)
- sum+=magic[i][j];
- if(even==8)
- cout<<endl<<sum+10;
- if(even==12)
- cout<<endl<<sum+36;
- else
- cout<<endl<<sum;
- j=(even/2)-2;
- sum=0;
- for(i=0; i<even; i++)
- sum+=magic[i][j];
- cout<<endl<<sum;
- }
- ## PREDICATE LOGIC
- #include<stdio.h>
- #include<conio.h>
- #include<iostream.h>
- #include<string.h>
- char eng[80],temp[80];
- int gettoken(int a)
- {
- int i=0;
- while(eng[a]!=' ' && heng[a]!='\0')
- temp[i++]=eng[a++];
- temp[i]='\0';
- return a;
- }
- void main()
- {
- int i=0,check=0;
- char save[2][20];
- clrscr();
- cout<<endl<<"Enter simple english sentence:";
- cout<<endl<<"Enter 1.is a 2.all or 3.some tye sentences"<<endl;
- scanf("%[^\n]",&eng);
- while(strlen(eng))
- {
- if(eng[i]=='\0')
- break;
- i=gettoken(i);
- i++;
- if(strcmp(temp,"all")==0 || strcmp(temp,"every")==0 || strcmp(temp,"everyone")==0)
- {
- cout<<"Vx:";
- i=gettoken(i);
- i++;
- cout<<temp<<"(x)->";
- strcpy(save[0],temp);
- check=1;
- }
- else if(strcmp(temp,"some")==0 || strcmp(temp,"someone")==0)
- {
- cout<<"Vy:Fx" ;
- i=gettoken(i);
- i++;
- cout<<temp<<"(y)->";
- strcpy(save[0],"x");
- check=1;
- }
- else if(strcmp(temp,"is")==0 || strcmp(temp,"was")==0 || strcmp(temp,"are")==0 || strcmp(temp,"the")==0 || strcmp(temp,"they")==0 || strcmp(temp,"there")==0 || strcmp(temp,"their")==0 || strcmp(temp,"have")==0 || strcmp(temp,"has")==0)
- {
- check=1;
- }
- else if(check==0)
- strcpy(save[0],temp);
- else if(strcmp(temp,"a")==0 || strcmp(temp,"an")==0 || strcmp(temp,"the")==0);
- else
- {
- check=1;
- strcpy(save[1],temp);
- cout<<temp;
- }
- }
- cout<<endl<<save[1]<<"("<<save[0]<<")";
- getch();
- }
- ##TIC TAC TOE
- #include<iostream.h>
- #include<conio.h>
- void init_Board();
- void disp_Board();
- void go(int);
- int make2();
- int posWin(int);
- int isFree(int);
- int empty();
- int isWin();
- #define E 2
- #define X 3
- #define O 5
- #define Xposwin X*X*E
- #define Oposwin O*O*E
- #define Xwin X*X*X
- #define Owin O*O*O
- int Board[3][3];
- int turn=1;
- void main()
- {
- int choice=0;
- int ch=0;
- clrscr();
- init_Board();
- cout<<"What do u want to play?:\n\t1 for 1 player\n\t2 for 2 player\n";
- ch=getch()-48;
- if(ch==1)
- {
- while(turn<=9)
- {
- savePoint:
- if(turn%2==0)
- {
- choice = getch() - 48;
- if(isFree(choice))
- go(choice);
- else goto savePoint;
- }
- else
- {
- switch(turn)
- {
- case 1: go(make2());
- break;
- case 3: go(make2());
- break;
- case 5: if(((Board[0][1]==X)||(Board[1][0]))&&(Board[0][0]==E)) {go(1); break;}
- if(((Board[0][1]==X)||(Board[1][2]==X))&&(Board[0][2]==E)) {go(3); break;}
- if(((Board[1][0]==X)||(Board[2][1]))&&(Board[2][0]==E)) {go(7); break;}
- if(((Board[2][1]==X)||Board[1][2])&&(Board[2][2]==E)) {go(9); break;}
- if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
- if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
- go(make2());
- break;
- case 7: if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
- if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
- go(empty());
- break;
- case 9: if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
- if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
- go(empty());
- break;
- }
- }
- clrscr();
- disp_Board();
- turn++;
- if(posWin(Xwin)) {cout<<"X is Winner"; break;}
- if(posWin(Owin)) {cout<<"O is Winner"; break;}
- }
- }
- if(ch==2)
- {
- clrscr();
- cout<<"Enter place number in the board to place";
- while(1)
- {
- savePoint1:
- {
- choice = getch() - 48;
- if(isFree(choice))
- go(choice);
- else goto savePoint1;
- }
- clrscr();
- disp_Board();
- turn++;
- if(posWin(Xwin)) {cout<<"X is Winner"; break;}
- if(posWin(Owin)) {cout<<"O is Winner"; break;}
- }
- }
- if(turn>9) cout<<"Match is a DRAW!!!";
- getch();
- }
- void init_Board()
- {
- for(int i=0; i<3; i++)
- for(int j=0;j<3;j++)
- Board[i][j] = E;
- }
- void disp_Board()
- {
- for(int i=0; i<3; i++)
- {
- for(int j=0; j<3; j++)
- {
- if(Board[i][j]==E) cout<<".";
- if(Board[i][j]==X) cout<<"X";
- if(Board[i][j]==O) cout<<"O";
- }
- cout<<endl;
- }
- }
- void go(int move)
- {
- int temp=0;
- int Play=0;
- if(turn%2==0) Play = O;
- else Play = X;
- for(int i=0; i<3; i++)
- for(int j=0; j<3; j++)
- {temp++;if(temp==move) Board[i][j] = Play;}
- }
- int make2()
- {
- if(posWin(Owin)!=0) return posWin(Oposwin);
- if(Board[1][1]==E) return 5;
- else if(Board[0][1]==E) return 2;
- else if(Board[1][0]==E) return 4;
- else if(Board[1][2]==E) return 6;
- else if(Board[2][1]==E) return 8;
- return 0;
- }
- int isFree(int pos)
- {
- int temp=0;
- for(int i=0; i<3; i++)
- for(int j=0; j<3; j++)
- {
- temp++;
- if(temp==pos)
- if(Board[i][j]==E) return 1;
- else {cout<<"Enter valid input";return 0;}
- }
- return 0;
- }
- int posWin(int Player)
- {
- static int val=1, i=0, j=0;
- for(i=0; i<3; i++)
- {
- for(j=0; j<3; j++) val*=Board[i][j];
- if(val==Player)
- {
- if(Player==Xwin || Player==Owin) return 1;
- for(j=0;j<3;j++) if(Board[i][j]==E) return((3*(i))+(j)+1);
- }
- else val=1;
- }
- val=1;
- for(j=0; j<3; j++)
- {
- for(i=0; i<3; i++) val*=Board[i][j];
- if(val==Player)
- {
- if(Player==Xwin || Player==Owin) return 1;
- for(i=0;i<3;i++) if(Board[i][j]==E) return((3*(i))+(j)+1);
- }
- else val=1;
- }
- if((Board[0][0]*Board[1][1]*Board[2][2])==Player)
- {
- if(Player==Xwin || Player==Owin) return 1;
- if(Board[0][0]==E) return 1;
- if(Board[1][1]==E) return 5;
- if(Board[2][2]==E) return 9;
- }
- if((Board[0][2]*Board[1][1]*Board[2][0])==Player)
- {
- if(Player==Xwin || Player==Owin) return 1;
- if(Board[0][2]==E) return 1;
- if(Board[1][1]==E) return 5;
- if(Board[2][0]==E) return 9;
- }
- return 0;
- }
- int empty()
- {
- for(int i=0; i<3; i++)
- for(int j=0; j<3; j++)
- if(Board[i][j]==E) return((3*(i))+(j)+1);
- return 1;
- }
- ##WEATHER PREDICTION
- #include<iostream.h>
- #include<conio.h>
- #include<string.h>
- #include<process.h>
- char temp[10],dur[30],month[30];
- void input()
- {
- cout<<"Enter the temperature(hot/cold/pleasant): ";
- cin>>temp;
- cout<<"\nEnter the duration(longday/longnight/equal): ";
- cin>>dur;
- cout<<"\nEnter the month(March-May,June-Aug,Aug-Oct,Nov-Feb): ";
- cin>>month;
- }
- void find()
- {
- if(strcmp(temp,"hot")==0&&strcmp(dur,"longday")==0&&strcmp(month,"March-May")==0)
- cout<<"Season is Summer\n";
- if(strcmp(temp,"cold")==0&&strcmp(dur,"longnight")==0&&strcmp(month,"Nov-Feb")==0)
- cout<<"Season is Winter\n";
- if(strcmp(temp,"cool")==0&&strcmp(dur,"equal")==0&&strcmp(month,"June-Aug")==0)
- cout<<"Season is Rainy\n";
- if(strcmp(temp,"pleasant")==0&&strcmp(dur,"equal")==0&&strcmp(month,"Aug-Oct")==0)
- cout<<"Season is Spring\n";
- else
- cout<<"\nIncorrect conditions";
- }
- void main()
- {
- int ch;
- clrscr();
- do
- {
- cout<<"1.Input\n2.Find the Season\n3.Exit\nEnter your option: ";
- cin>>ch;
- switch(ch)
- {
- case 1:input();
- break;
- case 2:find();
- break;
- case 3:exit(0);
- break;
- }
- }while(ch!=3);
- getch();
- }
- ##WATER JUG
- #include<conio.h>
- #include<stdio.h>
- int main() {
- int jug1=0;
- int jug2=0;
- int max1;
- int max2;
- int obtain;
- int step=1;
- int temp = 0;
- int bhag = 0;
- int a=0;
- int b=0;
- clrscr();
- printf("Enter capacity of jug 1: ");
- scanf("%d",&max1);
- printf("Enter capacity of jug 2: ");
- scanf("%d",&max2);
- b=max2;
- printf("Enter volume to obtain: ");
- scanf("%d",&obtain);
- printf("\nComputation\n");
- printf("\nJug1\tJug2\n");
- printf("\n0\t0\n");
- while(jug1!=obtain) {
- bhag = step%7;
- if(step>6) bhag++;
- if(step==1) {
- //fill smaller one to max capacity
- jug1 = 0;
- jug2 = max2;
- }
- else if(step==2) {
- //same as step 4
- if(max1>=jug1+jug2) {
- jug1 = jug1+jug2;
- jug2 = 0;
- }
- else {
- temp = jug1;
- jug1 = jug1+(max1-jug1);
- jug2 = jug2-(max1-temp);
- }
- }
- else if(bhag==3) {
- jug2 = max2;
- }
- else if(bhag==4) {
- if(max1>=jug1+jug2) {
- jug1 = jug1+jug2;
- jug2 = 0;
- }
- else {
- temp = jug1;
- jug1 = jug1+(max1-jug1);
- jug2 = jug2-(max1-temp);
- }
- }
- else if(bhag==5) {
- jug1 = 0;
- }
- else if(bhag==6) {
- jug1 = jug2;
- jug2 = 0;
- }
- if(a!=jug1 || b!=jug2){
- printf("%d\t%d\n",jug1,jug2);}
- a=jug1;
- b=jug2;
- step++;
- }
- getch();
- return 0;
- }
- ##MEDICAL
- #include<stdio.h>
- #include<conio.h>
- void disp();
- int ctr=0;
- void med();
- char sym1[100];
- char sym2[100];
- void main()
- {
- int n;
- char ch;
- char sym[100];
- clrscr();
- do
- {
- printf("Medical diagnosis system\n 1.Diagnosis\n 2.Prescribe medicines\n 3.Exit system\n");
- printf("Enter options:\n");
- scanf("%d",&n);
- switch(n)
- {
- case 1: disp();
- break;
- case 2: med();
- break;
- case 3: exit();
- }
- }
- while(n!=3);
- getch();
- }
- void disp()
- {
- printf("Enter 2 symptoms in the same order as mentioned\n 1.fever\n 2.vomitting\n 3.bodyache\n 4.lung congestion\n 5.headache\n 6.insomnia\n 7.loss of appetite\n");
- printf("Enter any two symptoms\n");
- scanf("%s",sym1);
- scanf("%s",sym2);
- if((strcmp(sym1,"fever")==0)&&(strcmp(sym2,"vomitting")==0))
- {
- ctr=1;
- printf("disease detected is malaria\n");
- printf("if you want suggestions for medicines select 2 from menu:\n");
- }
- else
- if((strcmp(sym1,"fever")==0)&&(strcmp(sym2,"lung congestion")==0))
- {
- ctr=2;
- printf("Disease detected is peneumonia\n");
- printf("if you want suggestions for medicines select 2 from menu\n");
- }
- else
- if((strcmp(sym1,"headache")==0)&&(strcmp(sym2,"insomnia")==0))
- {
- ctr=3;
- printf("Disease detected is high blood pressure\n");
- printf("if you want suggestions for medicines select 2 from the menu\n");
- }
- else
- if((strcmp(sym1,"bodyache")==0)&&(strcmp(sym2,"loss of appetite")==0))
- {
- ctr=4;
- printf("Disease detected is jaundice\n");
- printf("If you want suggestions for medicines select 2 from menu\n");
- }
- else
- printf("Enter symptoms correctly. System unable to detect disease\n");
- }
- void med()
- {
- if(ctr==1)
- {
- printf("Cure for malaria\n");
- printf("1.Take two doses of quinine\n");
- printf("2.Take plenty of rest\n3.Ensure a good diet\n");
- }
- if(ctr==2)
- {
- printf("Cure for pneumonia\n");
- printf("\n1.Take asphilix tablets thrice a day\n2.Avoid chilled drinks\n3.Take rest");
- }
- if(ctr==3)
- {
- printf("cure for high blood pressure\n");
- printf("1.Erocin twice a day\n 2.Avoid salt and sugar\n 3.Maintain a healthy diet\n 4.Do exercise daily\n");
- }
- if(ctr==4)
- {
- printf("Cure for jaundice\n");
- printf("1.Take doses of liver tonics\n");
- printf("2.Follow a bland diet\n3.Regular drips if required\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement