Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Contenitore{
- int qt = 0;
- public:
- int get_qt(){return qt;}
- void versa(int lt){qt += lt;}
- void togli(int lt){
- qt -= lt;
- if(qt < 0)
- qt = 0;
- }
- };
- class Anfora: public Contenitore{
- int capacita;
- public:
- Anfora(int x):Contenitore(){capacita = x;}
- int get_capacita(){return capacita;}
- void riempi(){
- if(get_qt()<capacita){
- int a = capacita - get_qt();
- versa(a);
- }
- }
- void svuota(){
- if(get_qt() != 0){
- togli(get_qt());
- }
- }
- bool isVuota(){
- if(get_qt() == 0)return 1;else return 0;
- }
- bool isPiena(){
- if(get_qt() == capacita)return 1;else return 0;
- }
- void spostaContenuto(Anfora &x){
- while(get_qt() > 0 && x.get_qt() < x.get_capacita()){
- togli(1);
- x.versa(1);
- }
- }
- };
- class Indovinello{
- Anfora A_5 = Anfora(5);
- Anfora A_3 = Anfora(3);
- public:
- Indovinello(){cout << "Indovinello delle anfore risolto automaticamente" << endl;}
- void risolvi(){
- cout << "Anfora 5\tAnfora 3" << endl;
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.riempi();
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.spostaContenuto(A_5);
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.riempi();
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.spostaContenuto(A_5);
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_5.svuota();
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.spostaContenuto(A_5);
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.riempi();
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- A_3.spostaContenuto(A_5);
- cout << A_5.get_qt() << "\t\t" << A_3.get_qt() << endl;
- }
- };
- int main()
- {
- Indovinello anfore;
- anfore.risolvi();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement