axeefectushka

Untitled

Jan 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. Билет 1
  2. #include "stdafx.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class first
  7. {
  8. protected:
  9.     double a;
  10.     double b;
  11. public:
  12.     first(double aa, double bb) :a(aa), b(bb) {}
  13.     virtual double square(first&c)
  14.     {
  15.         return c.b*c.a;
  16.     }
  17.     ~first() { cout << "work1!" << endl; }
  18. };
  19. class second :public first
  20. {
  21. public:
  22.     second(double aa, double bb) :first(aa, bb) {}
  23.     double square(first&c) override
  24.     {
  25.         return 3.14*(c.a + c.b)*(c.a + c.b);
  26.     }
  27.     ~second() { cout << "work2!" << endl; };
  28. };
  29.  
  30.  
  31. int main()
  32. {
  33.     first object1(5, 6);
  34.     double s1, s2;
  35.     s1 = square(object1);
  36.     second object2(1, 1);
  37.     s2 = square(object2);
  38.     return 0;
  39. }
Add Comment
Please, Sign In to add comment