Question

Using C++ programming. Write a program that takes a string of input from the user and...

Using C++ programming. Write a program that takes a string of input from the user and separates the string of words based on the premise that the string contains words whose first letter is uppercase. Then, display the phrase (or sentence) to a string in which the words are separated by spaces and only the first word of the phrase starts with an uppercase letter. For example, if the user enters "IAmTheTeacher", then the program would display: "I am the teacher" on the screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include<iostream>
using namespace std;

int main()
{
string str,outputStr;
int i;

cout<<"Enter a string: ";
cin>>str;

for(i=0;i<str.length();i++)
{
if(str[i]>='A' && str[i]<='Z')
{
if(i!=0)
outputStr=outputStr+" ";

outputStr=outputStr+str[i];
}
else
{
outputStr=outputStr+str[i];
}
}

cout<<outputStr;
return 0;
}

Output:

OR

#include<iostream>
using namespace std;

int main()
{
string str;
int i;

cout<<"Enter a string: ";
cin>>str;

cout<<"Output String: ";
for(i=0;i<str.length();i++)
{
if(str[i]>='A' && str[i]<='Z')
{
if(i!=0)
cout<<" ";

cout<<str[i];

}
else
{
cout<<str[i];
}
}

return 0;
}

Add a comment
Know the answer?
Add Answer to:
Using C++ programming. Write a program that takes a string of input from the user and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT