Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.;h"
- #include "iostream"
- using namespace std;
- const int M = 5;
- class TMyClass
- {
- private:
- int a;
- unsigned int *b;
- float arr[M];
- char *mass;
- int n;
- public:
- TMyClass(int nn = 5, char massmass = 'a', int aa = 2, unsigned int bb = 10, char arrarr = 'b');
- TMyClass(TMyClass &obj);
- ~TMyClass();
- void input();
- void output();
- double fff();
- friend void input_F(TMyClass&);
- };
- class TChild :public TMyClass
- {
- char* d;
- double f;
- int j;
- public:
- TChild(int nn = 5, char massmass = 'a', int aa = 2, unsigned int bb = 10, char arrarr = 'b', char dd = 's', double ff=50, int jj=60);
- ~TChild();
- void input();
- void output();
- };
- TMyClass::TMyClass(int nn, char massmass, int aa, unsigned int bb, char arrarr)
- {
- n = nn;
- mass = new char[n];
- for (int i = 0; i < n; i++)
- mass[i] = massmass;
- a = aa;
- b = new unsigned int;
- *b = bb;
- for (int i = 0; i < M; i++)
- {
- arr[i] = arrarr;
- }
- }
- TMyClass::TMyClass(TMyClass &obj)
- {
- n = obj.n;
- mass = new char[n];
- for (int i = 0; i < n; i++)
- mass[i] = obj.mass[i];
- a = obj.a;
- b = new unsigned int;
- *b = *obj.b;
- for (int i = 0; i < M; i++)
- {
- arr[i] = obj.arr[i];
- }
- }
- TMyClass::~TMyClass()
- {
- delete[]mass;
- delete b;
- }
- TChild::TChild(int nn, char massmass, int aa, unsigned int bb, char arrarr, char dd, double ff, int jj):TMyClass(dd,ff,jj)
- {
- d = new char;
- *d = dd;
- f = ff;
- j = jj;
- }
- TChild::~TChild()
- {
- delete d;
- }
- void TMyClass::input()
- {
- cout << "Введите переменную типа int" << endl;
- cin >> a;
- cout << "Введите статический массив" << endl;
- for (int i = 0; i < M; i++)
- {
- cout << "arr[" << i + 1 << "]=";
- cin >> arr[i];
- }
- cout << "Введите количество элементов дин.массива" << endl;
- cout << "n=";
- cin >> n;
- delete[]mass;
- mass = new char[n];
- cout << "Введите эелементы массива" << endl;
- for (int i = 0; i < n; i++)
- {
- cin >> mass[i];
- }
- cout << endl;
- cout << "Введите указатель *b" << endl;
- cin >> *b;
- }
- void input_F(TMyClass&obj)
- {
- cout << "Введите переменную типа int" << endl;
- cin >> obj.a;
- cout << "Введите статический массив" << endl;
- for (int i = 0; i < M; i++)
- {
- cin >> obj.arr[i];
- }
- cout << "Введите количество элементов дин.массива" << endl;
- cout << "n=";
- cin >> obj.n;
- delete[]obj.mass;
- obj.mass = new char[obj.n];
- cout << "Введите эелементы массива" << endl;
- for (int i = 0; i <obj.n; i++)
- {
- cout << "mass[" << i + 1 << "]=";
- cin >> obj.mass[i];
- }
- cout << endl;
- cout << "Введите указатель *b" << endl;
- cin >> *obj.b;
- }
- double TMyClass::fff()
- {
- double srA;
- int k = 0;
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- if (mass[i] <= 70)
- {
- k++;
- sum += mass[i];
- cout << "SUM=" << sum << endl;
- }
- }
- if (k>0)cout << "Ср.а не превышиющих 70:«" << sum / k << endl;
- else cout << "Числе не превышиющих 70 нет" << endl;
- return 0;
- }
- void TMyClass::output()
- {
- cout << endl;
- cout << "Вывод значений:" << endl;
- cout << "Переменная типа int:" << endl;
- cout << a << endl;
- cout << "Указатель *b:" << endl;
- cout << *b << endl;
- cout << "Статический массив:" << endl;
- for (int i = 0; i < M; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl;
- cout << "Дин.массив mass[" << n << "]" << endl;
- for (int i = 0; i < n; i++)
- {
- cout << mass[i] << " ";
- }
- cout << endl;
- }
- int main()
- {
- setlocale(LC_ALL, "RUS");
- TMyClass a;
- cout << " a - оригинальный " << endl;
- a.input();
- a.output();
- TMyClass b(a);
- TMyClass *c;
- c = new TMyClass;
- cout << "b(a) - копия а" << endl;
- b.output();
- cout << " c " << endl;
- c->output();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement