Guest User

Untitled

a guest
Dec 14th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. using namespace std;
  4.  
  5. int **create2DArray(int arrSize) {
  6.  
  7. srand(time(NULL));
  8.  
  9. int **userArr = new int*[arrSize];
  10. for (int i = 0; i < arrSize; i++) {
  11. userArr[i] = new int[arrSize];
  12. }
  13.  
  14. return userArr;
  15. }
  16.  
  17. int funcArr(int **someArr, int size) {
  18.  
  19. for (int i = 0; i < size; i++) {
  20. for (int j = 0; j < size; j++) {
  21. someArr[i][j] = rand() % 50;
  22. cout << someArr[i][j] << " ";
  23. }
  24. cout << endl;
  25. }
  26.  
  27. int *minElemArr = new int[size];
  28.  
  29. for (int i = 0; i < size; i++) {
  30. int min = someArr[i][0];
  31. for (int j = 0; j < size; j++) {
  32. if (someArr[i][j] <= min) {
  33. min = someArr[i][j];
  34. minElemArr[i] = min;
  35. }
  36. }
  37. }
  38.  
  39. cout << endl << "Array of min elements of matrix is: " << endl;
  40. for (int i = 0; i < size; i++) {
  41. cout << minElemArr[i] << " ";
  42. }
  43.  
  44. int max = 0;
  45. for (int i = 0; i < size; i++) {
  46. if (max < minElemArr[i]) {
  47. max = minElemArr[i];
  48. }
  49. }
  50.  
  51. cout << endl << "Max element of new array is: " << max << endl << endl;
  52. delete[] minElemArr;
  53. return max;
  54. }
  55.  
  56. char **createString(int strSize) {
  57. char **stringArr = new char*[strSize];
  58. for (int i = 0; i < strSize; i++) {
  59. stringArr[i] = new char[strSize];
  60. }
  61. return stringArr;
  62. }
  63.  
  64. char strings(char **stringArr, int strSize, int quant) {
  65.  
  66. for (int i = 0; i < quant; i++) {
  67. cin >> stringArr[i];
  68. }
  69. cout << endl;
  70.  
  71. char someChar;
  72. cout << "Some char to check: ";
  73. cin >> someChar;
  74.  
  75. int quantity = 0;
  76. for (int i = 0; i < quant; i++) {
  77. for (int j = 0; j < strSize; j++) {
  78. if (stringArr[i][j] == someChar) {
  79. quantity++;
  80. }
  81. }
  82. }
  83. cout << "Quantity is: " << quantity << endl << endl;
  84.  
  85. return quantity;
  86. }
  87.  
  88. int main() {
  89. bool func = true;
  90.  
  91. while (func) {
  92. cout << "What exercise do you want to check?(1/2)" << endl;
  93. int ex;
  94. cin >> ex;
  95. switch (ex) {
  96. case 1: {
  97. int arrSize;
  98. cout << "Enter size of array ";
  99. cin >> arrSize;
  100.  
  101. int **userArr = create2DArray(arrSize);
  102.  
  103. funcArr(userArr, arrSize);
  104.  
  105. for (int i = 0; i < arrSize; i++) {
  106. delete[] userArr[i];
  107. }
  108. delete[] userArr;
  109. break;
  110. }
  111. case 2: {
  112. int strSize, quant;
  113. cout << "Enter size of string ";
  114. cin >> strSize;
  115. cout << "Enter quant of string ";
  116. cin >> quant;
  117.  
  118. char **stringArr = createString(strSize);
  119.  
  120. strings(stringArr, strSize, quant);
  121.  
  122. for (int i = 0; i < strSize; i++) {
  123. delete[] stringArr[i];
  124. }
  125. delete[] stringArr;
  126. break;
  127. }
  128. default:
  129. cout << "Wrong input" << endl;
  130. break;
  131. }
  132. }
  133.  
  134. system("pause");
  135. return 0;
  136. }
Add Comment
Please, Sign In to add comment