Create and debug this program in Visual C++. Upload your Source.cpp file for tes
ID: 3602763 • Letter: C
Question
Create and debug this program in Visual C++. Upload your Source.cpp file for testing.
(1) Prompt the user to enter a string of their choosing. Output the string. (1 pt)
Ex:
(2) (2 pts) Write a function:
This function should NOT print anything.
*Note: A tab is ' '.
(3) In main(), call the CountWhitespace() function and then output the returned result. (1 pt)
(4) Implement a function:
Call the OutputWithoutWhitespace() function in main(), after printing out "String with no whitespace: " as shown below. (2 pts)
Ex:
Explanation / Answer
Here is the code given for the following question:
#include<iostream>
#include<string>
#include <cctype>
using namespace std;
void OutputWithoutWhitespace(string mystring) \calling for removing white space
{
int count=0; \initialize count
for (int i = 0; mystring[i]; i++)
if (mystring[i] != ' ')
mystring[count++] = mystring[i];
mystring[count] = '';
}
int CountWhitespace(string mystring) \ to count whitespace
{
int len, i, count=0;
len = mystring.size();
for(i=0;i<len;i++)
{
if(mystring[i]==' ')
{
count++;
}
}
return (count);
}
int main()
{
string mystring;
int count=0;
cout << "Enter a sentence or phrase:" << " ";
getline(cin,mystring);
cout << "You entered:" << mystring << " " << endl;
getline(cin,mystring);
CountWhitespace(mystring);
cout << "Whitespace count:" << count << endl;
OutputWithoutWhitespace(mystring);
cout << "string with no whitespace" << mystring;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.