Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include "locale.h"
- #include "Base.h"
- #include "Squar.h"
- #include "Circle.h"
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "RUS");
- char sname[30];
- strcpy_s(sname, "Circle");
- Circle C1(3, sname),C2;
- cout << C1.get_name() << endl << "S= " << C1.S() << endl;
- strcpy_s(sname, "Squar 1");
- Squar S1(3, sname),S2;
- cout << S1.get_name() <<endl<< "S= " << S1.S() << endl;
- strcpy_s(sname, "Squar 2");
- S2 = S1;
- S2.set_name(sname);
- cout << S2.get_name() << endl << "S= " << S2.S()<<endl;
- Base B, B1;
- //ранний полиморфизм
- B = C1;
- cout << B.get_name() << "S= " << B.S() << endl;
- B = S1;
- cout << B.get_name() << "S= " << B.S() << endl;
- //поздний полиморфизм (указатель на базовый класс)
- Base *ptrBase;
- ptrBase = &C1;
- cout << (*ptrBase).get_name() << "S= " << (*ptrBase).S() << endl;
- ptrBase = &S1;
- cout << (*ptrBase).get_name() << "S= " << (*ptrBase).S() << endl;
- Base *Sharp[3];
- Sharp[0] = &C1;
- Sharp[1] = &S1;
- Sharp[2] = &S2;
- for (int i = 0; i < 3; i++) cout << (*Sharp[i]).get_name() << "S= " << (*Sharp[i]).S() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement