daily pastebin goal
16%
SHARE
TWEET

Untitled

axeefectushka Jan 20th, 2019 (edited) 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class first
  6. {
  7. protected:
  8.     static int size;
  9.     int *array;
  10. public:
  11.     first()
  12.     {
  13.         cout << "Input size: ";
  14.         cin >> size;
  15.         array = new int[size];
  16.         cout << endl;
  17.         cout << "Input array: " << endl;
  18.         for (int i = 0; i < size; i++)
  19.         {
  20.             cin >> array[i];
  21.             cout << " ";
  22.         }
  23.         cout << endl;
  24.         cout << "Constructor!" << endl;
  25.     }
  26.     void sum()
  27.     {
  28.         size;
  29.         int sum = 0;
  30.         for (int i = 0; i < size; i++)
  31.         {
  32.             sum += array[i];
  33.         }
  34.         cout << "Sum = " << sum << endl;
  35.     }
  36.     ~first()
  37.     {
  38.         delete[]array;
  39.         cout << "Destructor!" << endl;
  40.     }
  41. };
  42. int first::size;
  43.  
  44. class second :public first
  45. {
  46. public:
  47.     void average()
  48.     {
  49.         {
  50.             double average, sum = 0;
  51.             for (int i = 0; i < size; i++)
  52.             {
  53.                 sum += array[i];
  54.             }
  55.             average = sum / size;
  56.         }
  57.         cout << "Average = " << average << endl;
  58.     }
  59. };
  60.  
  61. int main()
  62. {
  63.     second obj;
  64.     obj.sum();
  65.     obj.average();
  66.     return 0;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top