Advertisement
VictoriaLodochkina

MaxWZ

Apr 2nd, 2021
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. class Lettercount {
  9. private:
  10.     string str;
  11. public:
  12.     Lettercount() {};
  13.     Lettercount(string stroka) : str(stroka) {};
  14.     int count() {
  15.         int letter_count = 0;
  16.         string str_cop(str);
  17.         transform(str_cop.begin(), str_cop.end(), str_cop.begin(), ::toupper);
  18.         for (int i = 0; i < str_cop.length(); i++) {
  19.             if (isalpha(str_cop[i])) {
  20.                 letter_count++;
  21.             }
  22.             if ((int(str_cop[i]) >= 'А' && int(str_cop[i]) <= 'Я') || (int(str_cop[i]) == 'Ё'))
  23.             {
  24.                 letter_count++;
  25.             }
  26.         }
  27.         return letter_count;
  28.     }
  29. };
  30.  
  31. int main()
  32. {
  33.     setlocale(LC_ALL, "Russian");
  34.     SetConsoleCP(1251);
  35.     SetConsoleOutputCP(1251);
  36.     string your_stroka;
  37.     cout << "Enter the string: ";
  38.     cin >> your_stroka;
  39.     Lettercount obj(your_stroka);
  40.     cout << "Your result: " << obj.count();
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement