Answer:
#include<iostream>
using namespace std;
//method to remove the spaces and convert the first character of each word to uppercase
string
toUpperCameICase (string str)
{
string result;
int i, j;
//loop will continue till end
for (i = 0, j = 0; str[i] != '\0'; i++)
{
if (i == 0) //condition to convert the first character into uppercase
{
if (str[i] >= 'a' && str[i] <= 'z') //condition for lowercase
str[i] = str[i] - 32; //convert to uppercase
}
if (str[i] == ' ') //condition for space
if (str[i + 1] >= 'a' && str[i + 1] <= 'z') //condition to check whether the character after space is lowercase or not
str[i + 1] = str[i + 1] - 32; //convert into uppercase
if (str[i] != ' ') //condition for non sppace character
{
result = result + str[i]; //append the non space character into string
}
}
//return the string
return (result);
}
//driver program
int main ()
{
string str;
char ch;
//infinite loop
while (1)
{
fflush (stdin);
//cout<< endl;
getline (cin, str); //read the string
//print the result
//cout<< endl << "Q";
// cin >> ch; //ask user to continue or not
ch = str[0];
if (ch == 'q' || ch == 'Q') //is user will enter Q then terminatethe loop
break;
cout << toUpperCameICase (str);
cout << endl;
}
return 0;
}