Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- int **create2DArray(int arrSize) {
- srand(time(NULL));
- int **userArr = new int*[arrSize];
- for (int i = 0; i < arrSize; i++) {
- userArr[i] = new int[arrSize];
- }
- return userArr;
- }
- int funcArr(int **someArr, int size) {
- for (int i = 0; i < size; i++) {
- for (int j = 0; j < size; j++) {
- someArr[i][j] = rand() % 50;
- cout << someArr[i][j] << " ";
- }
- cout << endl;
- }
- int *minElemArr = new int[size];
- for (int i = 0; i < size; i++) {
- int min = someArr[i][0];
- for (int j = 0; j < size; j++) {
- if (someArr[i][j] <= min) {
- min = someArr[i][j];
- minElemArr[i] = min;
- }
- }
- }
- cout << endl << "Array of min elements of matrix is: " << endl;
- for (int i = 0; i < size; i++) {
- cout << minElemArr[i] << " ";
- }
- int max = 0;
- for (int i = 0; i < size; i++) {
- if (max < minElemArr[i]) {
- max = minElemArr[i];
- }
- }
- cout << endl << "Max element of new array is: " << max << endl << endl;
- delete[] minElemArr;
- return max;
- }
- char **createString(int strSize) {
- char **stringArr = new char*[strSize];
- for (int i = 0; i < strSize; i++) {
- stringArr[i] = new char[strSize];
- }
- return stringArr;
- }
- char strings(char **stringArr, int strSize, int quant) {
- for (int i = 0; i < quant; i++) {
- cin >> stringArr[i];
- }
- cout << endl;
- char someChar;
- cout << "Some char to check: ";
- cin >> someChar;
- int quantity = 0;
- for (int i = 0; i < quant; i++) {
- for (int j = 0; j < strSize; j++) {
- if (stringArr[i][j] == someChar) {
- quantity++;
- }
- }
- }
- cout << "Quantity is: " << quantity << endl << endl;
- return quantity;
- }
- int main() {
- bool func = true;
- while (func) {
- cout << "What exercise do you want to check?(1/2)" << endl;
- int ex;
- cin >> ex;
- switch (ex) {
- case 1: {
- int arrSize;
- cout << "Enter size of array ";
- cin >> arrSize;
- int **userArr = create2DArray(arrSize);
- funcArr(userArr, arrSize);
- for (int i = 0; i < arrSize; i++) {
- delete[] userArr[i];
- }
- delete[] userArr;
- break;
- }
- case 2: {
- int strSize, quant;
- cout << "Enter size of string ";
- cin >> strSize;
- cout << "Enter quant of string ";
- cin >> quant;
- char **stringArr = createString(strSize);
- strings(stringArr, strSize, quant);
- for (int i = 0; i < strSize; i++) {
- delete[] stringArr[i];
- }
- delete[] stringArr;
- break;
- }
- default:
- cout << "Wrong input" << endl;
- break;
- }
- }
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment