Facebook
From Cute Pelican, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 39
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Car
  6. {
  7.     public:
  8.     string color;
  9.     int horsepower;
  10.     int numberseats;
  11.     public:
  12.        virtual void Brumbrum(){
  13.        }
  14.  
  15.         friend ostream& operator <<(ostream&, const Car&);
  16. };
  17.  
  18. class Racecar :public Car
  19. {
  20.     public:
  21.     float nitro;
  22.     public:
  23.        Racecar(int hp, int ns, string c)
  24.         {
  25.             horsepower=hp;
  26.             numberseats=ns;
  27.             color=c;
  28.             nitro=9.4;
  29.         }
  30.         void Brumbrum()
  31.         {
  32.             cout<<"dzwiek Brumbrum \n";
  33.         }
  34.         friend ostream& operator <<(ostream&, const Racecar&);
  35. };
  36.  
  37. class Truck :public Car
  38. {
  39.     public:
  40.         string trailer;
  41.  
  42.     public:
  43.         Truck(int hp, int ns, string c)
  44.         {
  45.             horsepower=hp;
  46.             numberseats=ns;
  47.             color=c;
  48.             trailer="Temared";
  49.         }
  50.     void Brumbrum()
  51.     {
  52.         cout<<"dzwiek Wrrrrr\n";
  53.     }
  54.     friend ostream& operator <<(ostream&, const Truck&);
  55. };
  56.  
  57. ostream& operator<<(ostream& os, const Car& cc)
  58. {
  59.     os << "kolor "<< cc.color << " " << cc.horsepower << " koni "<< cc.numberseats <<" miejsca "<<endl;
  60.     return os;
  61. }
  62. ostream& operator<<(ostream& os, const Racecar& rc)
  63. {
  64.     os<< ""<<rc.nitro<<" l.pojemnosci nitro"<<endl;
  65.     return os;
  66. }
  67.  
  68. ostream& operator<<(ostream& os, const Truck& tt)
  69. {
  70.     os<< "przyczepa firmy " <<tt.trailer <<""<<endl;
  71.     return os;
  72. }
  73.  
  74.  
  75. int main()
  76. {
  77.  
  78.  
  79.     vector < Car > c1;
  80.     vector < Racecar > r1;
  81.     vector < Truck > t1;
  82.     c1.emplace_back(Racecar(700,2,"czerwony"));
  83.     c1.emplace_back(Truck(400,2,"zielony"));
  84.     t1.emplace_back(350,1,"bialy");
  85.     r1.emplace_back(500,3,"czarny");
  86.  
  87.  
  88.     for( int i = 0; i < c1.size(); i++ )
  89.     {
  90.         cout<<c1[i]<<endl;
  91.         if (i==0)
  92.         {
  93.         cout<<r1[i]<<endl;
  94.         r1[i].Brumbrum();
  95.         }
  96.  
  97.     }
  98.  
  99.     for(int j = 0; j<c1.size(); j++)
  100.     {
  101.         if(j==0)
  102.         {
  103.             cout<<t1[j]<<endl;
  104.             t1[j].Brumbrum();
  105.         }
  106.  
  107.     }
  108.  
  109.     return 0;
  110. }
  111.