djelad1

Untitled

Dec 2nd, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. const int SIZE = 6;
  4. const int ROWS = 2;
  5. const int COLS = 3;
  6. const int SIZE2 = 5;
  7. const int SIZE3 = 10;
  8. const int COLS1 = 5;
  9. const int ROWS1 = 7;
  10. const int SIZE4 = 4;
  11. const int FIRST_CHOICE = 1;
  12. const int EXIT = 10;
  13. void main()
  14. {
  15. int option;
  16. bool fExit = false;
  17. char answer;
  18. do
  19. {
  20. cout << "Hello, Please select an option from the menu:" << endl;
  21. cout << "--------------------------------------" << endl << endl;
  22.  
  23. cout << "1) for question 1" << endl;
  24. cout << "2) for question 2" << endl;
  25. cout << "3) for question 3" << endl;
  26. cout << "4) for question 4" << endl;
  27. cout << "5) for question 5" << endl;
  28. cout << "6) for question 6" << endl;
  29. cout << "7) for question 7" << endl;
  30. cout << "8) for question 8" << endl;
  31. cout << "9) for question 9" << endl;
  32. cout << "10) for Exit" << endl;
  33. cout << "\nType your choice: ";
  34.  
  35. cin >> option;
  36. if (option == EXIT)
  37. break;
  38.  
  39. while (option < FIRST_CHOICE || option > EXIT)
  40. {
  41. cout << endl << "Invalid choice please try again: ";
  42. cin >> option;
  43. }
  44. switch (option)
  45. {
  46. case 1:
  47. {
  48. int arr[SIZE] = {};
  49. bool flag = true;
  50. cout << "Enter The numbers one by one to check if they mirror :" << endl;
  51. for (int i = 0; i < SIZE; i++)
  52. cin >> arr[i];
  53. for (int i = 0; i < SIZE / 2 && flag; i++)
  54. {
  55. int temp = arr[i];
  56. int temp2 = 0;
  57. while (temp != 0)
  58. {
  59. temp2 = (temp2 * 10) + temp % 10;
  60. temp /= 10;
  61. }
  62.  
  63. if (temp2 != arr[SIZE - 1 - i])
  64. flag = false;
  65. }
  66.  
  67. cout << (flag ? "Mirrors" : "Not Mirrors") << endl;
  68. break;
  69. system("pause");
  70. system("cls");
  71. }
  72. }
  73. /*
  74. Type your choice: 1
  75. Enter The numbers one by one to check if they mirror :
  76. 123 121 45 54 121 321
  77. Mirrors
  78. Press any key to continue . . .
  79. */
  80. switch (option)
  81. {
  82. case 2:
  83. {
  84.  
  85. int arr[SIZE] = { 14, 61, 227 };
  86. int arr2[SIZE] = { 23, 43, 92 };
  87. bool flag = true;
  88.  
  89. for (int i = 0; i < SIZE && flag; i++)
  90. {
  91. int number1 = arr[i];
  92. int number2 = arr2[i];
  93. int sum1 = 0, sum2 = 0;
  94. while (number1 != 0)
  95. {
  96. sum1 += number1 % 10;
  97. number1 /= 10;
  98. }
  99. while (number2 != 0)
  100. {
  101. sum2 += number2 % 10;
  102. number2 /= 10;
  103. }
  104. if (sum2 != sum1)
  105. flag = false;
  106. }
  107. cout << (flag ? "The arrays with the same summary " : "The arrays without same summary") << endl;
  108. break;
  109. system("pause");
  110. system("cls");
  111. }
  112. }
  113. /*
  114. Type your choice: 2
  115. the arrays with the same summary
  116. Press any key to continue . . .
  117. */
  118. switch (option)
  119. {
  120. case 3:
  121. {
  122. int i = 0, j = 0, counter = 0, prev = 0, maxChar = 0;
  123. char yourCharacter;
  124. char arr[SIZE2][SIZE2]{
  125. { 'a', 'b', 'c', 'd', 'e' },
  126. { 'a', 'b', 'c', 'd', 'e' },
  127. { 'b', 'b', 'c', 'd', 'e' },
  128. { 'b', 'b', 'c', 'd', 'e' },
  129. { 'b', 'c', 'd', 'e', 'f' } };
  130.  
  131. for (i = 0; i < SIZE2; i++)
  132. {
  133. for (j = 0; j < SIZE2; j++)
  134. cout << arr[i][j];
  135. cout << endl;
  136. }
  137. cout << "Please enter one character (a-z) ---> ";
  138. cin >> yourCharacter;
  139. for (i = 0; i < SIZE2; i++)
  140. {
  141. counter = 0;
  142. for (j = 0; j < SIZE2; j++)
  143. {
  144. if (arr[j][i] == yourCharacter)
  145. {
  146. counter++;
  147. }
  148. }
  149. if (counter > prev)
  150. {
  151. prev = counter;
  152. maxChar = i;
  153. }
  154. }
  155. if (prev > 0)
  156. {
  157. cout << endl << "The char " << yourCharacter << " appears: " << prev << " times in the matrix, in col: " << maxChar + 1 << endl;
  158. }
  159. else
  160. {
  161. cout << endl << "The char " << yourCharacter << " does not appear in the matrix" << endl;
  162. }
  163. break;
  164. system("pause");
  165. system("cls");
  166. }
  167. }
  168. /*
  169. Type your choice: 3
  170. abcde
  171. abcde
  172. bbcde
  173. bbcde
  174. bcdef
  175. please enter one character that you want ---> b
  176.  
  177. The char b appears: 4 times in the matrix, in col: 2
  178. */
  179. switch (option)
  180. {
  181. case 4:
  182. {
  183. int rows = 0, cols = 0, arr[SIZE3][SIZE3] = { 0 }, i = 0, j = 0;
  184. int max1 = 0, max2 = 0, max3 = 0, max4 = 0;
  185. cout << "Please enter the numbers of rows (between1-10) : ";
  186. cin >> rows;
  187. while (rows > 10 || rows < 1)
  188. {
  189. cout << "Value should be between 1-10, please try again : ";
  190. cin >> rows;
  191. }
  192. cout << "Please enter the numbers of cols (between1-10) : ";
  193. cin >> cols;
  194. while (cols > 10 || cols < 1)
  195. {
  196. cout << "Value should be between 1-10, please try again : ";
  197. cin >> cols;
  198. }
  199. cout << "enter " << rows*cols << " numbers please : ";
  200. for (i = 0; i < rows; i++)
  201. {
  202. for (j = 0; j < cols; j++)
  203. {
  204. cin >> arr[i][j];
  205. }
  206. }
  207. for (i = 0; i < rows; i++)
  208. {
  209. for (j = 0; j < cols; j++)
  210. {
  211. cout << arr[i][j] << " ";
  212. }
  213. cout << endl;
  214. }
  215. max1 = arr[0][0];
  216. for (i = 0, j = 1; j < cols; j++)
  217. {
  218. if (arr[i][j] > max1)
  219. max1 = arr[i][j];
  220. }
  221. max2 = arr[rows - 1][0];
  222. for (i = rows - 1, j = 0; j < cols; j++)
  223. {
  224. if (arr[i][j] > max1)
  225. max1 = arr[i][j];
  226. }
  227. max3 = arr[0][cols - 1];
  228. for (i = 0, j = cols - 1; i < rows; i++)
  229. {
  230. if (arr[i][j] > max1)
  231. max1 = arr[i][j];
  232. }
  233. max4 = arr[0][0];
  234. for (i = 0, j = 0; i < rows; i++)
  235. {
  236. if (arr[i][j] > max1)
  237. max1 = arr[i][j];
  238. }
  239. cout << "The higher number on the fram is " << max1 << endl;
  240. break;
  241. system("pause");
  242. system("cls");
  243. }
  244. }
  245. /*
  246. enter 12 numbers please : 1 2 3 4 5 8 6 5 4 9 7 1
  247. 1 2 3 4
  248. 5 8 6 5
  249. 4 9 7 1
  250. the higher number on the fram is 9
  251. */
  252. switch (option)
  253. {
  254. case 5:
  255. {
  256.  
  257. int cols = 0, rows = 0;
  258. int matrix[ROWS1][COLS1] = { 0 };
  259. int value = 1, i = 0, j = 0;
  260. bool flag = true;
  261. for (i = 0, j = COLS1 - 1; j >= 0; j--)
  262. {
  263. if (flag)
  264. {
  265. for (i = 0; i < ROWS1; i++)
  266. matrix[i][j] = value++;
  267. }
  268. else
  269. {
  270. for (i = ROWS1 - 1; i >= 0; i--)
  271. matrix[i][j] = value++;
  272. }
  273. flag = !flag;
  274. }
  275. for (i = 0; i < ROWS1; i++)
  276. {
  277.  
  278. for (j = 0; j < COLS1; j++)
  279. cout << matrix[i][j] << "\t";
  280. cout << "\n";
  281. }
  282. break;
  283. system("pause");
  284. system("cls");
  285.  
  286. }
  287. }
  288. /*
  289. Type your choice: 5
  290. 29 28 15 14 1
  291. 30 27 16 13 2
  292. 31 26 17 12 3
  293. 32 25 18 11 4
  294. 33 24 19 10 5
  295. 34 23 20 9 6
  296. 35 22 21 8 7
  297. Press any key to continue . . .
  298. */
  299. switch (option)
  300. {
  301. case 6:
  302. {
  303. int matrix[SIZE2][SIZE2] ={
  304. { 1, 1, 0, 1, 1 },
  305. { 1, 0, 1, 0, 1 },
  306. { 0, 1, 1, 1, 0 },
  307. { 1, 0, 1, 0, 1 },
  308. { 1, 1, 0, 1, 1 } };
  309.  
  310. int mask[SIZE2][SIZE2] = { 0 };
  311. bool flag = true;
  312. int j = 0, i = 0;
  313. for (i = ((SIZE2 - 1) / 2); i >= 0; i--)
  314. {
  315. mask[i][j++] = 1;
  316. }
  317.  
  318. for (i = 0, j = (SIZE2 % 2 == 0 ? SIZE2 / 2 : (SIZE2 - 1) / 2); i <= (SIZE2 / 2) - 1; i++)
  319. {
  320. mask[i][j++] = 1;
  321. }
  322.  
  323. for (j = SIZE2 - 1, i = (SIZE2 % 2 == 0 ? SIZE2 / 2 : (SIZE2 - 1) / 2); i < SIZE2; i++, j--)
  324. {
  325. mask[i][j] = 1;
  326. }
  327.  
  328. for (j = (SIZE2 % 2 == 0 ? (SIZE2 / 2 - 1) : SIZE2 / 2), i = SIZE2 - 1; i >= SIZE2 / 2; i--, j--)
  329. {
  330. mask[i][j] = 1;
  331. }
  332. cout << "original diamond: \n";
  333. for (i = 0; i < SIZE2; i++)
  334. {
  335. for (j = 0; j < SIZE2; j++)
  336. cout << (mask[i][j] ? "0 " : " ");
  337. cout << endl;
  338. }
  339. cout << "your matrix : \n";
  340. for (i = 0; i < SIZE2; i++)
  341. {
  342. for (j = 0; j < SIZE2; j++)
  343. cout << (matrix[i][j] ? " " : "0 ");
  344. cout << endl;
  345. }
  346. for (i = 0; i < SIZE2; i++)
  347. {
  348. for (j = 0; j < SIZE2; j++)
  349. if (mask[i][j] == 1 && matrix[i][j] != 0)
  350. flag = false;
  351. }
  352. cout << (flag ? "\nCompatible Diamond\n" : "INVALID Diamond") << endl;
  353. break;
  354. system("pause");
  355. system("cls");
  356.  
  357. }
  358. }
  359. /*
  360. original diamond:
  361. 0
  362. 0 0
  363. 0 0
  364. 0 0
  365. 0
  366. your matrix :
  367. 0
  368. 0 0
  369. 0 0
  370. 0 0
  371. 0
  372.  
  373. Compatible Diamond
  374. */
  375. switch (option)
  376. {
  377. case 7:
  378. {
  379. int i = 0, j = 0, arr[SIZE4][SIZE4]
  380. {
  381. { 9, 2, 3, 4 },
  382. { 2, 9, 6, 3 },
  383. { 3, 6, 9, 2 },
  384. { 4, 3, 2, 9 }
  385. };
  386. bool flag = true;
  387. for (i = 0; i < SIZE4; i++)
  388. {
  389. for (j = 0; j < SIZE4; j++)
  390. {
  391. cout << arr[i][j] << " ";
  392. }
  393. cout << "\n";
  394. }
  395. for (i = 0; i < SIZE4; i++)
  396. {
  397. for (j = 0; j < SIZE4; j++)
  398. {
  399. if (arr[i][j] != arr[j][i])
  400. flag = false;
  401. }
  402. }
  403. cout << (flag ? "Mekupelet" : "INVALID Mekupelet") << endl;
  404. break;
  405. system("pause");
  406. system("cls");
  407. }
  408. }
  409. /*
  410. Type your choice: 7
  411. 9 2 3 4
  412. 2 9 6 3
  413. 3 6 9 2
  414. 4 3 2 9
  415. Mekupelet
  416. */
  417. switch (option)
  418. {
  419. case 8:
  420. {
  421. int i = 0, j = 0, counter1 = 0, arr[SIZE4][SIZE4] =
  422. {
  423. { 4, 2, 3, 9 },
  424. { 1, 6, 9, 3 },
  425. { 5, 9, 6, 2 },
  426. { 9, 5, 1, 4 }
  427. };
  428. bool flag = true;
  429. for (i = 0; i < SIZE4; i++)
  430. {
  431. for (j = 0; j < SIZE4; j++)
  432. {
  433. cout << arr[i][j] << " ";
  434. }
  435. cout << "\n";
  436. }
  437. for (i = 0, j = SIZE4 - 1; i < SIZE4; i++, j = (SIZE4 - 1) - counter1)
  438. {
  439. counter1++;
  440. for (int counter = 0; counter <= j; counter++)
  441. {
  442. if (arr[i][j - counter] != arr[i + counter][j])
  443. flag = false;
  444. }
  445. }
  446. cout << (flag ? "Mekupelet" : "INVALID") << endl;
  447. break;
  448. system("pause");
  449. system("cls");
  450. }
  451. }
  452. /*
  453. Type your choice: 8
  454. 1 2 3 9
  455. 4 5 9 3
  456. 3 9 5 2
  457. 9 3 4 1
  458.  
  459. Mekupelet
  460.  
  461. Press any key to continue . . .
  462. */
  463. switch (option)
  464. {
  465. case 9:
  466. {
  467.  
  468. int i = 0, j = 0;
  469. bool flag = true;
  470. char arr[SIZE2][SIZE]{
  471. { 'F', 'C', 'B', 'J', '|', '|' },
  472. { '1', '9', '3', '6', '|', '-' },
  473. { 'B', '|', '-', '-', '-', '-' },
  474. { 'J', '|', 'F', 'C', 'B', 'J' },
  475. { '|', '-', '1', '9', '3', '6' }
  476. };
  477. for (i = 0; i < SIZE2; i++)
  478. {
  479. for (j = 0; j < SIZE; j++)
  480. {
  481. cout << arr[i][j] << " ";
  482. }
  483. cout << "\n";
  484. }
  485.  
  486. for (j = SIZE - 1, i = 0; i<SIZE2 ; i++)
  487. {
  488. if (arr[0][SIZE - 1] != '|' && arr[0][SIZE - 1] != '-')
  489. flag = false;
  490. while (arr[i][j] == '-')
  491. j--;
  492. if (arr[i][j] != '|')
  493. flag = false;
  494. }
  495. if (arr[SIZE2 - 1][j] != '|' )
  496. {
  497. flag = false;
  498. }
  499. cout << (flag ? "\nVALID\n" : "\nINVALID\n") << endl;
  500. break;
  501. system("pause");
  502. system("cls");
  503. }
  504. }
  505. /*
  506. Type your choice: 9
  507. F C B J | |
  508. 1 9 3 6 | -
  509. B | - - - -
  510. J | F C B J
  511. | - 1 9 3 6
  512.  
  513. VALID
  514.  
  515. Press any key to continue . . .
  516. */
  517. system("pause");
  518. system("cls");
  519. cout << "Would you like to continue? ";
  520. cin >> answer;
  521. if (answer == 'N' || answer == 'n')
  522. fExit = true;
  523. system("cls");
  524. } while (!fExit);
  525. cout << "Goodbye!\n";
  526. }
Advertisement
Add Comment
Please, Sign In to add comment