Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication14.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- const int Count = 6;
- class TMyClass
- {
- private:
- char c;
- double *d;
- long int arr[Count];
- float *mass;
- int n;
- public:
- TMyClass(int nn = 3, float massmass = 3.1, char cc = 'w', double dd = 2.4, long int ararar = 100);
- TMyClass(TMyClass &obj);
- ~TMyClass();
- void input();
- void output();
- long int fff(int x);
- friend void input_F(TMyClass&);
- };
- TMyClass::TMyClass(int nn, float massmass, char cc, double dd, long int ararar)
- {
- n = nn;
- mass = new float[n];
- for (int i = 0; i < n; i++)
- mass[i] = massmass;
- c = cc;
- d = new double;
- *d = dd;
- for (int i = 0; i < Count; i++)
- {
- arr[i] = ararar;
- }
- }
- TMyClass::TMyClass(TMyClass &obj)
- {
- n = obj.n;
- mass = new float[n];
- for (int i = 0; i < n; i++)
- mass[i] = obj.mass[i];
- c = obj.c;
- d = new double;
- *d = *obj.d;
- for (int i = 0; i < Count; i++)
- {
- arr[i] = obj.arr[i];
- }
- }
- TMyClass::~TMyClass()
- {
- delete[]mass;
- delete d;
- }
- void TMyClass::input()
- {
- cout << "Введите переменную(char)" << endl;
- cin >> c;
- cout << "Введите статический массив(long int)" << endl;
- for (int i = 0; i < Count; i++)
- {
- cout << "arr[" << i + 1 << "]=";
- cin >> arr[i];
- }
- cout << "Введите количество элементов дин.массива" << endl;
- cout << "n=";
- cin >> n;
- delete[]mass;
- mass = new float[n];
- cout << "Введите элементы динамического массива(float)" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << "mass[" << i + 1 << "]=";
- cin >> mass[i];
- }
- cout << endl;
- cout << "Введите указатель *b(double)" << endl;
- cin >> *d;
- }
- void input_F(TMyClass&obj)
- {
- cout << "Введите переменную(char)" << endl;
- cin >> obj.c;
- cout << "Введите статический массив(long int)" << endl;
- for (int i = 0; i < Count; i++)
- {
- cout << "arr[" << i + 1 << "]=";
- cin >> obj.arr[i];
- }
- cout << "Введите количество элементов дин.массива" << endl;
- cout << "n=";
- cin >> obj.n;
- delete[]obj.mass;
- obj.mass = new float[obj.n];
- cout << "Введите элементы динамического массива(float)" << endl;
- for (int i = 0; i < obj.n; i++)
- {
- cout << "mass[" << i + 1 << "]=";
- cin >> obj.mass[i];
- }
- cout << "Введите указатель *b(double)" << endl;
- cin >> *obj.d;
- }
- long int TMyClass::fff(int x) //умножение элементов стат. массива на переданное число x
- {
- for (int i = 0; i < Count; i++)
- {
- arr[i] *= x;
- }
- for (int i = 0; i < Count; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- return 0;
- }
- void TMyClass::output()
- {
- cout << endl;
- cout << "Вывод значений:" << endl;
- cout << "Переменная типа char:" << endl;
- cout << c << endl;
- cout << "Указатель *b:" << endl;
- cout << *d << endl;
- cout << "Статический массив:" << endl;
- for (int i = 0; i < Count; i++)
- {
- cout << "arr[" << i + 1 << "]=" << arr[i] << endl;
- }
- cout << "Дин.массив mass[" << n << "]" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << mass[i] << " ";
- }
- cout << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- TMyClass a;
- cout << "Объект a - оригинал" << endl;
- a.input();
- a.output();
- TMyClass b(a);
- TMyClass *px, *py;
- px = new TMyClass;
- py = new TMyClass;
- cout << "Объект b(a) - копия объекта a" << endl;
- b.output();
- cout << "Объект py - ввод с помощью конструктора по умолчанию" << endl;
- py->output();
- cout << "Объект px - ввод через внешнюю функцию ввода" << endl;
- input_F(*px);
- px->output();
- int x;
- cout << "Введите параметр x=";
- cin >> x;
- cout << "Метод fff для a" << endl;
- a.fff(x);
- cout << "Метод fff для b(a)" << endl;
- b.fff(x);
- cout << "Метод fff для px" << endl;
- px->fff(x);
- cout << "Метод fff для py" << endl;
- py->fff(x);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement