Advertisement
darkjessy94

asd es1 anfore c++

Oct 3rd, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 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(int capacita){this->capacita=capacita;}
  24.         ~Anfora(){}
  25.         void riempi(){versa(capacita);}
  26.         void svuota(){togli(capacita);}
  27.         int isVuota()
  28.             {
  29.                 if(getQt()==0)
  30.                     return 1;
  31.                 else
  32.                     return 0;
  33.             }
  34.         int isPiena()
  35.             {
  36.                 if(capacita==getQt())
  37.                     return 1;
  38.                 else
  39.                     return 0;
  40.             }
  41.         void spostaContenuto(Anfora &ogg)
  42.             {
  43.                 int diff=ogg.getCapacita()-ogg.getQt();
  44.                 if(getQt()<=diff)
  45.                     {
  46.                         ogg.versa(getQt());
  47.                         togli(getQt());
  48.                     }
  49.                 else
  50.                     {
  51.                         ogg.versa(diff);
  52.                         togli(diff);
  53.                     }
  54.  
  55.             }
  56.         int getCapacita(){return capacita;}
  57. };
  58.  
  59. class Indovinello
  60. {
  61.     private:
  62.         Anfora *a3;
  63.         Anfora *a5;
  64.     public:
  65.         Indovinello(Anfora *a3,Anfora *a5)
  66.         {
  67.             this->a3=a3;
  68.             this->a5=a5;
  69.         }
  70.         ~Indovinello(){delete a3; delete a5;}
  71.         void Risolvi()
  72.         {
  73.             cout<<"a5: "<<a5->getQt()<<endl;
  74.             a5->riempi();
  75.             cout<<"a5: "<<a5->getQt()<<endl;
  76.             cout<<"a3: "<<a3->getQt()<<endl;
  77.             a5->spostaContenuto(*a3);
  78.             cout<<"a3: "<<a3->getQt()<<endl;
  79.             cout<<"a5: "<<a5->getQt()<<endl;
  80.             a3->svuota();
  81.             cout<<"a3: "<<a3->getQt()<<endl;
  82.             a5->riempi();
  83.             a5->spostaContenuto(*a3);
  84.             cout<<"a3: "<<a3->getQt()<<endl;
  85.             cout<<"a5: "<<a5->getQt()<<endl;
  86.         }
  87.  
  88.  
  89. };
  90.  
  91. int main()
  92. {
  93.     Anfora *a3;
  94.     Anfora *a5;
  95.     a3=new Anfora(3);
  96.     a5=new Anfora(5);
  97.  
  98.     Indovinello I(a3,a5);
  99.     I.Risolvi();
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement