Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Contatore{
- private:
- int val;
- // Contatore();
- public:
- static int pippo;
- Contatore(int val){ this->val = val; }
- void inc();
- void dec();
- void reset();
- int is_zero();
- int is_greater_than(int x);
- };
- void Contatore::inc(){ val++; }
- void Contatore::dec(){ val--; if(val<0) val = 0; }
- void Contatore::reset(){ val = 0; }
- int Contatore::is_zero(){ return !val; } // quando vale 0 รจ vera, diversamente รจ falsa
- int Contatore::is_greater_than(int x){ return (val > x); } // restituisce il valore dell'esp. booleana
- int Contatore::pippo;
- int main(){
- Contatore::pippo = 5;
- Contatore *c = new Contatore(0);
- //for( int i = 0; i < 100; i++ )
- //for( c->reset(); !(c->is_greater_than(99)); c->inc() )
- c->pippo = 6;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement