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

//Variables string original; double remove_1; double remove_2; double remove_3;

ID: 3537001 • Letter: #

Question

//Variables
string original;
double remove_1;
double remove_2;
double remove_3;
double remove_4;
string productsymbol;
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;

//Statements
cout << "Type any words you like" << endl;
cin >> original;
cout << "How would you like to space these words?...hint use *..." << endl;
cin >> productsymbol;


remove_1 = original.find(productsymbol);
reverse_1.assign(original, 0, remove_1);
original.erase(0, remove_1);
remove_2 = original.find(productsymbol);
reverse_2.assign(original, 0, remove_2);
original.erase(0, remove_2);
remove_3 = original.find(productsymbol);
reverse_3.assign(original, 0, remove_3);
original.erase(0, remove_3);
remove_4 = original.find(productsymbol);
reverse_4.assign(original, 0, remove_4);
final = reverse_4 + "*" + reverse_3 + "*" + reverse_2 + "*" + reverse_1;

cout << " Original string: " << original << endl;
cout << "ReversedString: " << final << endl;

return(0);
}
_______________________________________________________________________________________________

Complete the following using the program above!!

Program Test Plan:

FUNCTIONS:

(Repeat this section for each of your functions). Provide the function prototype here.

Function Preconditions and Post Conditions:

Function Inputs and Outputs:

Function formulas:

Function Algorithm:

Explanation / Answer


word1*word2*word3*word4

and productsymbol as

*

it outputs


word4*word3*word2*word1

1. take a word from user with a symbol used multiple times in the word

{ in the bracket, i ll explain you how it works. word = word1*word2*word3*word4 }

2.take input from user what that symbol will be.

{symbol = *}

3. check if the symbol exist in the word or not

{check if * exist in word1*word2*word3*word4}

4. then remove the part till the encountered symbol.

{remove till * is encountered. so now original will be left with *word2*word3*word4}

5. assigned the removed value into a variable.

{word1 is assigned to reverse1}

6. repeat step 4 till it encounters the last symbol in the word.

{in second iteration, word2 will be removed and original will be left with **word3*word4}

{in third iteration, word 3 will be removed and original will be left with ***word4}

7. repeat step 5 till it encounters the last symbol in the word

8. Display the original and reversed word.



Program Test Plan:

test plan consists of both valid and invalid test cases. So, we will consider two cases.

case1 : valid test case

1. take string as input.

2. find for the available symbol in the input string.

3.and print the reversed string.


case 2 : invalid test case

1. take string as input.

2. find for the NOT available symbol in the input string.

3.and try to print the reversed string.


FUNCTIONS:

used functions are find() assign() and erase()

(Repeat this section for each of your functions). Provide the function prototype here.


find()

find : O(n)

Function Preconditions and Post Conditions:


PreCondition- a String input or word where a particular symbol or character can be searched.

PostCondition - a variable to store the position of the symbol in the word, if the symbol is found.


Function Inputs and Outputs:

in your code, it is used as

remove_1 = original.find(productsymbol);

suppose, our input was


word1*word2*word3*word4

and symbol we are looking for is *


then


this will return 5. which is the position of first occurence of star *

w =0 o = 1 r = 2 d = 3 1 =4 * = 5


Function formulas:

checking of a symbol starting from the first letter and if the character is not found, move to the next character . if found, stop .

Function Algorithm:

1. take an input word

2. apply find method to that word and pass the character to be find as the method parameter.

3. start with i =0 and compare the first character of the word with seraching word (which is used as the parameter. {* in our case})

4. if not found, increment i to i++

5. if found, stop.


assign()


assign: O(1)

Function Preconditions and Post Conditions:


needs a input word, the index which denotes the point to start and another index where it is needed to stop.


Function Inputs and Outputs:

in your code, it is used as


reverse_1.assign(original, 0, remove_1);


suppose our input is

word1*word2*word3*word4

and remove_1 has stored 5 into it.

so it, will start writing from 0 index and reads till 5 th character is encountered.

5th character is excluded. as soon as the program fetches the 5th character, values before it is stored.

output = word1



Function formulas:

none

Function Algorithm:

1. takes an input word.

2. takes starting index

3. takes ending index

4. copies the values from starting index to the ending index in a variable




erase()

erase : O(1)



Function Preconditions and Post Conditions:

Needs an input word or String,

needs starting index

needs ending index



Function Inputs and Outputs:

in your code, it is used as

original.erase(0, remove_1);


here, remove_1 stores a value 5 (as told above.)

so suppose our input in original is

word1*word2*word3*word4

and remove_1 has stored 5 into it.

then

it will remove all the characters between starting index and ending index

i.e all the characters from 0th to occurence of 5th character.

so the output would be


*word2*word3*word4


Function formulas:

none

Function Algorithm:


1. takes an input string

2. takes starting index

3. takes ending index

4. remove character from starting index till the ending index is encountered.