Advertisement
Alysik

Untitled

Dec 1st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. class Transport {
  6. protected:
  7.     int age;
  8.     int coast;
  9.     string name;
  10. public:
  11.     Transport() {
  12.         age = 0;
  13.         coast = 0;
  14.     }
  15.     ~Transport(){}
  16.  
  17.     void input(int age, int coast, string name) {
  18.         (*this).age = age;
  19.         (*this).coast = coast;
  20.         (*this).name = name;
  21.     }
  22.     friend istream& operator>>(istream& is, Transport& x);
  23.     friend ostream& operator <<(ostream& os, Transport& x);
  24.  
  25.     virtual void output() {
  26.         cout << "Age = " << age << " Coast = " << coast << " Name " << name << endl;
  27.     }
  28. };
  29.  
  30. class ElectricTransport : public Transport{
  31. protected:
  32.     float chargingTime;
  33. public:
  34.     ElectricTransport() {
  35.         chargingTime = 0;
  36.     }
  37.     ~ElectricTransport(){}
  38.     virtual void input(int age, int coast, string name, float chargingTime) {
  39.         (*this).age = age;
  40.         (*this).coast = coast;
  41.         (*this).name = name;
  42.         (*this).chargingTime = chargingTime;
  43.     }
  44.  
  45.     friend istream& operator>>(istream& is, ElectricTransport& x);
  46.     friend ostream& operator <<(ostream& os, ElectricTransport& x);
  47.  
  48.     virtual void output() {
  49.         cout << "Age = " << age << " Coast = " << coast << " Name = " << name <<" Charging time = "<< endl;
  50.     }
  51.  
  52. };
  53.  
  54. class RailwayTransport : public Transport{
  55. };
  56.  
  57. istream& operator>>(istream& is, Transport& x) {
  58.     cout << "Enter age:" << endl;
  59.     is >> x.age;
  60.     cout << "Enter coast: " << endl;
  61.     is >> x.coast;
  62.     cout << "Enter name: " << endl;
  63.     is >> x.name;
  64.     return is;
  65. }
  66.  
  67. ostream& operator <<(ostream& os, Transport& x) {
  68.     os << "Age = " << x.age << endl;
  69.     os << "Coast = " << x.coast << endl;
  70.     os << "Name = " << x.name << endl;
  71.     return os;
  72. }
  73.  
  74. istream& operator>>(istream& is, ElectricTransport& x) {
  75.     cout << "Enter age:" << endl;
  76.     is >> x.age;
  77.     cout << "Enter coast: " << endl;
  78.     is >> x.coast;
  79.     cout << "Enter name: " << endl;
  80.     is >> x.name;
  81.     cout << "Enter charging time: " << endl;
  82.     is >> x.chargingTime;
  83.     return is;
  84. }
  85.  
  86. ostream& operator <<(ostream& os, ElectricTransport& x) {
  87.     os << "Age = " << x.age << endl;
  88.     os << "Coast = " << x.coast << endl;
  89.     os << "Name = " << x.name << endl;
  90.     os << "Charging Time = " << x.chargingTime << endl;
  91.     return os;
  92. }
  93.  
  94.  
  95. int main() {
  96.     Transport k;
  97.     cin >> k;
  98.     cout << k;
  99.     ElectricTransport f;
  100.     cin >> f;
  101.     cout << f;
  102.     RailwayTransport d;
  103.     cin >> d;
  104.     cout << d;
  105.     return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement