Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class robot
- {
- public:
- virtual void praca()const = 0;
- virtual robot& operator-=(const int& a2) = 0;
- virtual ~robot(){}
- };
- class rt1 : public robot
- {
- protected:
- string * txt;
- public:
- rt1():txt(new string("brak")){}
- rt1(const string& a1): txt(new string(a1)){}
- rt1(const rt1& a1): txt(new string(*a1.txt)){}
- rt1& operator =(const rt1& a1)
- {
- if(this != &a1)
- {
- delete txt;
- txt = new string(*a1.txt);
- }
- return *this;
- }
- void praca()const
- {
- cout << *txt << endl;
- }
- robot & operator-=(const int& a1)
- {
- return *this;
- }
- ~rt1(){delete txt;}
- };
- class rt2 : public rt1
- {
- protected:
- int w;
- public:
- rt2():rt1(),w(0){}
- rt2(const string& a1,const int& a2): rt1(a1),w(a2){}
- void praca()const
- {
- cout << *txt << " " << w << endl;
- }
- robot & operator-=(const int& a1)
- {
- w -= a1;
- return *this;
- }
- };
- int main()
- {
- const rt1 odbior("Odebrano gotowy produkt");
- robot * linia[5];
- linia[0] = new rt1("Polozono");
- linia[1] = new rt2("Uderzono",5);
- linia[2] = new rt2("Prawo",4);
- linia[3] = new rt2("Uderzono",7);
- linia[4] = new rt1(odbior);
- for(int i = 0; i < 5; i++)
- {
- linia[i] -> praca();
- }
- cout << "*******3*******" << endl;
- cout << endl;
- *linia[3] -= 5;
- for(int i = 0; i < 5; i++)
- {
- delete linia[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement