Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <time.h>
- using namespace std;
- int max(int* array, int n)
- {
- int max = array[0];
- for (int i = 1; i < n; i++)
- {
- if (max < array[i])
- {
- max = array[i];
- }
- }
- return max;
- }
- int intInput(char ch, int index)
- {
- int a;
- cout << ch << '[' << index << "] = ";
- while (!(cin >> a) || (cin.peek() != '\n'))
- {
- cin.clear();
- while (cin.get() != '\n')
- {
- cout << "Неверный ввод!";
- }
- }
- return a;
- }
- int intRandom()
- {
- return int(-100 + rand() % (100 + 100));
- }
- int* getArray(int n, char ch, bool random)
- {
- int* arr = new int[n];
- for (int i = 0; i < n; i++)
- {
- if (random != true)
- arr[i] = intInput(ch, i);
- else
- arr[i] = intRandom();
- }
- return arr;
- }
- int* defineTArray(int* X, int* Y, int* Z, int n)
- {
- int* T = new int[10];
- int maxX = max(X, 10);
- int maxY = max(Y, 10);
- int maxZ = max(Z, 10);
- for (int i = 0; i < n; i++)
- {
- if (Z[i] > 0)
- {
- T[i] = (maxX + maxY) / 2;
- }
- else
- {
- T[i] = 1 + (maxZ * maxZ);
- }
- }
- return T;
- }
- void print(int* arr, int n, char ch)
- {
- cout << ch << " = ";
- for (int i = 0; i < n; i++)
- {
- cout << arr[i] << ' ';
- }
- }
- int main()
- {
- setlocale(LC_ALL, "rus");
- srand(time(0));
- bool random;
- cout << "Заполнение массивов случайными числами - 1, вручную - 0: ";
- while (!(cin >> random) || (cin.peek() != '\n')) {
- cin.clear();
- while (cin.get() != '\n');
- cout << "Заполнение массива случайными числами - 1, вручную - 0: ";
- }
- int* X = getArray(10, 'X', random);
- int* Y = getArray(10, 'Y', random);
- int* Z = getArray(10, 'Z', random);
- int* T = defineTArray(X, Y, Z, 10);
- print(T, 10, 'T');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement