HRusev

4. Some Ordering

May 29th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. void printLowerOrUppreCase(string* str, bool(*caseProcesses)(char&))
  9. {
  10.    
  11.     char ch;
  12.     for (int i = 0; i < str->length(); i++)
  13.     {
  14.         ch = str->at(i);
  15.         if (caseProcesses(ch))
  16.             str->replace(i, 1, 1, ch);
  17.     }
  18.     cout << str[0];
  19. }
  20.  
  21.  
  22. bool lowerCase(char& ch)
  23. {
  24.     if (ch >= 'A' && ch <= 'Z')
  25.     {
  26.         ch += 32;
  27.         return true;
  28.     }
  29.     return false;
  30. }
  31.  
  32. bool upperCase(char& ch)
  33. {
  34.     if (ch >= 'a' && ch <= 'z')
  35.     {
  36.         ch -= 32;
  37.         return true;
  38.     }
  39.     return false;
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. int main()
  47. {
  48.     string input;
  49.     getline(cin, input);
  50.     string copy = input;
  51.  
  52.  
  53.    
  54.     printLowerOrUppreCase(&copy, lowerCase);
  55.     cout << endl;
  56.     printLowerOrUppreCase(&input, upperCase);
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment