This is in c++ 1. Prompt the user to enter a string of their choosing and output the string. 2. Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. Encouraged to use a for loop. 3. In main(), call the GetNumOfCharacters() function and then output the returned result. 4. Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main(). My issue is deleting the spaces. I googled how to delete spaces, but there are terms I haven't learned yet. I'm not sure how to delete the spaces. This is what I have: #include #include using namespace std; //Returns the number of characters in usrStr int GetNumOfCharacters(const string usrStr) { int count = 0; unsigned int i; for (i = 0; i < usrStr.size(); ++i) { ++count; } return count; } void OutputWithoutWhitespace(string usrStr) { unsigned int i; for (i = 0; i < usrStr.size(); ++i) { if ((usrStr.at(i) == ' ') | (usrStr.at(i) == '\t')) { usrStr.at(i) = '\0'; } } } int main() { string userInput; cout << "Enter a sentence or phrase:" << endl << endl; getline(cin, userInput); cout << "You entered: " << userInput << endl << endl; cout << "Number of characters: " << GetNumOfCharacters(userInput) << endl; OutputWithoutWhitespace(userInput); cout << "String with no whitespeace: " << userInput; return 0; }
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
This is in c++
1. Prompt the user to enter a string of their choosing and output the string.
2. Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. Encouraged to use a for loop.
3. In main(), call the GetNumOfCharacters() function and then output the returned result.
4. Implement the OutputWithoutWhitespace() function. OutputWithoutWhitespace() outputs the string's characters except for whitespace (spaces, tabs). Note: A tab is '\t'. Call the OutputWithoutWhitespace() function in main().
My issue is deleting the spaces. I googled how to delete spaces, but there are terms I haven't learned yet. I'm not sure how to delete the spaces.
This is what I have:
#include <iostream>
#include <string>
using namespace std;
//Returns the number of characters in usrStr
int GetNumOfCharacters(const string usrStr) {
int count = 0;
unsigned int i;
for (i = 0; i < usrStr.size(); ++i) {
++count;
}
return count;
}
void OutputWithoutWhitespace(string usrStr) {
unsigned int i;
for (i = 0; i < usrStr.size(); ++i) {
if ((usrStr.at(i) == ' ') | (usrStr.at(i) == '\t')) {
usrStr.at(i) = '\0';
}
}
}
int main() {
string userInput;
cout << "Enter a sentence or phrase:" << endl << endl;
getline(cin, userInput);
cout << "You entered: " << userInput << endl << endl;
cout << "Number of characters: " << GetNumOfCharacters(userInput) << endl;
OutputWithoutWhitespace(userInput);
cout << "String with no whitespeace: " << userInput;
return 0;
}
Thank you.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images