// Andres Guzman CSC5 Chapter 10, P. 589, #5
/******************************************************************************
*
* CAPITALIZE SENTENCE BEGINNINGS
* ____________________________________________________________________________
* Program function will uppercase the start of each word after the beginning
* or after a period.
*
* Computation:
*
* Function will compute using a for loop to step through the subscript of the
* array, an if statement to determine the start of the array and a else if
* statement to uppercase the start of each sentence.
* ____________________________________________________________________________
*
* INPUT
*
* SIZE = Array size of characters
* sentence = Entered c-string
*
* OUTPUT
*
* uppercase = Entered c-string with proper capitalization
*
******************************************************************************/
#include <iostream>
#include <cctype>
using namespace std;
void uppercase(char *a);
int main()
{
const int SIZE = 1000; //Array Size
char sentence[SIZE]; //Array of characters
//
//Display input prompt
cout << "Type a Sentence with ALL lowercases EXCEPT Names & Places: ";
cin.getline(sentence, SIZE);
uppercase(sentence); //Function Call and output
}
/*******************************************************************************
* Adding Definition to function. This function will uppercase the start of each
* sentence using a for loop to step through the array, and then a if and else
* if statement to determine the start of a sentence.
******************************************************************************/
void uppercase(char *a)
{
//
//Initialize for loop to step through array
for(int count = 0; a[count] != '\0'; count++)
{
//
//If statements determines the start of the array
if(count == 0)
a[count] = toupper(a[count]);
//
//Else if statement determines the start of a new sentence
else if(a[count - 1] == '.')
{
int next = count;
//
//Nested while loop skips spaces between period and letter
while(isspace(a[next]))
next++;
a[next] = toupper(a[next]);
}
}
//
//Output sentence
cout << "\nProper Capitalization: " << a << endl;
}