Advertisement
Vladislav_Bezruk

Untitled

Oct 14th, 2021 (edited)
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.95 KB | None | 0 0
  1. /*
  2. * Визначити базовий клас «транспорт» і похідні від нього класи «вантажний транспорт» та «пасажирський транспорт».
  3. * Загальним для них є «чистий прибуток».
  4. * Елементами даних похідних класів та віртуальними функціями задатися САМОСТІЙНО!
  5. */
  6.  
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. class Transport {
  12.     protected:
  13.         float maxMas;
  14.         int countSeats;
  15.         float hourlyProfit;
  16.  
  17.     public:
  18.         Transport() {}
  19.  
  20.         Transport(float a, int b, float c) : maxMas(a), countSeats(b), hourlyProfit(c) {}
  21.  
  22.         virtual void set() = 0;
  23.  
  24.         virtual void get() = 0;
  25.  
  26.         virtual void calcMonthProfit() = 0;
  27. };
  28.  
  29. class FreightTransport : public Transport {
  30.     public:
  31.         FreightTransport() {}
  32.  
  33.         FreightTransport(float a, int b, float c) : Transport(a, b, c) {}
  34.  
  35.         void set() {
  36.             cout << "Enter info about freight transport:" << endl;
  37.             cout << "\tmaximum weight: ";
  38.             cin >> maxMas;
  39.             cout << "\tcount of seats: ";
  40.             cin >> countSeats;
  41.             cout << "\thourly profit: ";
  42.             cin >> hourlyProfit;
  43.  
  44.             cout << endl;
  45.         }
  46.  
  47.         void get() {
  48.             cout << "Info about freight transport:" << endl;
  49.             cout << "\tmaximum weight: " << maxMas << endl;
  50.             cout << "\tcount of seats: " << countSeats << endl;
  51.             cout << "\thourly profit: " << hourlyProfit << endl << endl;
  52.         }
  53.  
  54.         void calcMonthProfit() {
  55.             float profit = hourlyProfit * 24 * 30 * 1.5;
  56.             cout << "Monthly profit of freight transport" << " = " << profit << endl << endl;
  57.         }
  58. };
  59.  
  60. class PassengerTransport : public Transport {
  61.     public:
  62.         PassengerTransport() {}
  63.  
  64.         PassengerTransport(float a, int b, float c) : Transport(a, b, c) {}
  65.  
  66.         void set() {
  67.             cout << "Enter info about passenger transport:" << endl;
  68.             cout << "\tmaximum weight: ";
  69.             cin >> maxMas;
  70.             cout << "\tcount of seats: ";
  71.             cin >> countSeats;
  72.             cout << "\thourly profit: ";
  73.             cin >> hourlyProfit;
  74.  
  75.             cout << endl;
  76.         }
  77.  
  78.         void get() {
  79.             cout << "Info about passenger transport:" << endl;
  80.             cout << "\tmaximum weight: " << maxMas << endl;
  81.             cout << "\tcount of seats: " << countSeats << endl;
  82.             cout << "\thourly profit: " << hourlyProfit << endl << endl;
  83.         }
  84.  
  85.         void calcMonthProfit() {
  86.             float profit = hourlyProfit * 24 * 30 * 1.25;
  87.             cout << "Monthly profit of passenger transport" << " = " << profit << endl << endl;
  88.         }
  89. };
  90.  
  91. int main() {
  92.  
  93.     Transport* a = new FreightTransport();
  94.  
  95.     a->set(); //функція класу FreightTransport
  96.     a->get(); //функція класу FreightTransport
  97.     a->calcMonthProfit(); //функція класу FreightTransport
  98.  
  99.     Transport* b = new PassengerTransport();
  100.  
  101.     b->set(); //функція класу PassengerTransport
  102.     b->get(); //функція класу PassengerTransport
  103.     b->calcMonthProfit(); //функція класу PassengerTransport
  104.  
  105.     delete a, b;
  106.  
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement