Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- using namespace std;
- const int Count = 6;
- class TMyClass
- {
- private:
- int c;
- unsigned int *d;
- float arr[Count];
- char *mass;
- int q;
- public:
- TMyClass(int cc = 3, float arrarr = 3.1, char massmass = 'w', int qq = 5, unsigned int dd = 10);
- TMyClass(TMyClass &obj);
- ~TMyClass();
- void input();
- void output();
- long int fff(int x);
- friend void input_F(TMyClass&);
- };
- TMyClass::TMyClass(int cc, float arrarr, char massmass, int qq, unsigned int dd)
- {
- q = qq;
- mass = new char[q];
- for (int i = 0; i < q; i++)
- mass[i] = massmass;
- c = cc;
- d = new unsigned int;
- *d = dd;
- for (int i = 0; i < Count; i++)
- {
- arr[i] = arrarr;
- }
- }
- TMyClass::TMyClass(TMyClass &obj)
- {
- q = obj.q;
- mass = new char[q];
- for (int i = 0; i < q; i++)
- mass[i] = obj.mass[i];
- c = obj.c;
- d = new unsigned int;
- *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 << "Введите переменную(int)" << endl;
- cin >> c;
- cout << "Введите статический массив(float)" << 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 char[q];
- cout << "Введите элементы динамического массива(char)" << endl;
- for (int i = 0; i < q; i++)
- {
- cout << "mass[" << i + 1 << "]=";
- cin >> mass[i];
- }
- cout << endl;
- cout << "Введите указатель *b(unsigned int)" << endl;
- cin >> *d;
- }
- void input_F(TMyClass&obj)
- {
- cout << "Введите переменную(int)" << endl;
- cin >> obj.c;
- cout << "Введите статический массив(float)" << 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 char[obj.q];
- cout << "Введите элементы динамического массива(char)" << endl;
- for (int i = 0; i < obj.q; i++)
- {
- cout << "mass[" << i + 1 << "]=";
- cin >> obj.mass[i];
- }
- cout << endl;
- cout << "Введите указатель *b(unsigned int)" << 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 << "Переменная типа int:" << 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;
- char *t;
- double m;
- TChild(int cc = 3, float arrarr = 3.1, char massmass = 'w', int qq = 5, unsigned int dd = 10, int yy = 4, char tt = 's', double mm = 100.23);
- TChild(TMyClass &obj, TChild &object);
- void output();
- };
- TChild::TChild(int cc, float arrarr, char massmass, int qq, unsigned int dd, int yy, char tt, double mm) :TMyClass(cc, arrarr, massmass, qq, dd)
- {
- y = yy;
- m = mm;
- t = new char;
- *t = tt;
- }
- TChild::TChild(TMyClass &obj, TChild &object) :TMyClass(obj)
- {
- y = object.y;
- t = new char;
- *t = *object.t;
- m = object.m;
- }
- void TChild::output()
- {
- TMyClass::output();
- cout << "Переменная y типа int:" << endl;
- cout << y << endl;
- cout << "Указатель t типа char:" << endl;
- cout << *t << endl;
- cout << "Переменная m типа double:" << endl;
- cout << m << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "Russian");
- cout << "Объекты TMyClass" << endl;
- TMyClass a(3, 2.1, 'g', 4, 13);
- 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(3, 2.1, 'g', 4, 13, 15, 'j', 50.21);
- 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();
- delete g;
- cout << "Проверка наследования" << endl;
- TChild h;
- input_F(h);
- h.output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement