Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this program in C++ and make sure that you do the program in the main, i cant have any other functions out of

image text in transcribed

image text in transcribed

Please do this program in C++ and make sure that you do the program in the main, i cant have any other functions out of the main. The whole code has to be in the main. Make as simple as possible.

Algorithm/Pseudo-code for Exercise 1 1. This exercise requires you to compress several consecutive "whitespaces" into a single space. A whitespace can be a spacea tab '"\f, or a newline n' and/or . So it is convenient to define a function to check if a character is a whitespace or not. For example, define the following function to accomplish it. 2. The beginning whitespaces, if any, need to be removed. 3. Read the input character one at a time, call IsWhiteSpace0 to check if it is a whitespace. If not, write the character to the output. If yes, go to 3.a. Repeat this step until all characters are read. a. You would need a bool flag to help you identify if the current whitespace is the first one between two words. If so, writes a space to the output string; if not, do not write anything. Reset this flag if the next character is not a whitespace. Go back to step 3 if more characters are to be read in the string. Special case needs to be handled for the very beginning whitespace of the input string. Use a bool variable to help you. b. c. bool aticstRJAR= false; // Used for the compressing consecutive whitesnaces bool iinitial-true; I/ Used for removing the beginning whitespaces // Read in all characters and change all characters to lowercase and compress // nk consecutive whitespaces to a single bla // Skip the beginning whitespaces continue /I compress all consecutive whitespace into one blank add a space to the new string else // We have already got the first non-whitespace character // So there are no more beginning whitespaces isiana, = false; aticstRARk = false add the toloneRcharacter) to the new string Algorithm/Pseudo-code for Exercise 1 1. This exercise requires you to compress several consecutive "whitespaces" into a single space. A whitespace can be a spacea tab '"\f, or a newline n' and/or . So it is convenient to define a function to check if a character is a whitespace or not. For example, define the following function to accomplish it. 2. The beginning whitespaces, if any, need to be removed. 3. Read the input character one at a time, call IsWhiteSpace0 to check if it is a whitespace. If not, write the character to the output. If yes, go to 3.a. Repeat this step until all characters are read. a. You would need a bool flag to help you identify if the current whitespace is the first one between two words. If so, writes a space to the output string; if not, do not write anything. Reset this flag if the next character is not a whitespace. Go back to step 3 if more characters are to be read in the string. Special case needs to be handled for the very beginning whitespace of the input string. Use a bool variable to help you. b. c. bool aticstRJAR= false; // Used for the compressing consecutive whitesnaces bool iinitial-true; I/ Used for removing the beginning whitespaces // Read in all characters and change all characters to lowercase and compress // nk consecutive whitespaces to a single bla // Skip the beginning whitespaces continue /I compress all consecutive whitespace into one blank add a space to the new string else // We have already got the first non-whitespace character // So there are no more beginning whitespaces isiana, = false; aticstRARk = false add the toloneRcharacter) to the new string

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions