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

Revise the function writeBackward, discussed in Section 2.3.1, so that its base

ID: 3749934 • Letter: R

Question

Revise the function writeBackward, discussed in Section 2.3.1, so that its base case is a string of length 1, the original function is as follows:

void writeBackward(std::string s){

int length = s.size();

if (length > 0){

std::cout << s.substr(length - 1, 1);

writeBackward(s.substr(0, length - 1));

} //end if

//length == 0 is the base case - do nothing.

} //end writeBackward

Then, Write a C++ function that implements the pseudocode function writeBackward2, as given in Section 2.3.1. which is:

writeBackwards2(s:string){

if (the string s is empty){

Do nothing--this is the base case.

}//end if

else{

writeBackward2(s minus its first character)

Write the first character of s

}//end else

}//end writeBackward2

Explanation / Answer

If you have any doubts, please give me comment...

void writeBackward(std::string s){

int length = s.size();

if (length == 1){

std::cout << s;

} // end if

else

{

std::cout << s.substr(length - 1, 1);

writeBackward(s.substr(0, length - 1));

} //end else

} //end writeBackward

pseudo code:

writeBackwards2(s:string){

if (the string s has length 1){

write the string s

}//end if

else{

writeBackward2(s minus its first character)

Write the first character of s

}//end else

}//end writeBackward2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote