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 B2
- {
- int a;
- public:
- B2(int x) { a = x; }
- void show_B2() { cout << "B2= " << a << "\n"; }
- };
- class B1
- {
- int b;
- public:
- B1(int x) { b = x; };
- void show_B1() { cout << "B1= " << b << "\n"; }
- };
- class D1 : public B2, protected B1
- {
- 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 B3
- {
- int d;
- public:
- B3(int x) { d = x; };
- void show_B3() { cout << "B3= " << d << "\n"; }
- };
- class D2 : public D1, protected B3
- {
- int e;
- public:
- D2(int x, int y, int z, int i, int j) : D1(y, z, i), B3(j) { e = x; };
- void show_D2() { cout << "D2= " << e << "\n"; show_D1(); show_B3(); }
- };
- class D3 : public D2
- {
- int f;
- public:
- D3(int x, int y, int z, int i, int j, int k) : D2(y, z, i, j, k) { f = x; }
- void show_D3() { cout << "D3= " << f << "\n"; show_D2(); }
- };
- int main()
- {
- D3 temp(100, 200, 300, 400, 500, 600);
- D2 temp1(1, 2, 3, 4, 5);
- cout << "D3 temp(100, 200, 300, 400, 500, 600);\n";
- cout << "D4 temp1(1,2,3,4,5);\n";
- cout << "\nFollowing the class hierarchy D3: \n";
- temp.show_D3();
- cout << "\nFollowing the class hierarchy D4\n";
- temp1.show_D2();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment