Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_9_Task1_var6
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class B
- {
- int a;
- public:
- B(int x) { a = x; }
- void show_B() { cout << "B= " << a << "\n"; }
- };
- class D1: public B
- {
- int b;
- public:
- D1(int x, int y) : B(y) { b = x; };
- void show_D1() { cout << "D1= " << b << "\n"; show_B(); }
- };
- class D2 : private B
- {
- int c;
- public:
- D2(int x, int y) : B(y) { c = x; };
- void show_D2() { cout << "D2= " << c << "\n"; show_B(); }
- };
- class D3: private B
- {
- int d;
- public:
- D3(int x, int y) : B(y) { d = x; };
- void show_D3() { cout << "D3= " << d << "\n"; show_B();}
- };
- class D4 : private D1
- {
- int e;
- public:
- D4(int x, int y, int z) : D1(y, z) { e = x; };
- void show_D4() { cout << "D4= " << e << "\n"; show_D1(); }
- };
- class D5 : public D1, public D2, private D3
- {
- int f;
- public:
- 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; }
- void show_D5() { cout << "D5= " << f << "\n"; show_D1(); show_D2(); show_D3(); }
- };
- int main()
- {
- D5 temp(100, 200, 300, 400, 500, 600, 700);
- D4 temp1(1, 2, 3);
- cout << "D5 temp(100, 200, 300, 400, 500, 600, 700);\n";
- cout << "D4 temp1(1, 2, 3);\n";
- cout << "\nFollowing the class hierarchy D5: \n";
- temp.show_D5();
- cout << "\nFollowing the class hierarchy D4\n";
- temp1.show_D4();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment