Advertisement
TermSpar

String To Upper/Lower Case And Reverse

Nov 5th, 2016
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #define UP_A 65
  5. #define UP_Z 91
  6.  
  7. #define LOW_A 97
  8. #define LOW_Z 122
  9.  
  10. int main() {
  11.  
  12.     std::string word;
  13.     std::string upper;
  14.     std::string lower;
  15.     std::string backwards;
  16.    
  17.     std::cout << "Enter word: ";
  18.     std::cin >> word;
  19.  
  20.     //Lower To Upper:
  21.     for (int i = 0; i < word.length(); i++) {
  22.         if (word.at(i) >= LOW_A && word.at(i) <= LOW_Z) {
  23.             upper += (word.at(i) - 32);
  24.         }
  25.         else {
  26.             upper += word.at(i);
  27.         }
  28.     }
  29.  
  30.     //Upper To Lower:
  31.     for (int i = 0; i < word.length(); i++) {
  32.         if (word.at(i) >= UP_A && word.at(i) <= UP_Z) {
  33.             lower += (word.at(i) + 32);
  34.         }
  35.         else {
  36.             lower += word.at(i);
  37.         }
  38.     }
  39.  
  40.     //Reverse String:
  41.     for (int i = word.length(); i > 0; i--) {
  42.         backwards += word.at(i - 1);
  43.     }
  44.  
  45.     //Print Data:
  46.     std::cout << "Upper: " << upper << "\n";
  47.     std::cout << "Lower: " << lower << "\n";
  48.     std::cout << "Reversed: " << backwards << "\n";
  49.  
  50.     system("PAUSE");
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement