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
What finger should be on the Y key?
geniusboy [140]

Answer:

Right index

Explanation:

6 0
3 years ago
Read 2 more answers
HELP asap please... ​
Usimov [2.4K]

Answer:

I have absolutely no idea bruddah.

Explanation:

Soz!

8 0
3 years ago
What is the disadvantage of a mesh topology?
-BARSIC- [3]

Answer:

Topology means arrangement of nodes

Explanation:

In computer science the word topology means the arrangement of nodes and elements in a network. For any topology we do need nodes and cables for maintaining the infrastructure.

In mesh topology the all nodes use to get connected by direct link. While each and every node is directly associated with  one another. In this infrastructure we do need lot cabling where every node will be connected with one another. While usage of good quality cable in network is  also expensive to manage. Although there are lot of benefits of this topology, where the transmission of data would never stop if node is not working the rest will be working to transfer the data among other nodes ,this is more secure because there is no traffic for data to travel via many nodes   to reach the destination. Every node is directly connected and communicate. So, once the node is not working the communication will not be stop but the maintenance and troubleshooting will be difficult in this infrastructure.

It is proved along with lot of benefits and network security ,this infrastructure is having some disadvantages as well. Cabling expense , maintenance cost etc  . usually small scale networks do not prefer mesh topology.  Small scale and low budget companies can  not afford this topology because it is expensive.

Although we do believe that the data security is most important for today's era ,so few companies those wanted to keep their information secure and confidential they must use mesh topology by ignoring the cost incurred for this set up. Data security and integrity would never be compromised by some of the companies.

Mesh topology is more safer, more quick infrastructure which is although very expensive , difficult to mange and maintain. Moreover it is overhead of cabling as well to connect every node but the demand of mesh topology would never be less. It is demanding and appealing topology still.

7 0
3 years ago
Read 2 more answers
Which range of values would result in 10 elements stored in an array?
Paraphin [41]

Answer:

0-9

Explanation:

count 0 as 1

len(0,1,2,3,4,5,6,7,8,9)=10

3 0
3 years ago
What is a quasi vpn?
Natasha2012 [34]

Answer:

i don't think there is such thing as a quasi vpn

Explanation:

6 0
3 years ago
Other questions:
  • If you wanted to create a graph that showed how much each value contributed to the whole value, you would use a _____.
    15·2 answers
  • Which type of appliance can host several functions, such as antimalware, firewall, content filter, and proxy server
    11·1 answer
  • Write an algorithm that accepts two numbers,
    7·1 answer
  • Technological advances have made cyberbullying
    5·1 answer
  • The information given to you by your teachers is always accurate and should never be questioned. Please select the best answer f
    8·1 answer
  • Jonathan is in the process of creating a photo of a fluttering flag with cars moving around in the background. He wants the flag
    13·2 answers
  • The hexadecimal eqquivalent of (80)10 is
    11·1 answer
  • How can i setup a mesage room and also want to hangout ??????
    10·1 answer
  • What do hard disk drive use to store data
    10·1 answer
  • Which of the following offers a combination of the features of ram and rom?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!