axeefectushka

Untitled

Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. Билет 28
  2. #include "stdafx.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class A {
  7. protected:
  8.     int *mas;
  9.     int size;
  10. public:
  11.     A()
  12.     {
  13.         cout << "Input size: ";
  14.         cin >> size;
  15.         cout << endl;
  16.         mas = new int[size];
  17.         cout << "Input array: ";
  18.         for (int i = 0; i < size; i++)
  19.         {
  20.             cin >> mas[i];
  21.             cout << " ";
  22.         }
  23.         cout << endl;
  24.     }
  25.     ~A()
  26.     {
  27.         delete[]mas;
  28.     }
  29. };
  30.  
  31. class B : public A {
  32. public:
  33.    
  34.     B() : A()
  35.     {
  36.         int sum = 0;
  37.         for (int i = 0; i < size; i++)
  38.         {
  39.             sum += mas[i];
  40.         }
  41.         cout << "Sum = " << sum << endl;
  42.     }
  43. };
  44.  
  45. int main()
  46. {
  47.     B a;
  48.     system("pause");
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment