fork download
  1. //Cameron Pham CS1A Chapter 10, p. 590, #11
  2. /*******************************************************************************
  3.  * CONVERT STRING CASE
  4.  * _____________________________________________________________________________
  5.  * This program displays a string entered by the user with the case of its
  6.  * letters swapped, then in all lowercase, and then in all uppercase.
  7.  * _____________________________________________________________________________
  8.  * INPUTS
  9.  * Text // String entered by the user
  10.  *
  11.  * OUTPUTS
  12.  * Text // The string after each case conversion
  13.  ******************************************************************************/
  14.  
  15. #include <iostream>
  16. #include <cctype>
  17. using namespace std;
  18.  
  19. // Function prototypes
  20. void upper(char *str);
  21. void lower(char *str);
  22. void reverse(char *str);
  23.  
  24. int main()
  25. {
  26. const int SIZE = 256; // Size of the character array
  27. char text[SIZE] = ""; // INPUT/OUTPUT - String entered by the user
  28. // Get a string from the user
  29. cout << "Enter a string: ";
  30. cin.getline(text, SIZE);
  31. // Swap the case of each letter
  32. reverse(text);
  33. cout << "Reversed case: " << text << endl;
  34. // Convert every letter to lowercase
  35. lower(text);
  36. cout << "Lowercase: " << text << endl;
  37. // Convert every letter to uppercase
  38. upper(text);
  39. cout << "Uppercase: " << text << endl;
  40. return 0;
  41. }
  42. void upper(char *str)
  43. {
  44. // Convert each character to uppercase
  45. while (*str != '\0')
  46. {
  47. *str = toupper(*str);
  48. str++;
  49. }
  50. }
  51. void lower(char *str)
  52. {
  53. // Convert each character to lowercase
  54. while (*str != '\0')
  55. {
  56. *str = tolower(*str);
  57. str++;
  58. }
  59. }
  60. void reverse(char *str)
  61. {
  62. // Swap the case of each letter
  63. while (*str != '\0')
  64. {
  65. if (isupper(*str))
  66. {
  67. *str = tolower(*str);
  68. }
  69. else if (islower(*str))
  70. {
  71. *str = toupper(*str);
  72. }
  73. str++;
  74. }
  75. }
Success #stdin #stdout 0s 544KB
stdin
i'm so bombastically tired of writing this code!!!!!!!!!!!!
stdout
Enter a string: Reversed case: I'M SO BOMBASTICALLY TIRED OF WRITING THIS CODE!!!!!!!!!!!!
Lowercase:     i'm so bombastically tired of writing this code!!!!!!!!!!!!
Uppercase:     I'M SO BOMBASTICALLY TIRED OF WRITING THIS CODE!!!!!!!!!!!!