2.1.6.2 : Les sources
Écrivons le fichier accord_shadok.cppnoteNous allons juste ajouter un s à un mot si il doit être au pluriel :Nous commençons à inclure notre header :
1 |
#include "accord_shadok.h"
|
Maintenant la fonction qui accorde un nom qui lui est donné en fonction de la quantité passée :
1 2 3 4 5 6 |
///Accord a word by respect of its quantity /** @param name : name to be accored (or chord) * @param nbName : number of name * @return accorded string (with a 's' if necessary) */ std::string accord_shadok(const std::string & name, size_t nbName){ |
Si nbName est inférieure ou égale à 1, nous ne changeons rien, sinon nous ajoutons un 's' :
1 2 3 4 5 |
if(nbName <= 1lu){ return name; }else{ return name + "s"; } |
Enfin, nous fermons la fonction :
1 |
} |
Le fichier accord_shadok.cpp complet :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
/*************************************** Auteur : Pierre Aubert Mail : pierre.aubert@lapp.in2p3.fr Licence : CeCILL-C ****************************************/ #include "accord_shadok.h" ///Accord a word by respect of its quantity /** @param name : name to be accored (or chord) * @param nbName : number of name * @return accorded string (with a 's' if necessary) */ std::string accord_shadok(const std::string & name, size_t nbName){ if(nbName <= 1lu){ return name; }else{ return name + "s"; } } |
Vous pouvez le télécharger ici.