fork download
  1. //Sam Trivikraman CS1A Chapter 10, p. 589, #5
  2. //
  3. /*
  4.  ******************************************************************************
  5. Capitalize the First Letter
  6. _______________________________________________________________________________
  7. This program capitalizes the first letter of each sentence in a string.
  8. _______________________________________________________________________________
  9. INPUT
  10. the string of words : The sentences contained within a cstring.
  11.  
  12.  
  13. OUTPUT
  14. the capitalized version of the array : The same string, but with the first letter of each starting word capitalized
  15. _______________________________________________________________________________
  16. *******************************************************************************
  17. */
  18. #include <iostream>
  19. using namespace std;
  20.  
  21. //Function that capitalizes the first letter of each starting word
  22. void capital (char sentence[])
  23. {
  24. //iterate through the string and capitalize the correct letters
  25. for(int i = 0; i < 100; i++)
  26. {
  27. if(ispunct(sentence[i]))
  28. {
  29. toupper(sentence[i + 2]);
  30. }
  31.  
  32. }
  33. //output the new string
  34. cout << sentence << endl;
  35. }
  36.  
  37. int main() {
  38.  
  39. char words[100]; //INPUT The sentences contained within a cstring
  40.  
  41. //Ask the user for a string of sentences
  42. cout << "Please enter a string: " << endl;
  43. cin >> words;
  44. //call the capitalization function
  45. capital(words);
  46. return 0;
  47. }
Success #stdin #stdout 0s 5284KB
stdin
hello. my name is
stdout
Please enter a string: 
hello.