Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.54 KB | None | 0 0
  1. ## AOSTAR
  2. #include<iostream.h>
  3. #include<conio.h>
  4. void mapping();
  5. int map[15][4],flag[10],n,tc=0,cost[10];
  6. void main()
  7. {
  8. int i,j,k,z,r;
  9. clrscr();
  10. cout<<"Enter the no. of nodes: ";
  11. cin>>n;
  12. mapping();
  13. for(i=1;i<=n;i++)
  14. {
  15. cout<<endl;
  16. for(j=0;j<4;j++)
  17. cout<<map[i][j]<<" ";
  18. }
  19. cout<<"Enter the no. of goals: ";
  20. cin>>z;
  21. for(i=0;i<z;i++)
  22. cin>>flag[i];
  23. for(i=n;i>0;i--)
  24. {
  25. if(map[i][1]!=0||map[i][2]!=0)
  26. {
  27. z=0;
  28. r=0;
  29. while(flag[z]!=0)
  30. z++;
  31. for(k=0;k<z;k++)
  32. {
  33. 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]))
  34. {
  35. flag[z]=i;
  36. break;
  37. }
  38. else if(map[i][2]==flag[k])
  39. {
  40. for(k=0;k<z;k++)
  41. {
  42. if(map[i][3]==flag[k])
  43. {
  44. r=1;
  45. flag[z]=i;
  46. }
  47. }
  48. }
  49. if(r==1)
  50. break;
  51. }//for
  52. }}
  53. for(i=0;i<z+1;i++)
  54. {
  55. tc+=cost[flag[i]];
  56. cout<<" "<<flag[i]<<" ";
  57. if(flag[i]==1)
  58. cout<<"\nSolvable";
  59. }
  60. cout<<"\nTotal cost: "<<tc;
  61. getch();
  62. }
  63. void mapping()
  64. {
  65. int i,j;
  66. for(i=1;i<10;i++)
  67. {
  68. cout<<"Enter nodes such that succ1 ir OR rel and succ2 and succ3 is in AND relation\n";
  69. for(j=0;j<4;j++)
  70. cin>>map[i][j];
  71. cout<<"\nEnter the cost of parent node: ";
  72. cin>>cost[i];
  73. }
  74. }
  75.  
  76.  
  77. ## MAGIC SQR EVEN
  78. #include<iostream.h>
  79. #include<conio.h>
  80. void init_mat();
  81. void disp_mat();
  82. void alloc();
  83. void do_magic();
  84. void check();
  85. int magic[20][20], even=0;
  86. void main()
  87. {
  88. clrscr();
  89. cout<<"Enter the dimension of the magic square:"; cin>>even;
  90. init_mat();
  91. alloc();
  92. do_magic();
  93. disp_mat();
  94. check();
  95. getch();
  96. }
  97. void init_mat()
  98. {
  99. for(int i=0; i<20; i++)
  100. for(int j=0; j<20; j++)
  101. magic[i][j]=0;
  102. }
  103. void alloc()
  104. {
  105. int x=1;
  106. for(int i=0; i<even; i++)
  107. for(int j=0; j<even; j++)
  108. {
  109. magic[i][j]=x++;
  110. }
  111. }
  112. void do_magic()
  113. {
  114. int i=0, j=0, x=0, temp=0;
  115. while(x<(even/2))
  116. {
  117. x++;
  118. temp = magic[i][j];
  119. magic[i][j] = magic[even-1-i][even-1-j];
  120. magic[even-1-i][even-1-j] = temp;
  121. i++; j++;
  122. }
  123. i=0, j=even-1;
  124. x=0;
  125. while(x<(even/2))
  126. {
  127. x++;
  128. temp = magic[i][j];
  129. magic[i][j] = magic[even-1-i][even-1-j];
  130. magic[even-1-i][even-1-j] = temp;
  131. i++; j--;
  132. }
  133. }
  134. void disp_mat()
  135. {
  136. for(int i=0; i<even; i++)
  137. {
  138. cout<<endl;
  139. for(int j=0; j<even; j++)
  140. {
  141. cout<<magic[i][j]<<" ";
  142. if(magic[i][j]<10) cout<<" ";
  143. }
  144. }
  145. }
  146. void check()
  147. {
  148. int sum=0;
  149. int i=(even/2)-1;
  150. for(int j=0; j<even; j++)
  151. sum+=magic[i][j];
  152. if(even==8)
  153. cout<<endl<<sum+10;
  154. if(even==12)
  155. cout<<endl<<sum+36;
  156. else
  157. cout<<endl<<sum;
  158. j=(even/2)-2;
  159. sum=0;
  160. for(i=0; i<even; i++)
  161. sum+=magic[i][j];
  162. cout<<endl<<sum;
  163. }
  164.  
  165.  
  166. ## PREDICATE LOGIC
  167. #include<stdio.h>
  168. #include<conio.h>
  169. #include<iostream.h>
  170. #include<string.h>
  171. char eng[80],temp[80];
  172. int gettoken(int a)
  173. {
  174. int i=0;
  175. while(eng[a]!=' ' && heng[a]!='\0')
  176. temp[i++]=eng[a++];
  177. temp[i]='\0';
  178. return a;
  179. }
  180. void main()
  181. {
  182. int i=0,check=0;
  183. char save[2][20];
  184. clrscr();
  185. cout<<endl<<"Enter simple english sentence:";
  186. cout<<endl<<"Enter 1.is a 2.all or 3.some tye sentences"<<endl;
  187. scanf("%[^\n]",&eng);
  188. while(strlen(eng))
  189. {
  190.  
  191. if(eng[i]=='\0')
  192. break;
  193. i=gettoken(i);
  194. i++;
  195. if(strcmp(temp,"all")==0 || strcmp(temp,"every")==0 || strcmp(temp,"everyone")==0)
  196. {
  197. cout<<"Vx:";
  198. i=gettoken(i);
  199. i++;
  200. cout<<temp<<"(x)->";
  201. strcpy(save[0],temp);
  202. check=1;
  203. }
  204. else if(strcmp(temp,"some")==0 || strcmp(temp,"someone")==0)
  205. {
  206. cout<<"Vy:Fx" ;
  207. i=gettoken(i);
  208. i++;
  209. cout<<temp<<"(y)->";
  210. strcpy(save[0],"x");
  211. check=1;
  212. }
  213. 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)
  214. {
  215. check=1;
  216. }
  217. else if(check==0)
  218. strcpy(save[0],temp);
  219. else if(strcmp(temp,"a")==0 || strcmp(temp,"an")==0 || strcmp(temp,"the")==0);
  220. else
  221. {
  222. check=1;
  223. strcpy(save[1],temp);
  224. cout<<temp;
  225. }
  226. }
  227. cout<<endl<<save[1]<<"("<<save[0]<<")";
  228. getch();
  229. }
  230.  
  231.  
  232. ##TIC TAC TOE
  233. #include<iostream.h>
  234. #include<conio.h>
  235. void init_Board();
  236. void disp_Board();
  237. void go(int);
  238. int make2();
  239. int posWin(int);
  240. int isFree(int);
  241. int empty();
  242. int isWin();
  243. #define E 2
  244. #define X 3
  245. #define O 5
  246. #define Xposwin X*X*E
  247. #define Oposwin O*O*E
  248. #define Xwin X*X*X
  249. #define Owin O*O*O
  250. int Board[3][3];
  251. int turn=1;
  252. void main()
  253. {
  254. int choice=0;
  255. int ch=0;
  256. clrscr();
  257. init_Board();
  258. cout<<"What do u want to play?:\n\t1 for 1 player\n\t2 for 2 player\n";
  259. ch=getch()-48;
  260. if(ch==1)
  261. {
  262. while(turn<=9)
  263. {
  264. savePoint:
  265. if(turn%2==0)
  266. {
  267. choice = getch() - 48;
  268. if(isFree(choice))
  269. go(choice);
  270. else goto savePoint;
  271. }
  272.  
  273. else
  274. {
  275. switch(turn)
  276. {
  277. case 1: go(make2());
  278. break;
  279. case 3: go(make2());
  280. break;
  281. case 5: if(((Board[0][1]==X)||(Board[1][0]))&&(Board[0][0]==E)) {go(1); break;}
  282. if(((Board[0][1]==X)||(Board[1][2]==X))&&(Board[0][2]==E)) {go(3); break;}
  283. if(((Board[1][0]==X)||(Board[2][1]))&&(Board[2][0]==E)) {go(7); break;}
  284. if(((Board[2][1]==X)||Board[1][2])&&(Board[2][2]==E)) {go(9); break;}
  285. if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
  286. if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
  287. go(make2());
  288. break;
  289. case 7: if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
  290. if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
  291. go(empty());
  292. break;
  293. case 9: if(posWin(Xposwin)!=0) {go(posWin(Xposwin)); break;}
  294. if(posWin(Oposwin)!=0) {go(posWin(Oposwin)); break;}
  295. go(empty());
  296. break;
  297. }
  298. }
  299.  
  300. clrscr();
  301. disp_Board();
  302. turn++;
  303. if(posWin(Xwin)) {cout<<"X is Winner"; break;}
  304. if(posWin(Owin)) {cout<<"O is Winner"; break;}
  305. }
  306. }
  307. if(ch==2)
  308. {
  309. clrscr();
  310. cout<<"Enter place number in the board to place";
  311. while(1)
  312. {
  313. savePoint1:
  314. {
  315. choice = getch() - 48;
  316. if(isFree(choice))
  317. go(choice);
  318. else goto savePoint1;
  319. }
  320. clrscr();
  321. disp_Board();
  322. turn++;
  323. if(posWin(Xwin)) {cout<<"X is Winner"; break;}
  324. if(posWin(Owin)) {cout<<"O is Winner"; break;}
  325. }
  326. }
  327. if(turn>9) cout<<"Match is a DRAW!!!";
  328. getch();
  329. }
  330. void init_Board()
  331. {
  332. for(int i=0; i<3; i++)
  333. for(int j=0;j<3;j++)
  334. Board[i][j] = E;
  335. }
  336. void disp_Board()
  337. {
  338. for(int i=0; i<3; i++)
  339. {
  340. for(int j=0; j<3; j++)
  341. {
  342. if(Board[i][j]==E) cout<<".";
  343. if(Board[i][j]==X) cout<<"X";
  344. if(Board[i][j]==O) cout<<"O";
  345. }
  346. cout<<endl;
  347. }
  348. }
  349. void go(int move)
  350. {
  351. int temp=0;
  352. int Play=0;
  353. if(turn%2==0) Play = O;
  354. else Play = X;
  355. for(int i=0; i<3; i++)
  356. for(int j=0; j<3; j++)
  357. {temp++;if(temp==move) Board[i][j] = Play;}
  358. }
  359. int make2()
  360. {
  361. if(posWin(Owin)!=0) return posWin(Oposwin);
  362. if(Board[1][1]==E) return 5;
  363. else if(Board[0][1]==E) return 2;
  364. else if(Board[1][0]==E) return 4;
  365. else if(Board[1][2]==E) return 6;
  366. else if(Board[2][1]==E) return 8;
  367. return 0;
  368. }
  369. int isFree(int pos)
  370. {
  371. int temp=0;
  372. for(int i=0; i<3; i++)
  373. for(int j=0; j<3; j++)
  374. {
  375. temp++;
  376. if(temp==pos)
  377. if(Board[i][j]==E) return 1;
  378. else {cout<<"Enter valid input";return 0;}
  379. }
  380. return 0;
  381. }
  382. int posWin(int Player)
  383. {
  384. static int val=1, i=0, j=0;
  385. for(i=0; i<3; i++)
  386. {
  387. for(j=0; j<3; j++) val*=Board[i][j];
  388. if(val==Player)
  389. {
  390. if(Player==Xwin || Player==Owin) return 1;
  391. for(j=0;j<3;j++) if(Board[i][j]==E) return((3*(i))+(j)+1);
  392. }
  393. else val=1;
  394. }
  395. val=1;
  396. for(j=0; j<3; j++)
  397. {
  398. for(i=0; i<3; i++) val*=Board[i][j];
  399. if(val==Player)
  400. {
  401. if(Player==Xwin || Player==Owin) return 1;
  402. for(i=0;i<3;i++) if(Board[i][j]==E) return((3*(i))+(j)+1);
  403. }
  404. else val=1;
  405. }
  406. if((Board[0][0]*Board[1][1]*Board[2][2])==Player)
  407. {
  408. if(Player==Xwin || Player==Owin) return 1;
  409. if(Board[0][0]==E) return 1;
  410. if(Board[1][1]==E) return 5;
  411. if(Board[2][2]==E) return 9;
  412. }
  413. if((Board[0][2]*Board[1][1]*Board[2][0])==Player)
  414. {
  415. if(Player==Xwin || Player==Owin) return 1;
  416. if(Board[0][2]==E) return 1;
  417. if(Board[1][1]==E) return 5;
  418. if(Board[2][0]==E) return 9;
  419. }
  420. return 0;
  421. }
  422. int empty()
  423. {
  424. for(int i=0; i<3; i++)
  425. for(int j=0; j<3; j++)
  426. if(Board[i][j]==E) return((3*(i))+(j)+1);
  427. return 1;
  428. }
  429.  
  430. ##WEATHER PREDICTION
  431. #include<iostream.h>
  432. #include<conio.h>
  433. #include<string.h>
  434. #include<process.h>
  435. char temp[10],dur[30],month[30];
  436. void input()
  437. {
  438. cout<<"Enter the temperature(hot/cold/pleasant): ";
  439. cin>>temp;
  440. cout<<"\nEnter the duration(longday/longnight/equal): ";
  441. cin>>dur;
  442. cout<<"\nEnter the month(March-May,June-Aug,Aug-Oct,Nov-Feb): ";
  443. cin>>month;
  444. }
  445. void find()
  446. {
  447. if(strcmp(temp,"hot")==0&&strcmp(dur,"longday")==0&&strcmp(month,"March-May")==0)
  448. cout<<"Season is Summer\n";
  449. if(strcmp(temp,"cold")==0&&strcmp(dur,"longnight")==0&&strcmp(month,"Nov-Feb")==0)
  450. cout<<"Season is Winter\n";
  451. if(strcmp(temp,"cool")==0&&strcmp(dur,"equal")==0&&strcmp(month,"June-Aug")==0)
  452. cout<<"Season is Rainy\n";
  453. if(strcmp(temp,"pleasant")==0&&strcmp(dur,"equal")==0&&strcmp(month,"Aug-Oct")==0)
  454. cout<<"Season is Spring\n";
  455. else
  456. cout<<"\nIncorrect conditions";
  457. }
  458. void main()
  459. {
  460. int ch;
  461. clrscr();
  462. do
  463. {
  464. cout<<"1.Input\n2.Find the Season\n3.Exit\nEnter your option: ";
  465. cin>>ch;
  466. switch(ch)
  467. {
  468. case 1:input();
  469. break;
  470. case 2:find();
  471. break;
  472. case 3:exit(0);
  473. break;
  474. }
  475. }while(ch!=3);
  476. getch();
  477. }
  478.  
  479. ##WATER JUG
  480. #include<conio.h>
  481. #include<stdio.h>
  482. int main() {
  483. int jug1=0;
  484. int jug2=0;
  485. int max1;
  486. int max2;
  487. int obtain;
  488. int step=1;
  489. int temp = 0;
  490. int bhag = 0;
  491. int a=0;
  492. int b=0;
  493. clrscr();
  494. printf("Enter capacity of jug 1: ");
  495. scanf("%d",&max1);
  496. printf("Enter capacity of jug 2: ");
  497. scanf("%d",&max2);
  498. b=max2;
  499. printf("Enter volume to obtain: ");
  500. scanf("%d",&obtain);
  501. printf("\nComputation\n");
  502. printf("\nJug1\tJug2\n");
  503. printf("\n0\t0\n");
  504. while(jug1!=obtain) {
  505. bhag = step%7;
  506. if(step>6) bhag++;
  507. if(step==1) {
  508. //fill smaller one to max capacity
  509. jug1 = 0;
  510. jug2 = max2;
  511. }
  512. else if(step==2) {
  513. //same as step 4
  514. if(max1>=jug1+jug2) {
  515. jug1 = jug1+jug2;
  516. jug2 = 0;
  517. }
  518. else {
  519. temp = jug1;
  520. jug1 = jug1+(max1-jug1);
  521. jug2 = jug2-(max1-temp);
  522. }
  523. }
  524. else if(bhag==3) {
  525.  
  526. jug2 = max2;
  527. }
  528. else if(bhag==4) {
  529. if(max1>=jug1+jug2) {
  530. jug1 = jug1+jug2;
  531. jug2 = 0;
  532. }
  533. else {
  534. temp = jug1;
  535. jug1 = jug1+(max1-jug1);
  536. jug2 = jug2-(max1-temp);
  537. }
  538. }
  539. else if(bhag==5) {
  540. jug1 = 0;
  541. }
  542. else if(bhag==6) {
  543. jug1 = jug2;
  544. jug2 = 0;
  545. }
  546. if(a!=jug1 || b!=jug2){
  547. printf("%d\t%d\n",jug1,jug2);}
  548. a=jug1;
  549. b=jug2;
  550. step++;
  551. }
  552. getch();
  553. return 0;
  554. }
  555.  
  556. ##MEDICAL
  557. #include<stdio.h>
  558. #include<conio.h>
  559. void disp();
  560. int ctr=0;
  561. void med();
  562. char sym1[100];
  563. char sym2[100];
  564. void main()
  565. {
  566. int n;
  567. char ch;
  568. char sym[100];
  569. clrscr();
  570. do
  571. {
  572. printf("Medical diagnosis system\n 1.Diagnosis\n 2.Prescribe medicines\n 3.Exit system\n");
  573. printf("Enter options:\n");
  574. scanf("%d",&n);
  575. switch(n)
  576. {
  577. case 1: disp();
  578. break;
  579. case 2: med();
  580. break;
  581. case 3: exit();
  582. }
  583. }
  584. while(n!=3);
  585. getch();
  586. }
  587. void disp()
  588. {
  589. 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");
  590. printf("Enter any two symptoms\n");
  591. scanf("%s",sym1);
  592. scanf("%s",sym2);
  593. if((strcmp(sym1,"fever")==0)&&(strcmp(sym2,"vomitting")==0))
  594. {
  595. ctr=1;
  596. printf("disease detected is malaria\n");
  597. printf("if you want suggestions for medicines select 2 from menu:\n");
  598. }
  599. else
  600. if((strcmp(sym1,"fever")==0)&&(strcmp(sym2,"lung congestion")==0))
  601. {
  602. ctr=2;
  603. printf("Disease detected is peneumonia\n");
  604. printf("if you want suggestions for medicines select 2 from menu\n");
  605. }
  606. else
  607. if((strcmp(sym1,"headache")==0)&&(strcmp(sym2,"insomnia")==0))
  608. {
  609. ctr=3;
  610. printf("Disease detected is high blood pressure\n");
  611. printf("if you want suggestions for medicines select 2 from the menu\n");
  612. }
  613. else
  614. if((strcmp(sym1,"bodyache")==0)&&(strcmp(sym2,"loss of appetite")==0))
  615. {
  616. ctr=4;
  617. printf("Disease detected is jaundice\n");
  618. printf("If you want suggestions for medicines select 2 from menu\n");
  619. }
  620. else
  621. printf("Enter symptoms correctly. System unable to detect disease\n");
  622. }
  623.  
  624. void med()
  625. {
  626. if(ctr==1)
  627. {
  628. printf("Cure for malaria\n");
  629. printf("1.Take two doses of quinine\n");
  630. printf("2.Take plenty of rest\n3.Ensure a good diet\n");
  631. }
  632. if(ctr==2)
  633. {
  634. printf("Cure for pneumonia\n");
  635. printf("\n1.Take asphilix tablets thrice a day\n2.Avoid chilled drinks\n3.Take rest");
  636. }
  637. if(ctr==3)
  638. {
  639. printf("cure for high blood pressure\n");
  640. printf("1.Erocin twice a day\n 2.Avoid salt and sugar\n 3.Maintain a healthy diet\n 4.Do exercise daily\n");
  641. }
  642. if(ctr==4)
  643. {
  644. printf("Cure for jaundice\n");
  645. printf("1.Take doses of liver tonics\n");
  646. printf("2.Follow a bland diet\n3.Regular drips if required\n");
  647. }
  648. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement