Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- class B
- {
- int varB;
- public:
- B(int par1) { varB = par1; }
- void ShowB()
- {
- cout << "B=\t" << varB << endl;
- }
- virtual void ShowV()
- {
- cout<< "virt B=\t" << varB << endl;
- }
- };
- class D1: public B
- {
- int varD1;
- public:
- D1(int par1, int par2) : B(par2) { varD1 = par1; }
- void ShowD1()
- {
- cout << "D1=\t" << varD1 << endl;
- ShowB();
- }
- void ShowV()
- {
- cout<< "virt D1=\t" << varD1 << endl;
- }
- };
- class D2: private B
- {
- int varD2;
- public:
- D2(int par1, int par2) : B(par2) { varD2 = par1; }
- void ShowD2()
- {
- cout << "D2=\t" << varD2 << endl;
- ShowB();
- }
- };
- class D3: private B
- {
- int varD3;
- public:
- D3(int par1, int par2) : B(par2) { varD3 = par1; }
- void ShowD3()
- {
- cout << "D3=\t" << varD3 << endl;
- ShowB();
- }
- };
- class D4: private D1, public D2
- {
- int varD4;
- public:
- D4(int par1, int par2, int par3, int par4, int par5) : D1(par2, par3), D2(par4, par5) { varD4 = par1; }
- void ShowD4()
- {
- cout << "D4=\t" << varD4 << endl;
- ShowD1();
- ShowD2();
- }
- };
- class D5: public D2, private D3
- {
- int varD5;
- public:
- D5(int par1, int par2, int par3, int par4, int par5) : D2(par2, par3), D3(par4, par5) { varD5 = par1; }
- void ShowD5()
- {
- cout << "D5=\t" << varD5 << endl;
- ShowD2();
- ShowD3();
- }
- };
- int main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- cout << "D4 d4(1, 2, 3, 4, 5);" << endl << "D5 d5(1, 2, 3, 4, 5);" << endl;
- D4 d4(1, 2, 3, 4, 5);
- D5 d5(1, 2, 3, 4, 5);
- cout << "Следуя иерархии класса D4:" << endl;
- d4.ShowD4();
- cout << "Следуя иерархии класса D5:" << endl;
- d5.ShowD5();
- cout << "Работа виртуальных функций:" << endl;
- d4.ShowV();
- d5.ShowV();
- //cout << "Hello world!" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment