fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <ctype.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int i;
  10. string first = "Bart";
  11. string last = "Simpson";
  12. string both = first + " " + last;
  13.  
  14. // print out the original name first
  15.  
  16. cout << both << endl;
  17.  
  18. // invert capitalization (small to big, big to small)
  19.  
  20. for (i=0; i<both.size(); i++)
  21. if (isupper(both[i]))
  22. both[i] = tolower(both[i]);
  23. else
  24. if (islower(both[i]))
  25. both[i] = toupper(both[i]);
  26.  
  27. // print the result out
  28.  
  29. cout << both << endl;
  30.  
  31. // capitalize each character
  32.  
  33. for (i=0; i<both.size(); i++)
  34. both[i] = toupper(both[i]);
  35.  
  36. // print the result out
  37.  
  38. cout << both << endl;
  39.  
  40. // make each character lower case
  41.  
  42. for (i=0; i<both.size(); i++)
  43. both[i] = tolower(both[i]);
  44.  
  45. // print the result out
  46.  
  47. cout << both << endl;
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 2860KB
stdin
Standard input is empty
stdout
Bart Simpson
bART sIMPSON
BART SIMPSON
bart simpson