Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Lab_9_Task1
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class B1
- {
- int a;
- public:
- B1(int x) { a = x; };
- void show_B1() { cout << "B1 = " << a << "\n"; }
- };
- class B2
- {
- int b;
- public:
- B2(int x) { b = x; }
- void show_B2() { cout << "B2 = " << b << "\n"; }
- };
- class D1 : public B1, private B2
- {
- int c;
- public:
- D1(int x, int y, int z) : B1(y), B2(z) { c = x; };
- void show_D1() { cout << "D1 = " << c << "\n"; show_B1(); show_B2(); }
- };
- class D2 : private D1
- {
- int d;
- public:
- D2(int x, int y, int z, int i) : D1(y, z, i) { d = x; };
- void show_D2() { cout << "D2 = " << d << "\n"; show_D1(); }
- };
- class D3 : public D2
- {
- int e;
- public:
- D3(int x, int y, int z, int i, int j) : D2(y, z, i, j) { e = x; }
- void show_D3() { cout << "D3 = " << e << "\n"; show_D2(); }
- };
- int main()
- {
- D3 temp(100, 200, 300, 400, 500);
- D2 temp1(1, 2, 3, 4);
- cout << "D3 temp(100, 200, 300, 400, 500);\n";
- cout << "D4 temp1(1,2,3,4);\n";
- cout << "\nFollowing the class hierarchy D3: \n";
- temp.show_D3();
- cout << "\nFollowing the class hierarchy D4\n";
- temp1.show_D2();
- cout << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment