Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class robot
  7. {
  8. public:
  9.  
  10.     virtual void praca()const = 0;
  11.  
  12.     virtual robot& operator-=(const int& a2) = 0;
  13.  
  14.     virtual ~robot(){}
  15. };
  16.  
  17. class rt1 : public robot
  18. {
  19. protected:
  20.     string * txt;
  21. public:
  22.     rt1():txt(new string("brak")){}
  23.     rt1(const string& a1): txt(new string(a1)){}
  24.     rt1(const rt1& a1): txt(new string(*a1.txt)){}
  25.  
  26.  
  27.     rt1& operator =(const rt1& a1)
  28.     {
  29.         if(this != &a1)
  30.         {
  31.             delete txt;
  32.             txt = new string(*a1.txt);
  33.         }
  34.         return *this;
  35.     }
  36.  
  37.  
  38.  
  39.     void praca()const
  40.     {
  41.         cout << *txt << endl;
  42.     }
  43.  
  44.     robot & operator-=(const int& a1)
  45.     {
  46.         return *this;
  47.     }
  48.  
  49.  
  50.     ~rt1(){delete txt;}
  51. };
  52.  
  53. class rt2 : public rt1
  54. {
  55. protected:
  56.     int w;
  57. public:
  58.     rt2():rt1(),w(0){}
  59.     rt2(const string& a1,const int& a2): rt1(a1),w(a2){}
  60.  
  61.     void praca()const
  62.     {
  63.         cout << *txt << " " << w << endl;
  64.     }
  65.  
  66.  
  67.     robot & operator-=(const int& a1)
  68.     {
  69.         w -= a1;
  70.         return *this;
  71.     }
  72.  
  73.  
  74.  
  75. };
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84. int main()
  85. {
  86.     const rt1 odbior("Odebrano gotowy produkt");
  87.     robot * linia[5];
  88.  
  89.     linia[0] = new rt1("Polozono");
  90.     linia[1] = new rt2("Uderzono",5);
  91.     linia[2] = new rt2("Prawo",4);
  92.     linia[3] = new rt2("Uderzono",7);
  93.     linia[4] = new rt1(odbior);
  94.  
  95.     for(int i = 0; i < 5; i++)
  96.     {
  97.         linia[i] -> praca();
  98.     }
  99.  
  100.     cout << "*******3*******" << endl;
  101.     cout << endl;
  102.  
  103.  
  104.     *linia[3] -= 5;
  105.  
  106.     for(int i = 0; i < 5; i++)
  107.     {
  108.         delete linia[i];
  109.     }
  110.  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement