Xom9ik

Lab_9_Task1/3 var (IIl semester)

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