fork download
  1. // Andres Guzman CSC5 Chapter 10, P. 589, #5
  2. /******************************************************************************
  3.  *
  4.  * CAPITALIZE SENTENCE BEGINNINGS
  5.  * ____________________________________________________________________________
  6.  * Program function will uppercase the start of each word after the beginning
  7.  * or after a period.
  8.  *
  9.  * Computation:
  10.  *
  11.  * Function will compute using a for loop to step through the subscript of the
  12.  * array, an if statement to determine the start of the array and a else if
  13.  * statement to uppercase the start of each sentence.
  14.  * ____________________________________________________________________________
  15.  *
  16.  * INPUT
  17.  *
  18.  * SIZE = Array size of characters
  19.  * sentence = Entered c-string
  20.  *
  21.  * OUTPUT
  22.  *
  23.  * uppercase = Entered c-string with proper capitalization
  24.  *
  25.  ******************************************************************************/
  26. #include <iostream>
  27. #include <cctype>
  28. using namespace std;
  29.  
  30. void uppercase(char *a);
  31.  
  32. int main()
  33. {
  34. const int SIZE = 1000; //Array Size
  35. char sentence[SIZE]; //Array of characters
  36. //
  37. //Display input prompt
  38. cout << "Type a Sentence with ALL lowercases EXCEPT Names & Places: ";
  39. cin.getline(sentence, SIZE);
  40. uppercase(sentence); //Function Call and output
  41. }
  42. /*******************************************************************************
  43.  * Adding Definition to function. This function will uppercase the start of each
  44.  * sentence using a for loop to step through the array, and then a if and else
  45.  * if statement to determine the start of a sentence.
  46.  ******************************************************************************/
  47. void uppercase(char *a)
  48. {
  49. //
  50. //Initialize for loop to step through array
  51. for(int count = 0; a[count] != '\0'; count++)
  52. {
  53. //
  54. //If statements determines the start of the array
  55. if(count == 0)
  56. a[count] = toupper(a[count]);
  57. //
  58. //Else if statement determines the start of a new sentence
  59. else if(a[count - 1] == '.')
  60. {
  61. int next = count;
  62. //
  63. //Nested while loop skips spaces between period and letter
  64. while(isspace(a[next]))
  65. next++;
  66. a[next] = toupper(a[next]);
  67. }
  68. }
  69. //
  70. //Output sentence
  71. cout << "\nProper Capitalization: " << a << endl;
  72. }
Success #stdin #stdout 0s 544KB
stdin
hello there
stdout
Type a Sentence with ALL lowercases EXCEPT Names & Places: 
Proper Capalization: Hello there