Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
need help to develop a C++ program?
Develop a C++ program to:
• read a long character string from the keyboard
• print out the length of the string
• convert all uppercase letters to lower case
• remove all spaces and non-letters from the string
The length of the string is unknown.
Test your program on the following strings (type them in exactly)
A man, a Plan, a Canal – Panama!
Able was I, ere I saw Elba
i don't even know how to start.
1 Answer
- 9 years agoFavorite Answer
To read a line of text from the keyboard, just use cin.getline(). This will allow any length of text typed, and when the user presses the Enter key, you get the line of text.
Just use the STL string class 'std::string', which has a length() function. So, you will know the length of the string.
Converting to lower case is done in a tricky way. see this example:
std::string myStr = "This is a test.";
transform(myStr.begin(), myStr.end(), myStr.begin(), tolower);
To remove not-letter characters, there may be a tricky way to do this. But, a simple way would be as follows:
std::string newStr;
for (int i=0; i<myStr.length(); ++i)
{
char ch = myStr[i];
if (isalpha(ch)) newStr += ch;
}
Now the string newStr has the text with only alphabetic characters.
Source(s): http://www.cplusplus.com/reference/clibrary/cctype... http://www.cplusplus.com/reference/string/string/