User Tools

Site Tools


in204:tds:sujets:td2:part3

This is an old revision of the document!


Partie III – Surcharge & Masquage

TD2

Nous repartons du code de MyBiDiCounter tel défini à la fin de la question 1 de la partie II.

Question n°1

Ajouter à la classe MyBiDiCounter une nouvelle méthode :

increment(unsigned value)
    si counter + value <= max
        counter <- counter + value
    sinon
        counter = (counter + value) mod max

Correction

Correction

Question n°2

Tester le bon fonctionnement de cette classe à partir du code suivant :

void testNewIncMethod() {
    MyBiDiCounter bidiCounter1(0, 5);
    for(unsigned i = 0; i <= 5; i++) 
    {
	  bidiCounter1.increment(5);
        bidiCounter1.print();
    }
}

Question n°3

Tester le code suivant.

void testOldIncMethod() {
    MyBiDiCounter bidiCounter1(0, 5);
    for(unsigned i = 0; i <= 5; i++) 
    {
        bidiCounter1.increment();
        bidiCounter1.print();
    }
}

Expliquer pourquoi cela ne fonctionne pas ? Proposer une modification de l’appel pour que cela puisse fonctionner.

Correction

Correction

in204/tds/sujets/td2/part3.1600237481.txt.gz · Last modified: 2020/09/16 06:24 by bmonsuez