Witam. Przyszedł mi do głowy pomysł skonstruowania prostych wyrażeń regularnych dla każdej oceny, oto kod do testów:
#include <iostream>
#include <regex>
std::regex ocenyR[11] = { std::regex("1|ndst|niedostateczny"), std::regex("2|dop|dopuszczajacy"),
std::regex("2\\+|dop\\+|dopuszczajacy\\+"), std::regex("3\\-|dop\\-|dopuszczajacy\\-"),
std::regex("3|dop|dostateczny"), std::regex("3\\+|dop\\+|dostateczny\\+"),
std::regex("4\\-|db\\-|dobry\\-"), std::regex("4|db|dobry"),
std::regex("4\\+|db\\+|dobry\\+"), std::regex("5\\-|brb\\-|bardzo dobry\\-"),
std::regex("5|brb|bardzo dobry"), };
double oceny[11] = { 1, 2, 2.5, 2.75, 3, 3.5, 3.75, 4, 4.5, 4.75, 5 };
int main()
{
std::string ocena;
std::cout << "Podaj jaka chcesz ocene: ";
std::getline(std::cin, ocena);
for (int i = 0; i < 11; i++) {
if (std::regex_match(ocena, ocenyR[i])) {
std::cout << "Ocena to " << oceny[i];
return 0;
}
}
std::cout << "Zle znaki na wejsciu!";
return 0;
}
Łatwo można ten kod rozszerzyć o inne sposoby podawania ocen, edytując tablicę regexów :P
Biblioteka <regex>:
http://www.cplusplus.com/reference/regex/
Zasady działania wyrażeń regularnych:
http://www.cplusplus.com/reference/regex/ECMAScript/