User Tools

Site Tools


in202:seance_2:td_2:part_i

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
in202:seance_2:td_2:part_i [2021/04/11 13:46]
bmonsuez [Question n° 1.1]
in202:seance_2:td_2:part_i [2025/04/07 07:49] (current)
bmonsuez [Question n° 1.1]
Line 28: Line 28:
 Ajouter les fonctions membres (méthodes) ''​decrement()''​ et ''​print()''​. Indiquer si ces méthodes modifient les champs de l'​objet ou pas en ajoutant le qualificateur ''​const''​. Ajouter les fonctions membres (méthodes) ''​decrement()''​ et ''​print()''​. Indiquer si ces méthodes modifient les champs de l'​objet ou pas en ajoutant le qualificateur ''​const''​.
  
-<nodisp ​Correction>​ +<hidden ​Correction>​ 
-</nodisp>+ 
 +<code cpp> 
 +class MyCounter 
 +
 +    protected:​ 
 +        int _counter; 
 +        int _max; 
 + 
 +    public: 
 +        MyCounter():​ _counter(0),​ _max(0) {} 
 +        explicit MyCounter(int theMaxValue):​ _counter(0),​ _max(theMaxValue) {} 
 +        MyCounter(int theCounterValue,​ int theMaxValue):​ 
 +            _counter(0),​ _max(theMaxValue)  
 +            {} 
 +        MyCounter(const MyCounter&​ anotherCounter):​  
 +            _counter(anotherCounter._counter),​  
 +            _max(anotherCounter._max)  
 +            {} 
 + 
 +        int getCounter() const { return _counter; } 
 +        int getMax() const { return _max; } 
 + 
 +        void increment()  
 +        { 
 +            _counter = _counter < _max ? _counter + 1 : 0; 
 +        } 
 +}; 
 + 
 +class MyBiDiCounter:​ public MyCounter 
 +
 +    public: 
 +        void decrement() 
 +        { 
 +            _counter = _counter > 0 ? _counter -1 : _max; 
 +        } 
 + 
 +        void print() 
 +        { 
 +            std::cout << "​("​ << _counter << "/" << _max << "​)"​ << std::​endl;​ 
 +        } 
 +}; 
 +</code> 
 + 
 +</​hidden>​ 
 + 
 ==== Question n° 1.2 ==== ==== Question n° 1.2 ====
  
in202/seance_2/td_2/part_i.1618148813.txt.gz · Last modified: 2021/04/11 13:46 by bmonsuez