Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Визначити базовий клас «транспорт» і похідні від нього класи «вантажний транспорт» та «пасажирський транспорт».
- * Загальним для них є «чистий прибуток».
- * Елементами даних похідних класів та віртуальними функціями задатися САМОСТІЙНО!
- */
- #include <iostream>
- using namespace std;
- class Transport {
- protected:
- float maxMas;
- int countSeats;
- float hourlyProfit;
- public:
- Transport() {}
- Transport(float a, int b, float c) : maxMas(a), countSeats(b), hourlyProfit(c) {}
- virtual void set() = 0;
- virtual void get() = 0;
- virtual void calcMonthProfit() = 0;
- };
- class FreightTransport : public Transport {
- public:
- FreightTransport() {}
- FreightTransport(float a, int b, float c) : Transport(a, b, c) {}
- void set() {
- cout << "Enter info about freight transport:" << endl;
- cout << "\tmaximum weight: ";
- cin >> maxMas;
- cout << "\tcount of seats: ";
- cin >> countSeats;
- cout << "\thourly profit: ";
- cin >> hourlyProfit;
- cout << endl;
- }
- void get() {
- cout << "Info about freight transport:" << endl;
- cout << "\tmaximum weight: " << maxMas << endl;
- cout << "\tcount of seats: " << countSeats << endl;
- cout << "\thourly profit: " << hourlyProfit << endl << endl;
- }
- void calcMonthProfit() {
- float profit = hourlyProfit * 24 * 30 * 1.5;
- cout << "Monthly profit of freight transport" << " = " << profit << endl << endl;
- }
- };
- class PassengerTransport : public Transport {
- public:
- PassengerTransport() {}
- PassengerTransport(float a, int b, float c) : Transport(a, b, c) {}
- void set() {
- cout << "Enter info about passenger transport:" << endl;
- cout << "\tmaximum weight: ";
- cin >> maxMas;
- cout << "\tcount of seats: ";
- cin >> countSeats;
- cout << "\thourly profit: ";
- cin >> hourlyProfit;
- cout << endl;
- }
- void get() {
- cout << "Info about passenger transport:" << endl;
- cout << "\tmaximum weight: " << maxMas << endl;
- cout << "\tcount of seats: " << countSeats << endl;
- cout << "\thourly profit: " << hourlyProfit << endl << endl;
- }
- void calcMonthProfit() {
- float profit = hourlyProfit * 24 * 30 * 1.25;
- cout << "Monthly profit of passenger transport" << " = " << profit << endl << endl;
- }
- };
- int main() {
- Transport* a = new FreightTransport();
- a->set(); //функція класу FreightTransport
- a->get(); //функція класу FreightTransport
- a->calcMonthProfit(); //функція класу FreightTransport
- Transport* b = new PassengerTransport();
- b->set(); //функція класу PassengerTransport
- b->get(); //функція класу PassengerTransport
- b->calcMonthProfit(); //функція класу PassengerTransport
- delete a, b;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement