Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Contenitore
- {
- private:
- int qt;
- public:
- Contenitore(){qt=0;}
- ~Contenitore(){}
- void versa(int lt){qt=qt+lt;}
- void togli(int lt){qt=qt-lt;}
- int getQt(){return qt;}
- };
- class Anfora : public Contenitore
- {
- private:
- int capacita;
- public:
- Anfora(){}
- Anfora(int capacita){this->capacita=capacita;}
- ~Anfora(){}
- void riempi(){versa(capacita);}
- void svuota(){togli(capacita);}
- int isVuota()
- {
- if(getQt()==0)
- return 1;
- else
- return 0;
- }
- int isPiena()
- {
- if(capacita==getQt())
- return 1;
- else
- return 0;
- }
- void spostaContenuto(Anfora &ogg)
- {
- int diff=ogg.getCapacita()-ogg.getQt();
- if(getQt()<=diff)
- {
- ogg.versa(getQt());
- togli(getQt());
- }
- else
- {
- ogg.versa(diff);
- togli(diff);
- }
- }
- int getCapacita(){return capacita;}
- };
- class Indovinello
- {
- private:
- Anfora a3;
- Anfora a5;
- public:
- Indovinello(Anfora a3,Anfora a5)
- {
- this->a3=a3;
- this->a5=a5;
- }
- ~Indovinello(){}
- void Risolvi()
- {
- cout<<"a5: "<<a5.getQt()<<endl;
- a5.riempi();
- cout<<"a5: "<<a5.getQt()<<endl;
- cout<<"a3: "<<a3.getQt()<<endl;
- a5.spostaContenuto(a3);
- cout<<"a3: "<<a3.getQt()<<endl;
- cout<<"a5: "<<a5.getQt()<<endl;
- a3.svuota();
- cout<<"a3: "<<a3.getQt()<<endl;
- a5.riempi();
- a5.spostaContenuto(a3);
- cout<<"a3: "<<a3.getQt()<<endl;
- cout<<"a5: "<<a5.getQt()<<endl;
- }
- };
- int main()
- {
- Anfora a3(3);
- Anfora a5(5);
- Indovinello I(a3,a5);
- I.Risolvi();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement