axeefectushka

Untitled

Jan 23rd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 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.    
  10. public:
  11.     first()
  12.     {
  13.         cout << "Size: ";
  14.         cin >> size; cout << endl;
  15.         mas = new int[size];
  16.         cout << "Array: ";
  17.         for (int i = 0; i < size; i++)
  18.         {
  19.             cin >> mas[i];
  20.             cout << " ";
  21.         }
  22.     }
  23.     void sum()
  24.     {
  25.         int sum = 0;
  26.         for (int i = 0; i < size; i++)
  27.         {
  28.             sum += mas[i];
  29.         }
  30.         cout <<"S = " << sum << endl;
  31.     }
  32.     ~first()
  33.     {
  34.         delete[]mas;
  35.     }
  36. };
  37.  
  38. class second : public first
  39. {
  40. private:
  41.     first ah;
  42.     int a;
  43.     int b;
  44. public:
  45.     second(int aa, int bb):ah()
  46.     {
  47.         a = aa;
  48.         b = bb;
  49.     }
  50.    
  51.     void multiply()
  52.     {
  53.         int mult=1;
  54.         for (int i = 0; i < size; i++)
  55.         {
  56.             mult *= mas[i];
  57.         }
  58.         cout << "M = " << mult << endl;
  59.     }
  60.     void show()
  61.     {
  62.         cout << "a: " << a << " b: " << b << endl;
  63.     }
  64. };
  65.  
  66. int main()
  67. {
  68.     second a(5,5);
  69.     a.show();
  70.     a.sum();
  71.     a.multiply();
  72.     return 0;
  73. }
Add Comment
Please, Sign In to add comment