Guest User

Untitled

a guest
Dec 6th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.12 KB | None | 0 0
  1.  
  2.  
  3. #include <cctype>
  4. #include <ctime>
  5. #include <functional>
  6. #include <iostream>
  7. #include <random>
  8. #include <string>
  9. #include <vector>
  10. #include <windows.h>
  11.  
  12. void cls()
  13. {
  14. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  15. COORD coordScreen = { 0, 0 };
  16. DWORD cCharsWritten;
  17. CONSOLE_SCREEN_BUFFER_INFO csbi;
  18. DWORD dwConSize;
  19. if( !GetConsoleScreenBufferInfo( hConsole, &csbi ))
  20. return;
  21. dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
  22. if( !FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten ) ||
  23. !GetConsoleScreenBufferInfo( hConsole, &csbi ) ||
  24. !FillConsoleOutputAttribute( hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten ))
  25. return;
  26. SetConsoleCursorPosition( hConsole, coordScreen );
  27. }
  28. template <typename T>
  29. T read(const std::string& request)
  30. {
  31. std::cout << request;
  32. T value;
  33. bool repeat = true;
  34. while (repeat)
  35. {
  36. repeat = false;
  37. std::cin >> value;
  38. if(!std::cin)
  39. {
  40. std::cout << "Invalid input\n";
  41. std::cin.clear();
  42. repeat = true;
  43. while(!isspace(std::cin.get()))
  44. ;
  45. }
  46. }
  47. return value;
  48. }
  49. bool ask(const std::string& question)
  50. {
  51. std::cout << question << '\n';
  52. char c;
  53. do
  54. {
  55. c = tolower(read<char>(""));
  56. if(c != 'y' && c != 'n')
  57. std::cout << "Invalid answer. Only Y, y, N and n are allowed\n";
  58. }
  59. while(c != 'y' && c != 'n');
  60. return c == 'y';
  61. }
  62.  
  63. void application5()
  64. {
  65. int number,guess;
  66.  
  67. while(number!=guess)
  68. {
  69.  
  70.  
  71. do
  72. {
  73. cls();
  74. std::cout<<"Enter a number 13 to 17\n";
  75. std::cin>>number;
  76. switch(number)
  77. {
  78.  
  79. case 13:
  80. {
  81. number=number*7.5433;
  82. break;
  83. }
  84. case 14:
  85. {
  86. number=number*3.9433;
  87. break;
  88. }
  89. case 15:
  90. {
  91. number=number*11.2433;
  92. break;
  93. }
  94. case 16:
  95. {
  96. number=number*4.69433;
  97. break;
  98. }
  99. case 17:
  100. {
  101. number=number*13.9433;
  102. break;
  103. }
  104. default:
  105. {
  106. std::cout<<"You haven't entered 13,14,15,16 or 17";
  107. }
  108. }
  109. cls();
  110.  
  111. std::cout<<"Now you must guess the number\n";
  112.  
  113. int times=0;
  114.  
  115. do
  116. {
  117. times++;
  118. std::cin>>guess;
  119.  
  120. if(guess<number)
  121. {
  122.  
  123. std::cout<<"Too small\n";
  124. }
  125. if(guess>number)
  126. {
  127.  
  128. std::cout<<"Too hight\n";
  129. }
  130. if(guess==number)
  131. {
  132. cls();
  133. std::cout<<"Congratulations1! You discovered the number\n";
  134. std::cout<<"The number was " << number << "\n"<<std::endl;
  135. std::cout<<"It took you "<<times<<" times to guess the number.\n\n";
  136. }
  137. }
  138. while(guess<number || guess>number);
  139. }
  140. while(ask("Do you want to try again?(Y OR N)"));
  141. }
  142.  
  143. }
  144.  
  145.  
  146. void application4()
  147. {
  148.  
  149. cls();
  150.  
  151. int number[5];
  152.  
  153. std::cout<<"Enter the number of pancakes eaten for the each Person\n";
  154. std::cout<<"First person:";
  155. std::cin>>number[1];
  156. std::cout<<"Second person:";
  157. std::cin>>number[2];
  158. std::cout<<"Third person:";
  159. std::cin>>number[3];
  160. std::cout<<"Fourth person:";
  161. std::cin>>number[4];
  162. std::cout<<"Fifth person:";
  163. std::cin>>number[5];
  164.  
  165. cls();
  166.  
  167. //The most eaten.
  168.  
  169. if(number[1]>number[2]&&number[1]>number[3]&&number[1]>number[4]&&number[1]>number[5])
  170. {
  171. std::cout<<"First person have eaten the most pancakes ("<< number[1]<< ")\n";
  172. }
  173. if(number[2]>number[1]&&number[2]>number[3]&&number[2]>number[4]&&number[2]>number[5])
  174. {
  175. std::cout<<"Second person have eaten the most pancakes ("<< number[2]<< ")\n";
  176. }
  177.  
  178. if(number[3]>number[1]&&number[3]>number[2]&&number[3]>number[4]&&number[3]>number[5])
  179. {
  180. std::cout<<"Third person have eaten the most pancakes ("<< number[3]<< ")\n";
  181. }
  182.  
  183. if(number[4]>number[1]&&number[4]>number[2]&&number[4]>number[3]&&number[4]>number[5])
  184. {
  185. std::cout<<"Fourth person have eaten the most pancakes ("<< number[4]<< ")\n";
  186. }
  187. if(number[5]>number[1]&&number[5]>number[2]&&number[5]>number[3]&&number[5]>number[4])
  188. {
  189. std::cout<<"Fifth person have eaten the most pancakes ("<< number[5]<< ")\n";
  190. }
  191.  
  192. std::cin.get(); //The fewest eaten;
  193.  
  194.  
  195. if(number[1]<number[2]&&number[1]<number[3]&&number[1]<number[4]&&number[1]<number[5])
  196. {
  197. std::cout<<"First person have eaten the fewest pancakes ("<< number[1]<< ")";
  198. }
  199. if(number[2]<number[1]&&number[2]<number[3]&&number[2]<number[4]&&number[2]<number[5])
  200. {
  201. std::cout<<"Second person have eaten the fewest pancakes ("<< number[2]<< ")";
  202. }
  203.  
  204. if(number[3]<number[1]&&number[3]<number[2]&&number[3]<number[4]&&number[3]<number[5])
  205. {
  206. std::cout<<"Third person have eaten the fewest pancakes ("<< number[3]<< ")";
  207. }
  208.  
  209. if(number[4]<number[1]&&number[4]<number[2]&&number[4]<number[3]&&number[4]<number[5])
  210. {
  211. std::cout<<"Fourth person have eaten the fewest pancakes ("<< number[4]<< ")";
  212. }
  213. if(number[5]<number[1]&&number[5]<number[2]&&number[5]<number[3]&&number[5]<number[4])
  214. {
  215. std::cout<<"Fifth person have eaten the fewest pancakes ("<< number[5]<< ")";
  216. }
  217.  
  218.  
  219. }
  220. void application3()
  221. {
  222. double number;
  223. int times = 0;
  224.  
  225. cls();
  226.  
  227. std::cout<<"Please enter a number other than 5\n";
  228.  
  229. do
  230. {
  231. times++;
  232. std::cin>>number;
  233. std::cout<<"Enter a number,other than 5\n";
  234. }
  235. while(number !=5&&times!=10);
  236. cls();
  237.  
  238. if(times==10)
  239. {
  240. std::cout<<"Wow, you're more patient then I am, you win.\n\n";
  241. }
  242. else
  243. {
  244. std::cout<<"Hey , you weren't supossed to enter 5!\n\n";
  245. }
  246. }
  247. void application2()
  248. {
  249. int howmany;
  250. int choice;
  251.  
  252. do
  253. {
  254. std::cout<<"There's the list of what you can buy\n";
  255. std::cout<<"<<--Cola-->>{1}\n<<--Beer-->>{2}\n<<--Sprite-->>{3}\n<<--Wine-->>{4}\n<<--Apple Juice-->>{5}\n";
  256. std::cin>>choice;
  257.  
  258. switch(choice)
  259. {
  260. case 1:
  261. {
  262. std::cout<<"An bottle of Cola it's 2$, how many do you want?\n";
  263. std::cin>>howmany;
  264. std::cout<<"You have to pay " << howmany*2<<" $\n";
  265. }
  266. break;
  267.  
  268. case 2:
  269. {
  270. cls();
  271. std::cout<<"An bottle of Beer it's 3.3$, how many do you want?\n";
  272. std::cin>>howmany;
  273. std::cout<<"You have to pay " << howmany*3.3<<" $\n";
  274. }
  275. break;
  276.  
  277. case 3:
  278. {
  279. cls();
  280. std::cout<<"An bottle of Sprite it's 1.5$, how many do you want?\n";
  281. std::cin>>howmany;
  282. std::cout<<"You have to pay " << howmany*1.5<<" $\n";
  283. }
  284. break;
  285.  
  286. case 4:
  287. {
  288. cls();
  289. std::cout<<"An bottle of Wine it's 12$, how many do you want?\n";
  290. std::cin>>howmany;
  291. std::cout<<"You have to pay " << howmany*12<<" $\n";
  292. }
  293. break;
  294.  
  295. case 5:
  296. {
  297. cls();
  298. std::cout<<"An bottle of Apple Juice it's 3.8$, how many do you want?\n";
  299. std::cin>>howmany;
  300. std::cout<<"You have to pay " << howmany*3.8<<" $\n";
  301. }
  302. break;
  303. }
  304. }
  305. while(ask("Do you want to continue?(Y OR N)"));
  306. }
  307. void application1()
  308. {
  309. int score;
  310. do
  311. {
  312. std::cout<<"Enter you're score of the programming class(0-100)\n)";
  313. std::cin>>score;
  314.  
  315. if(score==100)
  316. {
  317. cls();
  318. std::cout<<"Congratulations! You scored a perfect note.\n";
  319. }
  320. if (score>90 && score<99)
  321. {
  322. cls();
  323. std::cout<<"Congratulations! You're note is an A.\n";
  324. }
  325. if (score>80 && score<89)
  326. {
  327. cls();
  328. std::cout<<"Congratulations! You're note is an B.\n";
  329. }
  330. if (score>70 && score<79)
  331. {
  332. cls();
  333. std::cout<<"Congratulations! You're note is an C.\n";
  334. }
  335. if (score>60 && score<69)
  336. {
  337. cls();
  338. std::cout<<"Congratulations! You're note is an D.\n";
  339. }
  340. if (score>0 && score<59)
  341. {
  342. cls();
  343. std::cout<<"Congratulations! You're note is an F.\n";
  344. }
  345.  
  346. else
  347. {
  348. cls();
  349. }
  350. }
  351. while(ask("Do you want to continue?(Y OR N)"));
  352.  
  353. }
  354.  
  355. int main()
  356.  
  357. {
  358. int dec;
  359.  
  360. {
  361. std::cout<<" <>-1-<>\n\n";
  362. std::cout<<" <<---Grading Program--->>\n\n";
  363. std::cout<<" <>-2-<>\n\n";
  364. std::cout<<" <<---Cola Machine--->>\n\n";
  365. std::cout<<" <>-3-<>\n\n";
  366. std::cout<<" <<---While user == gullible--->>\n\n";
  367. std::cout<<" <>-4-<>\n\n";
  368. std::cout<<" <<---Pancakes--->>\n\n";
  369. std::cout<<" <>-5-<>\n\n";
  370. std::cout<<" <<---Bracketing Search--->>\n\n";
  371.  
  372. std::cin>>dec;
  373.  
  374. switch(dec)
  375. {
  376.  
  377. case 1:
  378. {
  379. cls();
  380. application1();
  381. break;
  382. }
  383. case 2:
  384. {
  385. cls();
  386. application2();
  387. break;
  388. }
  389. case 3:
  390. {
  391. cls();
  392. application3();
  393. break;
  394. }
  395. case 4:
  396. {
  397. cls();
  398. application4();
  399. break;
  400. }
  401. case 5:
  402. {
  403. cls();
  404. application5();
  405. break;
  406. }
  407. default:
  408. {
  409. cls();
  410. }
  411. }
  412. }
  413. }
Advertisement
Add Comment
Please, Sign In to add comment