Question: bool estNomValide ( const string& p _ nom ) { / / Les caract res valides string validChars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz - ; / /

bool estNomValide(const string& p_nom){
// Les caractres valides
string validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-";
// Vrifiez chaque caractre du nom
for (size_t i =0; i < p_nom.size(); ++i){
char c = p_nom[i];
// Les caractres du mot doivent seulement faire partie de la liste des caractres suivants
if (validChars.find(c)== string::npos){
return false;
}
// Toujours majuscule aprs un tiret ou un espace
if (i >0 && (p_nom[i-1]==''|| p_nom[i-1]=='-') && islower(c)){
return false;
}
}
// Premire lettre en majuscule
if (!isupper(p_nom[0])){
return false;
}
// Le mot doit se terminer seulement par une lettre
if (!isalpha(p_nom[p_nom.size()-1])){
return false;
}
// On ne peut pas avoir 2 tirets conscutifs ou 2 espaces conscutifs
if (p_nom.find("")!= string::npos || p_nom.find("--")!= string::npos){
return false;
}
// On ne peut pas avoir un tiret suivi dun espace ou inversement
if (p_nom.find("-")!= string::npos || p_nom.find("-")!= string::npos){
return false;
}
// Si toutes les conditions sont remplies, renvoyez true
return true;
}
failed:2 test
failed : validerNom.NomValideLongMin
failed : validerNom.NomInvalide ajusculeAuMilieu

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!