Xom9ik

Lab_9_Task1/6 var (IIl semester)

Nov 26th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. //Lab_9_Task1_var6
  2. #include "stdafx.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. class B
  7. {
  8.     int a;
  9. public:
  10.     B(int x) { a = x; }
  11.     void show_B() { cout << "B=   " << a << "\n"; }
  12. };
  13. class D1: public B
  14. {
  15.     int b;
  16. public:
  17.     D1(int x, int y) : B(y) { b = x; };
  18.     void show_D1() { cout << "D1=  " << b << "\n"; show_B(); }
  19. };
  20. class D2 : private B
  21. {
  22.     int c;
  23. public:
  24.     D2(int x, int y) : B(y) { c = x; };
  25.     void show_D2() { cout << "D2=  " << c << "\n"; show_B(); }
  26. };
  27. class D3: private B
  28. {
  29.     int d;
  30. public:
  31.     D3(int x, int y) : B(y) { d = x; };
  32.     void show_D3() { cout << "D3=  " << d << "\n"; show_B();}
  33. };
  34. class D4 : private D1
  35. {
  36.     int e;
  37. public:
  38.     D4(int x, int y, int z) : D1(y, z) { e = x; };
  39.     void show_D4() { cout << "D4=  " << e << "\n"; show_D1(); }
  40. };
  41. class D5 : public D1, public D2, private D3
  42. {
  43.     int f;
  44. public:
  45.     D5(int x, int y, int z, int i, int j, int k, int l) : D1(y, z), D2(i, j), D3(k, l) { f = x; }
  46.     void show_D5() { cout << "D5=  " << f << "\n"; show_D1(); show_D2(); show_D3(); }
  47. };
  48.  
  49. int main()
  50. {
  51.     D5 temp(100, 200, 300, 400, 500, 600, 700);
  52.     D4 temp1(1, 2, 3);
  53.     cout << "D5 temp(100, 200, 300, 400, 500, 600, 700);\n";
  54.     cout << "D4 temp1(1, 2, 3);\n";
  55.     cout << "\nFollowing the class hierarchy D5: \n";
  56.     temp.show_D5();
  57.     cout << "\nFollowing the class hierarchy D4\n";
  58.     temp1.show_D4();
  59.     system("pause");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment