1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
skad [1K]
3 years ago
8

Prompt the user to enter a string of their choosing. Output the string. (1 pt) Ex: Enter a sentence or phrase: The only thing we

have to fear is fear itself. You entered: The only thing we have to fear is fear itself.(2) Complete the GetNumOfCharacters() function, which returns the number of characters in the user's string. We encourage you to use a for loop in this function. (2 pts)(3) In main(), call the GetNumOfCharacters() function and then output the returned result. (1 pt)(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(). (2 pts) Ex: Enter a sentence or phrase: The only thing we have to fear is fear itself. You entered: The only thing we have to fear is fear itself. Number of characters: 46 String with no whitespace: Theonlythingwehavetofearisfearitself.'--------------------------------------------------------------- C++ --------------------- C++ -------------------------- C++-----------------------------------------This is what I have so far:#include #include using namespace std;//Returns the number of characters in usrStrint GetNumOfCharacters(int usrStr) {userCount = usrStr.length();return userCount;}const OutputWithoutWhiteSpaces(string& usrStr) {string text;text = text.replace(" ","");return text;}int main() {string usrStr;cout << "Enter a sentence or phrase: ";getline(cin, usrStr);cout << "You entered: " << usrStr << endl;int count = GetNumOfCharacters();cout << "Number of characters: " << count << endl;cout << "String with no whitespace: " << OutputWithoutWhitespace() << endl;return 0;}
Computers and Technology
1 answer:
frosja888 [35]3 years ago
7 0

Answer:

Explanation:

Section 1) Enter String and Output String

#include<iostream> //for input and output  

#include <string>  // for string  

using namespace std;  

int main()  

{  

   string sentense;

   cout<<"Enter a sentence or phrase: ";

  getline(cin,sentense);

  cout<<"You Entered :"<<sentense;

   return 0;  

}

Output

Enter a sentence or phrase: The only thing we have to fear is fear itself

You Entered :The only thing we have to fear is fear itself

Explanation

To get full sentence or phrase, we need to call getline function in string package which will get the overall entered string. cin will not get the whole sentence

Section 2) GetNumOfCharacters

int getNumberOfCharacters(string sentence){

int count =0;

for(int i=0; i<sentence.size(); i++){

 count++;

}

return count;

}

Explanation

As we have taken sentence as string in previous section, we need to count total number of characters in the input string. for that purpose we are iterating over all the characters within string through for loop. declaring count variable and initializing it with 0 and increment on every for loop iteration. at the end returning the count variable.

Section 3) Call the GetNumOfCharacters() in main method.

int main()  

{  

   string sentence;

   cout<<"Enter a sentence or phrase: ";

  getline(cin,sentence);

  cout<< getNumberOfCharacters(sentence);  //Here we call out method and output its value

   return 0;  

}

Explanation

In main method first we get the sentence with getline and then by using cout and calling the getNumberOfCharacters(sentence) function it will show the number of characters in string.

Output

Enter a sentence or phrase: The only thing we have to fear is fear itself

45

Section 4) Implement OutputWithoutWhitespace() function

#include<iostream> //for input and output  

#include <string>  // for string  

using namespace std;  

int getNumberOfCharacters(string sentence){

int count =0;

for(int i=0; i<sentence.size(); i++){

 count++;

}

return count;

}

void OutputWithoutWhitespace(string sentence){

string output="";

 for(int i=0; i<sentence.size(); i++){

 if(sentence[i]!=' ' && sentence[i] != '\t'){  // checking the tab and spaces

  output+=sentence[i];  //then add that into output string

 }

}

cout<< output;

}

int main()  

{  

   string sentence;

   cout<<"Enter a sentence or phrase: ";

  getline(cin,sentence);

  OutputWithoutWhitespace(sentence);

   return 0;  

}  

Code Explanation

In OutputWithoutWhitespace() function we get string as a parameter and iterating all the characters and if current iteration character from sentence string is not equal to tab('\t') and space then add that character into output string. After the loop is finished, output the result.

Output

Enter a sentence or phrase: The only thing we have to fear is fear itself       hello

Theonlythingwehavetofearisfearitselfhello

You might be interested in
Dana downloads music into her computers random access memory, or ram, without authorization. this is?
lilavasa [31]
This is copyright infringement.
7 0
3 years ago
I Previous
Tcecarenko [31]

Answer:

D. Change the def to def area (width, height = 12)

Explanation:

Required

Update the function to set height to 12 when height is not passed

To do this, we simply update the def function to:

def area (width, height = 12)

So:

In boxlarea = area (5,2), the area will be calculated as:

area = 5 * 2 = 10

In box2area = area (6), where height is not passed, the area will be calculated as:

area = 6 * 12 = 72

5 0
2 years ago
Write the definition of a function isSenior, that receives an integer parameter and returns true if the parameter's value is gre
ohaa [14]

Answer:

The function definition for this question can be given as:

Function Definition:

bool isSenior(int x )  //function

{  

//function body Or function definition.

//conditional statement

//if statement

if (x >=65)  

{

return true;   //return value true.

}

else  //else statement

{

return false;    //return value false.

}

}

Explanation:

In the above function definition firstly we define a function that isSenior. This function return Boolean value that is true or false in this function we pass the value as the parameter in that function we use the if statement that check the pass value is greater then equal to 65. If the condition is true it return true.else it will return false.

6 0
3 years ago
What are the main types of reading tools? Check all that apply. please HELP​
vovangra [49]

Answer:

Comprehension

reference

3 0
2 years ago
How should your fingers rest upon the home row keys?
xxTIMURxx [149]

Answer:

Your left index finger should rest on the "f" key which can be found easily by using your touching senses because there is a bump on the "f" , and the "j" Key your right index finger should rest on the "j" Key, Your thumbs can rest on the space bar

7 0
2 years ago
Other questions:
  • Kendra needs to configure a visual alert for an appointment that she is creating for next week. What should she configure?
    11·1 answer
  • What is life all about?
    15·2 answers
  • What command would you issue from a command prompt to see a listing of the computers in your workgroup?
    11·1 answer
  • Playstation network live updates pes 2018 does it cost extra
    13·1 answer
  • The study of a current business and information system application and the definition of user requirements and priorities for a
    5·1 answer
  • Sean works for a company that ships hospital equipment. He needs to calculate the weight of the items being shipped. He enters t
    12·1 answer
  • What is malware? a type of virus that spreads through a network connection a type of virus that targets programs and files any p
    8·1 answer
  • PLEASE HELP I HAVE A TEST RIGHT NOW!!!
    13·1 answer
  • Alguien porfavor me dice como cambiar de idioma en brainly
    15·1 answer
  • Why do relational databases use primary keys and foreign keys?.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!