fork(1) 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.  
  10. ****************************************************************************/
  11. #include <iostream>
  12. #include <cstring>
  13. using namespace std;
  14.  
  15. void CapString(char *string, const int SIZE, bool capNext);
  16.  
  17. int main()
  18. {
  19. //DATA DICTIONARY
  20.  
  21. //Input
  22. const int SIZE = 100;
  23. char string[SIZE];
  24.  
  25. //Output
  26. bool capNext = true;
  27.  
  28. //INPUT
  29. cin.getline (string, SIZE);
  30.  
  31. //PROCESS
  32. CapString (string, SIZE, capNext);
  33.  
  34. //OUTPUT
  35. cout << string;
  36.  
  37. return 0;
  38. }
  39.  
  40. void CapString(char *string, const int SIZE, bool capNext)
  41. {
  42. for (int i = 0; string[i] != '\0'; i++)
  43. {
  44. if(capNext && isalpha(string[i]))
  45. {
  46. string[i] = toupper(string[i]);
  47. capNext = false;
  48. }
  49.  
  50. if (string[i] == '.' || string[i] == '!' || string[i] == '?')
  51. capNext = true;
  52. }
  53. }
Success #stdin #stdout 0s 5320KB
stdin
hello. My name is Joe. what is your name?
stdout
Hello. My name is Joe. What is your name?