Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int SIZE = 6;
- const int ROWS = 2;
- const int COLS = 3;
- const int SIZE2 = 5;
- const int SIZE3 = 10;
- const int COLS1 = 5;
- const int ROWS1 = 7;
- const int SIZE4 = 4;
- const int FIRST_CHOICE = 1;
- const int EXIT = 10;
- void main()
- {
- int option;
- bool fExit = false;
- char answer;
- do
- {
- cout << "Hello, Please select an option from the menu:" << endl;
- cout << "--------------------------------------" << endl << endl;
- cout << "1) for question 1" << endl;
- cout << "2) for question 2" << endl;
- cout << "3) for question 3" << endl;
- cout << "4) for question 4" << endl;
- cout << "5) for question 5" << endl;
- cout << "6) for question 6" << endl;
- cout << "7) for question 7" << endl;
- cout << "8) for question 8" << endl;
- cout << "9) for question 9" << endl;
- cout << "10) for Exit" << endl;
- cout << "\nType your choice: ";
- cin >> option;
- if (option == EXIT)
- break;
- while (option < FIRST_CHOICE || option > EXIT)
- {
- cout << endl << "Invalid choice please try again: ";
- cin >> option;
- }
- switch (option)
- {
- case 1:
- {
- int arr[SIZE] = {};
- bool flag = true;
- cout << "Enter The numbers one by one to check if they mirror :" << endl;
- for (int i = 0; i < SIZE; i++)
- cin >> arr[i];
- for (int i = 0; i < SIZE / 2 && flag; i++)
- {
- int temp = arr[i];
- int temp2 = 0;
- while (temp != 0)
- {
- temp2 = (temp2 * 10) + temp % 10;
- temp /= 10;
- }
- if (temp2 != arr[SIZE - 1 - i])
- flag = false;
- }
- cout << (flag ? "Mirrors" : "Not Mirrors") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 1
- Enter The numbers one by one to check if they mirror :
- 123 121 45 54 121 321
- Mirrors
- Press any key to continue . . .
- */
- switch (option)
- {
- case 2:
- {
- int arr[SIZE] = { 14, 61, 227 };
- int arr2[SIZE] = { 23, 43, 92 };
- bool flag = true;
- for (int i = 0; i < SIZE && flag; i++)
- {
- int number1 = arr[i];
- int number2 = arr2[i];
- int sum1 = 0, sum2 = 0;
- while (number1 != 0)
- {
- sum1 += number1 % 10;
- number1 /= 10;
- }
- while (number2 != 0)
- {
- sum2 += number2 % 10;
- number2 /= 10;
- }
- if (sum2 != sum1)
- flag = false;
- }
- cout << (flag ? "The arrays with the same summary " : "The arrays without same summary") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 2
- the arrays with the same summary
- Press any key to continue . . .
- */
- switch (option)
- {
- case 3:
- {
- int i = 0, j = 0, counter = 0, prev = 0, maxChar = 0;
- char yourCharacter;
- char arr[SIZE2][SIZE2]{
- { 'a', 'b', 'c', 'd', 'e' },
- { 'a', 'b', 'c', 'd', 'e' },
- { 'b', 'b', 'c', 'd', 'e' },
- { 'b', 'b', 'c', 'd', 'e' },
- { 'b', 'c', 'd', 'e', 'f' } };
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE2; j++)
- cout << arr[i][j];
- cout << endl;
- }
- cout << "Please enter one character (a-z) ---> ";
- cin >> yourCharacter;
- for (i = 0; i < SIZE2; i++)
- {
- counter = 0;
- for (j = 0; j < SIZE2; j++)
- {
- if (arr[j][i] == yourCharacter)
- {
- counter++;
- }
- }
- if (counter > prev)
- {
- prev = counter;
- maxChar = i;
- }
- }
- if (prev > 0)
- {
- cout << endl << "The char " << yourCharacter << " appears: " << prev << " times in the matrix, in col: " << maxChar + 1 << endl;
- }
- else
- {
- cout << endl << "The char " << yourCharacter << " does not appear in the matrix" << endl;
- }
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 3
- abcde
- abcde
- bbcde
- bbcde
- bcdef
- please enter one character that you want ---> b
- The char b appears: 4 times in the matrix, in col: 2
- */
- switch (option)
- {
- case 4:
- {
- int rows = 0, cols = 0, arr[SIZE3][SIZE3] = { 0 }, i = 0, j = 0;
- int max1 = 0, max2 = 0, max3 = 0, max4 = 0;
- cout << "Please enter the numbers of rows (between1-10) : ";
- cin >> rows;
- while (rows > 10 || rows < 1)
- {
- cout << "Value should be between 1-10, please try again : ";
- cin >> rows;
- }
- cout << "Please enter the numbers of cols (between1-10) : ";
- cin >> cols;
- while (cols > 10 || cols < 1)
- {
- cout << "Value should be between 1-10, please try again : ";
- cin >> cols;
- }
- cout << "enter " << rows*cols << " numbers please : ";
- for (i = 0; i < rows; i++)
- {
- for (j = 0; j < cols; j++)
- {
- cin >> arr[i][j];
- }
- }
- for (i = 0; i < rows; i++)
- {
- for (j = 0; j < cols; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << endl;
- }
- max1 = arr[0][0];
- for (i = 0, j = 1; j < cols; j++)
- {
- if (arr[i][j] > max1)
- max1 = arr[i][j];
- }
- max2 = arr[rows - 1][0];
- for (i = rows - 1, j = 0; j < cols; j++)
- {
- if (arr[i][j] > max1)
- max1 = arr[i][j];
- }
- max3 = arr[0][cols - 1];
- for (i = 0, j = cols - 1; i < rows; i++)
- {
- if (arr[i][j] > max1)
- max1 = arr[i][j];
- }
- max4 = arr[0][0];
- for (i = 0, j = 0; i < rows; i++)
- {
- if (arr[i][j] > max1)
- max1 = arr[i][j];
- }
- cout << "The higher number on the fram is " << max1 << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- enter 12 numbers please : 1 2 3 4 5 8 6 5 4 9 7 1
- 1 2 3 4
- 5 8 6 5
- 4 9 7 1
- the higher number on the fram is 9
- */
- switch (option)
- {
- case 5:
- {
- int cols = 0, rows = 0;
- int matrix[ROWS1][COLS1] = { 0 };
- int value = 1, i = 0, j = 0;
- bool flag = true;
- for (i = 0, j = COLS1 - 1; j >= 0; j--)
- {
- if (flag)
- {
- for (i = 0; i < ROWS1; i++)
- matrix[i][j] = value++;
- }
- else
- {
- for (i = ROWS1 - 1; i >= 0; i--)
- matrix[i][j] = value++;
- }
- flag = !flag;
- }
- for (i = 0; i < ROWS1; i++)
- {
- for (j = 0; j < COLS1; j++)
- cout << matrix[i][j] << "\t";
- cout << "\n";
- }
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 5
- 29 28 15 14 1
- 30 27 16 13 2
- 31 26 17 12 3
- 32 25 18 11 4
- 33 24 19 10 5
- 34 23 20 9 6
- 35 22 21 8 7
- Press any key to continue . . .
- */
- switch (option)
- {
- case 6:
- {
- int matrix[SIZE2][SIZE2] ={
- { 1, 1, 0, 1, 1 },
- { 1, 0, 1, 0, 1 },
- { 0, 1, 1, 1, 0 },
- { 1, 0, 1, 0, 1 },
- { 1, 1, 0, 1, 1 } };
- int mask[SIZE2][SIZE2] = { 0 };
- bool flag = true;
- int j = 0, i = 0;
- for (i = ((SIZE2 - 1) / 2); i >= 0; i--)
- {
- mask[i][j++] = 1;
- }
- for (i = 0, j = (SIZE2 % 2 == 0 ? SIZE2 / 2 : (SIZE2 - 1) / 2); i <= (SIZE2 / 2) - 1; i++)
- {
- mask[i][j++] = 1;
- }
- for (j = SIZE2 - 1, i = (SIZE2 % 2 == 0 ? SIZE2 / 2 : (SIZE2 - 1) / 2); i < SIZE2; i++, j--)
- {
- mask[i][j] = 1;
- }
- for (j = (SIZE2 % 2 == 0 ? (SIZE2 / 2 - 1) : SIZE2 / 2), i = SIZE2 - 1; i >= SIZE2 / 2; i--, j--)
- {
- mask[i][j] = 1;
- }
- cout << "original diamond: \n";
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE2; j++)
- cout << (mask[i][j] ? "0 " : " ");
- cout << endl;
- }
- cout << "your matrix : \n";
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE2; j++)
- cout << (matrix[i][j] ? " " : "0 ");
- cout << endl;
- }
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE2; j++)
- if (mask[i][j] == 1 && matrix[i][j] != 0)
- flag = false;
- }
- cout << (flag ? "\nCompatible Diamond\n" : "INVALID Diamond") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- original diamond:
- 0
- 0 0
- 0 0
- 0 0
- 0
- your matrix :
- 0
- 0 0
- 0 0
- 0 0
- 0
- Compatible Diamond
- */
- switch (option)
- {
- case 7:
- {
- int i = 0, j = 0, arr[SIZE4][SIZE4]
- {
- { 9, 2, 3, 4 },
- { 2, 9, 6, 3 },
- { 3, 6, 9, 2 },
- { 4, 3, 2, 9 }
- };
- bool flag = true;
- for (i = 0; i < SIZE4; i++)
- {
- for (j = 0; j < SIZE4; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << "\n";
- }
- for (i = 0; i < SIZE4; i++)
- {
- for (j = 0; j < SIZE4; j++)
- {
- if (arr[i][j] != arr[j][i])
- flag = false;
- }
- }
- cout << (flag ? "Mekupelet" : "INVALID Mekupelet") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 7
- 9 2 3 4
- 2 9 6 3
- 3 6 9 2
- 4 3 2 9
- Mekupelet
- */
- switch (option)
- {
- case 8:
- {
- int i = 0, j = 0, counter1 = 0, arr[SIZE4][SIZE4] =
- {
- { 4, 2, 3, 9 },
- { 1, 6, 9, 3 },
- { 5, 9, 6, 2 },
- { 9, 5, 1, 4 }
- };
- bool flag = true;
- for (i = 0; i < SIZE4; i++)
- {
- for (j = 0; j < SIZE4; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << "\n";
- }
- for (i = 0, j = SIZE4 - 1; i < SIZE4; i++, j = (SIZE4 - 1) - counter1)
- {
- counter1++;
- for (int counter = 0; counter <= j; counter++)
- {
- if (arr[i][j - counter] != arr[i + counter][j])
- flag = false;
- }
- }
- cout << (flag ? "Mekupelet" : "INVALID") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 8
- 1 2 3 9
- 4 5 9 3
- 3 9 5 2
- 9 3 4 1
- Mekupelet
- Press any key to continue . . .
- */
- switch (option)
- {
- case 9:
- {
- int i = 0, j = 0;
- bool flag = true;
- char arr[SIZE2][SIZE]{
- { 'F', 'C', 'B', 'J', '|', '|' },
- { '1', '9', '3', '6', '|', '-' },
- { 'B', '|', '-', '-', '-', '-' },
- { 'J', '|', 'F', 'C', 'B', 'J' },
- { '|', '-', '1', '9', '3', '6' }
- };
- for (i = 0; i < SIZE2; i++)
- {
- for (j = 0; j < SIZE; j++)
- {
- cout << arr[i][j] << " ";
- }
- cout << "\n";
- }
- for (j = SIZE - 1, i = 0; i<SIZE2 ; i++)
- {
- if (arr[0][SIZE - 1] != '|' && arr[0][SIZE - 1] != '-')
- flag = false;
- while (arr[i][j] == '-')
- j--;
- if (arr[i][j] != '|')
- flag = false;
- }
- if (arr[SIZE2 - 1][j] != '|' )
- {
- flag = false;
- }
- cout << (flag ? "\nVALID\n" : "\nINVALID\n") << endl;
- break;
- system("pause");
- system("cls");
- }
- }
- /*
- Type your choice: 9
- F C B J | |
- 1 9 3 6 | -
- B | - - - -
- J | F C B J
- | - 1 9 3 6
- VALID
- Press any key to continue . . .
- */
- system("pause");
- system("cls");
- cout << "Would you like to continue? ";
- cin >> answer;
- if (answer == 'N' || answer == 'n')
- fExit = true;
- system("cls");
- } while (!fExit);
- cout << "Goodbye!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment