fork download
  1. //ANDREW ALSPAUGH CS1A Chapter 10. P. 589 #5
  2. //
  3. /****************************************************************************
  4. Correct Sentence Capitalization
  5. ___________________________________________________________________________
  6. This program displays a string that capitalizes the first letter of each
  7. sentence.
  8. ___________________________________________________________________________
  9. //Input
  10. const int SIZE = 100;
  11. char string[SIZE];
  12.  
  13. //Output
  14. bool capNext = true;
  15. ****************************************************************************/
  16. #include <iostream>
  17. #include <cstring>
  18. using namespace std;
  19.  
  20. void CapString(char *string, const int SIZE, bool capNext);
  21.  
  22. int main()
  23. {
  24. //DATA DICTIONARY
  25.  
  26. //Input
  27. const int SIZE = 100;
  28. char string[SIZE];
  29.  
  30. //Output
  31. bool capNext = true;
  32.  
  33. //INPUT
  34. cin.getline (string, SIZE);
  35.  
  36. //PROCESS
  37. CapString (string, SIZE, capNext);
  38.  
  39. //OUTPUT
  40. cout << string;
  41.  
  42. return 0;
  43. }
  44.  
  45. void CapString(char *string, const int SIZE, bool capNext)
  46. {
  47. for (int i = 0; string[i] != '\0'; i++)
  48. {
  49. if(capNext && isalpha(string[i]))
  50. {
  51. string[i] = toupper(string[i]);
  52. capNext = false;
  53. }
  54.  
  55. if (string[i] == '.' || string[i] == '!' || string[i] == '?')
  56. capNext = true;
  57. }
  58. }
Success #stdin #stdout 0.01s 5288KB
stdin
hello. My name is Joe. what is your name?
stdout
Hello. My name is Joe. What is your name?