This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
in204:tds:sujets:td1:main [2019/09/19 11:44] 77.194.42.247 |
— (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== TD1 : Introduction aux objets ====== | ||
| - | |||
| - | {{ :in204:1-_in204_-_td1_-_premiers_pas_avec_les_objets.pdf |Format Pdf}} | ||
| - | |||
| - | ===== Partie I – Création du compteur en C++ ===== | ||
| - | |||
| - | |||
| - | ==== Question n° 0 ==== | ||
| - | |||
| - | Lancer votre environnement de développement préféré. | ||
| - | Question n°1 : Créer un ensemble de fichier counter.cpp et conter.hpp pour définir votre classe de base « MyCounter ». Au départ, seul le fichier counter.hpp contient le code suivant : | ||
| - | |||
| - | <code cpp> | ||
| - | struct MyCounter | ||
| - | { | ||
| - | unsigned counter; | ||
| - | unsigned max; | ||
| - | |||
| - | unsigned getCounter() const { | ||
| - | return counter; | ||
| - | } | ||
| - | unsigned getMax() const { | ||
| - | return max; | ||
| - | } | ||
| - | |||
| - | void increment() { | ||
| - | counter ++; | ||
| - | if(counter > max) | ||
| - | counter = 0; | ||
| - | } | ||
| - | |||
| - | void reset() { | ||
| - | counter = 0; | ||
| - | } | ||
| - | |||
| - | void set(unsigned value) { | ||
| - | counter = (value <= max) ? value : counter; | ||
| - | } | ||
| - | |||
| - | void setMax(unsigned value) { | ||
| - | if(counter >= value) | ||
| - | counter = 0; | ||
| - | max = value;; | ||
| - | } | ||
| - | |||
| - | MyCounter() | ||
| - | { | ||
| - | counter = 0; | ||
| - | max = value ; | ||
| - | } | ||
| - | } | ||
| - | </code> | ||