Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
- //
- #include <iostream>
- #include <clocale>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- class mas
- {
- protected:
- int* a;
- int n;
- public:
- mas() // Конструктор по умолчанию
- {
- }
- mas(int count)
- {
- n = count;
- a = new int[n];
- }
- mas(const mas& t) // Конструктор копирования
- {
- n = t.n;
- a = new int[t.n];
- for (int i = 0; i < n; i++)
- {
- a[i] = t.a[i];
- }
- }
- ~mas() { delete[] a; }; // Деструктор массива
- void input_rand()
- {
- for (int i = 0; i < n; i++)
- {
- a[i] = rand() % 20 ;
- }
- }
- void input()
- {
- cout << "Введите массив" << endl;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- }
- }
- void output() // Метод вывода массива
- {
- for (int i = 0; i < n; i++)
- {
- cout << a[i] << " ";
- }
- cout << endl;
- }
- };
- class mass2 : public mas {
- protected:
- public:
- int m, n;//строки. столбцы
- mass2() // Конструктор по умолчанию
- {
- cout << "введите размер (строки. столбцы): ";
- cin >> m;
- cin >> n;
- a = new int[m * n];
- for (int i = 0; i < m * n; i++)
- {
- a[i] = rand() % 20 - 10;
- }
- }
- mass2(int f, int q) // Конструктор задания матрицы
- {
- m = f;
- n = q;
- a = new int[m * n];
- }
- ~mass2() // Деструктор
- {
- }
- void in()
- {
- int mas_counter = 0;
- cout << "Введите матрицу: " << endl;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cin >> a[mas_counter];
- mas_counter++;
- }
- }
- }
- void out() // Метод вывода
- {
- int mas_counter = 0;
- for (int i = 0; i < m; i++)
- {
- for (int j = 0; j < n; j++)
- {
- cout << a[mas_counter] << "\t";
- mas_counter++;
- }
- cout << endl;
- }
- }
- };
- int main()
- {
- setlocale(LC_ALL, "rus");
- srand(time(0));
- int key;
- int size;
- cout << "Введите номер задания(1-одномерный. 2-двумерный): "; cin >> key;
- if (key == 1) {
- key = 0;
- cout << "1-rand; 2-ввести с клавиатуры: ";
- cin >> key;
- if(key==1){
- cout << "Ввeдите размер массива: ";
- cin >> size;
- mas mass1(size);
- mass1.input_rand();
- mass1.output();
- }
- if (key == 2) {
- cout << "Ввeдите размер массива: ";
- cin >> size;
- mas mass1(size);
- mass1.input();
- mass1.output();
- }
- }
- if (key == 2) {
- key = 0;
- cout << "1-rand; 2-ввести с клавиатуры: ";
- cin >> key;
- if (key == 1) {
- mass2 mas1;
- mas1.out();
- }
- if (key == 2) {
- int f, q;
- cout << "введите кол-во строк: "; cin >> f;
- cout << "введите кол-во stolbcov: "; cin >> q;
- mass2 mas2(f, q);
- mas2.in();
- mas2.out();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement