Xom9ik

Lab_9_Task1/16 var (IIl semester)

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