Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Створити абстрактний клас «корабель»і похідні від нього «ракетний катер» та «пасажирський лайнер».
- Функції введення та виведення даних в базовому класі зробити абстрактними і визначити їх конкретно в похідних класах.
- Продемонструвати їхню роботу.
- */
- #include <iostream>
- #include <ctime>
- #include <stdlib.h>
- using namespace std;
- /*class Ship*/
- class Ship {
- protected:
- /*capacity*/
- float capacity;
- public:
- /*constructor*/
- Ship() {}
- /*virtual function set*/
- virtual void set() = 0;
- /*virtual function get*/
- virtual void get() = 0;
- /*virtual function to get capacity*/
- virtual void getCapacity() = 0;
- };
- /*class RocketBoat based on Ship*/
- class RocketBoat : virtual public Ship {
- private:
- /*count of rockets*/
- int rocketsCount;
- /*count of guns*/
- int gunsCount;
- public:
- /*constructor*/
- RocketBoat() : Ship() {}
- /*function set*/
- void set() {
- cout << "===Enter info about rocket boat===" << endl;
- cout << "\tcount of rockets: "; cin >> rocketsCount;
- cout << "\tount of guns: "; cin >> gunsCount;
- cout << endl;
- }
- /*function get*/
- void get() {
- cout << "===Info about rocket boat===" << endl;
- cout << "\tcount of rockets: " << rocketsCount << endl;
- cout << "\tount of guns: " << gunsCount << endl;
- cout << endl;
- }
- /*function to get capacity*/
- void getCapacity() {
- capacity = (rocketsCount * 1.5 + gunsCount * 1.2) * 3;
- cout << "capacity of rocket boat = " << capacity << endl;
- cout << endl;
- }
- };
- /*class PassengerLiner based on Ship*/
- class PassengerLiner : virtual public Ship {
- private:
- /*count of passengers*/
- int passengersCount;
- public:
- /*constructor*/
- PassengerLiner() : Ship() {}
- /*function set*/
- void set() {
- cout << "===Enter info about passenger liner===" << endl;
- cout << "\tcount of passengers: "; cin >> passengersCount;
- cout << endl;
- }
- /*function get*/
- void get() {
- cout << "===Info about passenger liner===" << endl;
- cout << "\tcount of passengers: " << passengersCount << endl;
- cout << endl;
- }
- /*function to get capacity*/
- void getCapacity() {
- capacity = passengersCount * 6;
- cout << "capacity of passenger liner = " << capacity << endl;
- cout << endl;
- }
- };
- int main() {
- Ship* ship;
- /*class RocketBoat*/
- ship = new RocketBoat;
- ship->set();
- ship->get();
- ship->getCapacity();
- /*class PassengerLiner*/
- ship = new PassengerLiner;
- ship->set();
- ship->get();
- ship->getCapacity();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement