Xom9ik

Lab_9_Task1/9 var (IIl semester)

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