Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication13.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 q;
- public:
- TMyClass(int qq = 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 qq, float massmass, char cc, double dd, long int ararar)
- {
- q = qq;
- mass = new float[q];
- for (int i = 0; i < q; 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)
- {
- q = obj.q;
- mass = new float[q];
- for (int i = 0; i < q; 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 << "q=";
- cin >> q;
- delete[]mass;
- mass = new float[q];
- cout << "Введите элементы динамического массива(float)" << endl;
- for (int i = 0; i < q; 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 << "q=";
- cin >> obj.q;
- delete[]obj.mass;
- obj.mass = new float[obj.q];
- cout << "Введите элементы динамического массива(float)" << endl;
- for (int i = 0; i < obj.q; 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 << "Статический массив[" << Count << "]" << endl;
- for (int i = 0; i < Count; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- cout << "Дин.массив mass[" << q << "]" << endl;
- for (int i = 0; i < q; i++)
- {
- cout << mass[i] << " ";
- }
- cout << endl;
- }
- class TChild :public TMyClass
- {
- public:
- int y;
- float *t;
- char m;
- TChild(int nn = 3, float massmass = 3.1, char cc = 'w', double dd = 2.4, long int ararar = 100, int yy = 4, float tt = 5, char mm = 'i');
- TChild(TMyClass &obj, TChild &object);
- void output();
- };
- TChild::TChild(int qq, float massmass, char cc, double dd, long int ararar, int yy, float tt, char mm):TMyClass(qq,massmass,cc,dd,ararar)
- {
- y = yy;
- m = mm;
- t = new float;
- *t = tt;
- }
- TChild::TChild(TMyClass &obj, TChild &object):TMyClass(obj)
- {
- y = object.y;
- t = new float;
- *t = *object.t;
- m = object.m;
- }
- void TChild::output()
- {
- TMyClass::output();
- cout << "Переменная y типа int:" << endl;
- cout << y << endl;
- cout << "Указатель t типа float:" << endl;
- cout << *t << endl;
- cout << "Переменная m типа char:" << endl;
- cout << m << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout << "Объекты TMyClass" << endl;
- TMyClass a(7, 2.1, 'g', 2.24, 2000);
- cout << "Объект a - оригинал" << endl;
- a.output();
- TMyClass b(a);
- TMyClass *c;
- c = new TMyClass;
- cout << "Объект b(a) - копия объекта a" << endl;
- b.output();
- cout << "Объект c" << endl;
- c->output();
- cout << endl;
- cout << "Объекты TChild" << endl;
- TChild d(10, 5.2, 's', 2.37, 1000, 8, 1.4, 'q');
- cout << "Объект d - оригинал:" << endl;
- cout << "Cобственный метод вывода:" << endl;
- d.output();
- cout << "Унаследованный метод вывода:" << endl;
- d.TMyClass::output();
- TChild f(d);
- cout << "Объект f(d) - копия объекта d:" << endl;
- cout << "Cобственный метод вывода:" << endl;
- f.output();
- cout << "Унаследованный метод вывода:" << endl;
- f.TMyClass::output();
- TChild *g;
- g = new TChild;
- cout << "Объект c:" << endl;
- cout << "Cобственный метод вывода:" << endl;
- g->output();
- cout << "Унаследованный метод вывода:" << endl;
- g->TMyClass::output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement