Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Створити абстрактний клас «корабель»і похідні від нього «ракетний катер» та «пасажирський лайнер».
- // Функції введення та виведення даних в базовому класі зробити абстрактними і визначити їх конкретно в похідних класах.
- // Продемонструвати їхню роботу.
- #include <iostream>
- using namespace std;
- class ship {
- protected:
- string name;
- public:
- virtual void input() = 0;
- virtual void output() = 0;
- };
- class pasship : public ship {
- int people;
- public :
- void input() {
- cout << "Name of ship: ";
- cin >> name;
- cout << "Number of people on board: ";
- cin >> people;
- cout << endl;
- }
- void output() {
- cout << "Name of ship: " << name << endl;
- cout << "Number of people on board: " << people << endl;
- cout << endl;
- }
- };
- class batleship : public ship {
- int weapon;
- public :
- void input() {
- cout << "Name of ship: ";
- cin >> name;
- cout << "Number of weapons: ";
- cin >> weapon;
- cout << endl;
- }
- void output() {
- cout << "Name of ship: " << name << endl;
- cout << "Number of weapons: " << weapon << endl;
- cout << endl;
- }
- };
- int main() {
- ship *a = new pasship;
- cout << "Pasship:" << endl;
- a->input();
- a->output();
- a = new batleship;
- cout << "Batleship:" << endl;
- a->input();
- a->output();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement