axeefectushka

Untitled

Jan 22nd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class first
  5. {
  6. protected:
  7.     int *mas;
  8.     int size;
  9. public:
  10.     first()
  11.     {
  12.         cout << "Size: ";
  13.         cin >> size; cout << endl;
  14.         mas = new int[size];
  15.         cout << "Array: ";
  16.         for (int i = 0; i < size; i++)
  17.         {
  18.             cin >> mas[i];
  19.             cout << " ";
  20.         }
  21.     }
  22.     void sum()
  23.     {
  24.         int sum = 0;
  25.         for (int i = 0; i < size; i++)
  26.         {
  27.             sum += mas[i];
  28.         }
  29.         cout <<"S = " << sum << endl;
  30.     }
  31.     ~first()
  32.     {
  33.         delete[]mas;
  34.     }
  35. };
  36.  
  37. class second : public first
  38. {
  39. private:
  40.     first b;
  41.     int mult;
  42. public:
  43.     second() : b()
  44.     {
  45.         mult = 1;
  46.     }
  47.     void multiply()
  48.     {
  49.         for (int i = 0; i < size; i++)
  50.         {
  51.             mult *= mas[i];
  52.         }
  53.         cout << "M = " << mult << endl;
  54.     }
  55. };
  56.  
  57. int main()
  58. {
  59.     second a;
  60.     a.sum();
  61.     a.multiply();
  62.     return 0;
  63. }
Add Comment
Please, Sign In to add comment