Question: C + + PDF code: * / #include using namespace std; / * * Displays the reverse of a non blank string s . @

C++PDF code:
*/
#include
using namespace std;
/** Displays the reverse of a non blank string s.
@ pre s should not be blank.
@ post The reverse of the string s is dispalyed.
*/
void displayBackwards(string);
int main(){
string s;
cout" Enter a string -";
cin>>s;
cout"Reverse of string " s "=";
displayBackwards(s);
return 0;
}
/** Displays the reverse of a non blank string s.
@ pre s should not be blank.
@ post The reverse of the string s is dispalyed.
*/
void displayBackwards(string s){
int length = s.size();
if(length==0)//base case
couts,s[0] and then calls ReverseString on s
minus the last character. Notice that it doesn't work anymore! It no longer reverses the string. Look at what it does and
think about why.
What further changes can you make to the function to fix it? In other words, write a recursive function that reverses the
string, but you aren't allowed to print out the last character in s. You are allowed print out the first character in s. Useful
string functions:
s.size()- returns length of string s
s.substr(pos,len)- returns the substring of s of length len starting at postion pos (zero is first position)
 C++PDF code: */ #include using namespace std; /** Displays the reverse

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!