Advertisement
informaticage

Is string uppercase c++ BRIBRO

Dec 30th, 2020
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1.  
  2. // Prendevo una stringa di caratteri tipo una frase
  3. // Returna true se la stringa è tutta maiuscola, false altrimenti
  4. // Es: Lorem ipsum dolor SIT amet incipit rosae -> false
  5. // Es: LOREM IPSUM DOLOR SIT AMET INCIPIT ROSAE -> true
  6. #include <iostream>
  7. #include <string>
  8.  
  9. bool isCharUppercase(char c) {
  10.     // Se è maiuscolo
  11.     if (c < 65 || c > 90)
  12.         return false;
  13.     return true;
  14. }
  15.  
  16. bool isStringUppercase(std::string s) {
  17.     for(int i = 0; i < s.length(); i++) {
  18.         if(s[i] != ' ' && !isCharUppercase(s[i]))
  19.             return false;
  20.     }
  21.     return true;
  22. }
  23.  
  24.  
  25. int main () {
  26.     using namespace std;
  27.     string s;
  28.  
  29.     getline(cin, s);
  30.     cout << "Ho inserito: " << s << endl;
  31.     cout << isStringUppercase(s) << endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement