Advertisement
darkjessy94

Untitled

Oct 4th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.27 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class Contenitore
  7. {
  8.     private:
  9.         int qt;
  10.     public:
  11.         Contenitore(){qt=0;}
  12.         ~Contenitore(){}
  13.         void versa(int lt){qt=qt+lt;}
  14.         void togli(int lt){qt=qt-lt;}
  15.         int getQt(){return qt;}
  16. };
  17.  
  18. class Anfora : public Contenitore
  19. {
  20.     private:
  21.         int capacita;
  22.     public:
  23.         Anfora(){}
  24.         Anfora(int capacita){this->capacita=capacita;}
  25.         ~Anfora(){}
  26.         void riempi(){versa(capacita);}
  27.         void svuota(){togli(capacita);}
  28.         int isVuota()
  29.             {
  30.                 if(getQt()==0)
  31.                     return 1;
  32.                 else
  33.                     return 0;
  34.             }
  35.         int isPiena()
  36.             {
  37.                 if(capacita==getQt())
  38.                     return 1;
  39.                 else
  40.                     return 0;
  41.             }
  42.         void spostaContenuto(Anfora &ogg)
  43.             {
  44.                 int diff=ogg.getCapacita()-ogg.getQt();
  45.                 if(getQt()<=diff)
  46.                     {
  47.                         ogg.versa(getQt());
  48.                         togli(getQt());
  49.                     }
  50.                 else
  51.                     {
  52.                         ogg.versa(diff);
  53.                         togli(diff);
  54.                     }
  55.  
  56.             }
  57.         int getCapacita(){return capacita;}
  58. };
  59.  
  60. class Indovinello
  61. {
  62.     private:
  63.         Anfora a3;
  64.         Anfora a5;
  65.     public:
  66.         Indovinello(Anfora a3,Anfora a5)
  67.         {
  68.             this->a3=a3;
  69.             this->a5=a5;
  70.         }
  71.         ~Indovinello(){}
  72.  
  73.         void Risolvi()
  74.         {
  75.             cout<<"a5: "<<a5.getQt()<<endl;
  76.             a5.riempi();
  77.             cout<<"a5: "<<a5.getQt()<<endl;
  78.             cout<<"a3: "<<a3.getQt()<<endl;
  79.             a5.spostaContenuto(a3);
  80.             cout<<"a3: "<<a3.getQt()<<endl;
  81.             cout<<"a5: "<<a5.getQt()<<endl;
  82.             a3.svuota();
  83.             cout<<"a3: "<<a3.getQt()<<endl;
  84.             a5.riempi();
  85.             a5.spostaContenuto(a3);
  86.             cout<<"a3: "<<a3.getQt()<<endl;
  87.             cout<<"a5: "<<a5.getQt()<<endl;
  88.  
  89.         }
  90.  
  91.  
  92. };
  93.  
  94. int main()
  95. {
  96.     Anfora a3(3);
  97.     Anfora a5(5);
  98.  
  99.     Indovinello I(a3,a5);
  100.     I.Risolvi();
  101.  
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement