Advertisement
xSiRON

PROG2-1_Contatore_05-04-2016

Apr 5th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Contatore{
  5. private:
  6.     int val;
  7.     // Contatore();
  8.  
  9. public:
  10.     static int pippo;
  11.  
  12.     Contatore(int val){ this->val = val; }
  13.     void inc();
  14.     void dec();
  15.     void reset();
  16.     int is_zero();
  17.     int is_greater_than(int x);
  18. };
  19.  
  20. void Contatore::inc(){ val++; }
  21. void Contatore::dec(){ val--; if(val<0) val = 0; }
  22. void Contatore::reset(){ val = 0; }
  23. int Contatore::is_zero(){ return !val; } // quando vale 0 รจ vera, diversamente รจ falsa
  24. int Contatore::is_greater_than(int x){ return (val > x); } // restituisce il valore dell'esp. booleana
  25.  
  26. int Contatore::pippo;
  27.  
  28. int main(){
  29.     Contatore::pippo = 5;
  30.     Contatore *c = new Contatore(0);
  31.  
  32.     //for( int i = 0; i < 100; i++ )
  33.     //for( c->reset(); !(c->is_greater_than(99)); c->inc() )
  34.  
  35.     c->pippo = 6;
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement