Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a recursive reverseString in C + + function like the one in the pdf ' s videos, but with a twist. You are no

Implement a recursive reverseString in C++ function like the one in the pdf's videos, but with a twist. You are no longer allowed to print out the last character in s. You are, however, allowed to print out the first character in s, i.e. s[0].
First, make one change to the function so that it prints out the first character in s, 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:
o s.size()- returns length of string s
o s.substr(pos,len)- returns the substring of s of length len starting at postion pos (zero is first position)Question 1
Implement a recursive reverseString in C++ function like the one in the pdf's videos, but with a twist. You are no longer
allowed to print out the last character in s. You are, however, allowed to print out the first character in s, i.e. s[0].
First, make one change to the function so that it prints out the first character in s,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)
image text in transcribed

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago