Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NEED ALL PARTS COMPLETED Write a program that reads a string containing exactly

ID: 3536773 • Letter: N

Question

NEED ALL PARTS COMPLETED

Write a program that reads a string containing exactly four words (separated by * symbols) into a single string object. Next, extract each word from the original string and store each word in a string object. Display both the original and final strings (Hint: To extract the words, you should use the find member function of find each symbol *, assign the characters up to the * to one of the four string objects, and then remove those characters from the original string).

If your program includes functions, then the analysis section should consist of two sections:

An analysis of the program as a whole

     An analysis of each task that will be written as a function

   For user-defined functions write an analysis

For library functions, list the library and the functions you intend to use.

If your program includes functions, in addition to the program inputs and outputs, a section should be added which lists the inputs and outputs to each user-defined function (this step is not needed for library functions). In addition to identifying the program inputs and outputs, the preconditions and post conditions for user-defined functions should be identified.

A precondition is a condition that should be true before the function is called. For example, if the input to your function is a variable assigned a depth value, the precondition would be:

depth is defined and is a positive floating point number

By specifying that the depth is defined, the function is not required to acquire the depth but is expecting a variable containing the depth. The second part of the precondition specifies the data type expected and the range of acceptable numbers.

A post condition is a condition that should be true after the function is called. The functions we have studied so far return a value so it is not really necessary to specify a post condition. In the future, we will learn about functions that don%u2019t return a value, but provide the results in another manner. These types of functions will more often require a post condition specification.

While the precondition statement specifies what type of information should be supplied to the function, the writer of the function should not assume that the user of the function has provided the correct input. It is the responsibility of the function writer to validate the inputs. The methods to validate inputs will be covered later in the text.

This section should include both the program inputs and the inputs to each function.

This section should include the program outputs and the function outputs.

If a formula is inside of a function, identify the function when the formula is specified.

Provide a pseudcode algorithm for the program as a whole and for each function.

Desk-check your algorithm and list the inputs you used and the results you obtained. We will discuss methods for verifying that a function is working correctly later in the course.

Test your program with your desk-check data. Describe the results here. Try at least one other set of test data and record the results. We will discuss methods for testing functions later in the course.

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

int main()

{

//First, I will declare the variables

string original;

int remove_1;

int remove_2;

int remove_3;

int remove_4;

string star;

string word_1;

string word_2;

string word_3;

string word_4;

string reverse_1;

string reverse_2;

string reverse_3;

string reverse_4;

string final;

//Next, I will gather the inputs

cout << "Please enter your words..." << endl;

cin >> original;

cout << "Please enter your method of spacing..." << endl;

cin >> star;

//Next, I will separate the words

remove_1 = original.find(star);

reverse_1.assign(original, 0, remove_1);

original.erase(0, remove_1);

remove_2 = original.find(star);

reverse_2.assign(original, 0, remove_2);

original.erase(0, remove_2);

remove_3 = original.find(star);

reverse_3.assign(original, 0, remove_3);

original.erase(0, remove_3);

remove_4 = original.find(star);

reverse_4.assign(original, 0, remove_4);

final = reverse_4 + "*" + reverse_3 + "*" + reverse_2 "*" + reverse_1;

//Next, I will compile the new string and display it on the screen

cout << "The original string was: " << original << endl;

cout << "The reversed string is: " << final << endl;

return(0);

}