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]
4 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]4 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
How do you delete your brainly account
Artyom0805 [142]

Answer:

moderators only can banned you and delete all

5 0
3 years ago
Question 4: What will be the output of the code? Show a complete analysis.
Eva8 [605]

Answer:

The output of the code is 8

4 0
4 years ago
The Hazard Communication Standard, commonly called the “Right-to-Know” law, gives you the right to know what information?
AlladinOne [14]
The answer to your question is D, OSHA requires employers to let employees of any hazardous chemicals exposed,or not.
7 0
3 years ago
Read 2 more answers
Pleaseee helpppppppppp
zloy xaker [14]

Answer:

EXAMPLE -

Create a variable and assign your age

var myage = 32;

type your age:

console.log(my age) ;

Notice that we did not type the actual numeric age. We used the variable instead. There wouldn’t be any purpose of declaring a variable if we were going to type 32 directly.

This makes the scrip more portable which means that the result on the screen is independent of the code console.log(myAge); . If we need to change our age all we have to do is to assign another number to the variable myAge and the output will change automatically. That’s the purpose of a variable.

5 0
3 years ago
What is the specifications, number of sales, positive and negative points and a few popular games of the first PlayStation?
Semmy [17]
Specs:
CPU
R3000A 32bit RISC chip @ 33.8mhz - Manufactured by LSI Logic Corp.
Clearing capacity: 30 MIPS
Bus bandwidth: 132 Mb/sec

3D Geometry Engine
High speed matrix calculator
Clearing capacity: 66 MIPS
1.5 million flat-shaded polygons/sec
500,000 texture-mapped and light-sourced polygons/sec

Data Engine (MDEC)
Clearing capacity: 80 MIPS
CPU, direct bus connection
Also compatible with JPEG, H.261 files

Sound
ADPCM, 24 channels
Sampling frequency: 44.1 Khz

Graphics
16.7 million colors
Resolution: 256x224 - 740x480
Sprite/BG drawing
Adjustable frame buffer
No line restriction
Unlimited CLUTs (Color Look-Up Tables)
4,000 8x8 pixel sprites with individual scaling and rotation
Simultaneous backgrounds (Parallax scrolling)
360,000 polygons/sec

Memory:
Main RAM: 2 Megabytes
VRAM: 1 Megabyte
Sound RAM: 512 K
CD-ROM buffer: 32K
Operating System ROM: 512K
RAM cards for data save: 128K EEprom

Cd-rom
Double speed
<span>XA compliant
</span>
Number of sales: 102.49 million

Pros: Great game selection. Fantastic 3D graphics for the time, elegant console design, memory cards convenient and meant never running out of space and could play saved games on another console. Comfortable controllers, games stored in standard CD cases.

Cons: Long load times. <span>Often overheated which would cause audio skipping, even longer load times, and sometimes system failure! </span><span>Memory cards don't hold much.</span>

Games: Ridge Racer, Battle Arena Toshinden, and ESPN Extreme Games. on release. Later Spyro the Dragon, Tekken, Wipeout, Crash Bandicoot, Tomb Raider, Metal Gear Solid, Gran Turismo, Resident Evil, Silent Hill, Soul Blade, and Twisted Metal.
5 0
3 years ago
Other questions:
  • During an experiment, if you purpose change the temperature to test a hypothesis the temperature is called what??
    6·1 answer
  • Which option should u select to ignore all tracked changes in a document
    8·1 answer
  • What acronym describes networked devices that contain microcomputers but are not thought of as computing devices, such as refrig
    9·1 answer
  • How do you make an app for help
    6·2 answers
  • Suppose that a is a one-dimensional array of ints with a length of at least 2. Which of the following code fragments successfull
    8·1 answer
  • 2. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The object
    14·1 answer
  • Write a program in Cto define a structure Patient that has the following members
    12·1 answer
  • Write two statements that each use malloc to allocate an int location for each pointer. Sample output for given program:
    7·1 answer
  • What is an OS? Explain the objectives of an OS.​
    11·1 answer
  • How to fix this? Zoom it in to see it better
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!