Advertisement
lucasiano97

Indovinello delle Anfore

Sep 29th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Contenitore{
  6.     int qt = 0;
  7. public:
  8.     int get_qt(){return qt;}
  9.     void versa(int lt){qt += lt;}
  10.     void togli(int lt){
  11.         qt -= lt;
  12.         if(qt < 0)
  13.             qt = 0;
  14.     }
  15. };
  16.  
  17. class Anfora: public Contenitore{
  18.     int capacita;
  19. public:
  20.     Anfora(int x):Contenitore(){capacita = x;}
  21.     int get_capacita(){return capacita;}
  22.     void riempi(){
  23.         if(get_qt()<capacita){
  24.               int a = capacita - get_qt();
  25.               versa(a);
  26.         }
  27.     }
  28.     void svuota(){
  29.         if(get_qt() != 0){
  30.             togli(get_qt());
  31.         }
  32.     }
  33.     bool isVuota(){
  34.         if(get_qt() == 0)return 1;else return 0;
  35.     }
  36.     bool isPiena(){
  37.         if(get_qt() == capacita)return 1;else return 0;
  38.     }
  39.     void spostaContenuto(Anfora &x){
  40.         while(get_qt() > 0 && x.get_qt() < x.get_capacita()){
  41.             togli(1);
  42.             x.versa(1);
  43.         }
  44.     }
  45. };
  46.  
  47. class Indovinello{
  48.     Anfora A_5 = Anfora(5);
  49.     Anfora A_3 = Anfora(3);
  50. public:
  51.     Indovinello(){cout << "Indovinello delle anfore risolto automaticamente" << endl;}
  52.     void risolvi(){
  53.         cout << "Anfora 5\tAnfora 3" << endl;
  54.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  55.         A_3.riempi();
  56.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  57.         A_3.spostaContenuto(A_5);
  58.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  59.         A_3.riempi();
  60.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  61.         A_3.spostaContenuto(A_5);
  62.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  63.         A_5.svuota();
  64.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  65.         A_3.spostaContenuto(A_5);
  66.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  67.         A_3.riempi();
  68.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  69.         A_3.spostaContenuto(A_5);
  70.         cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
  71.     }
  72. };
  73.  
  74. int main()
  75. {
  76.     Indovinello anfore;
  77.     anfore.risolvi();
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement