Question: Please help me the assignment based on these code below. /** Program to display the reverse of a non blank string s , using a
Please help me the assignment based on these code below.
/** Program to display the reverse of a non blank string s , using a recursive function. The program demonstartes a Void Recursive function. */ #include 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) /** Program to display the reverse of a non blank string s , using a recursive function. The program demonstartes a Void Recursive function. */ #include Question 2 In the videos/pdfs, you have seen a recursive solution for the fibonacci sequence and also an iterative solution. In this exercise you will examine the runtime efficiency of both. Enter the recursive solution from the videos/pdfs in a program. Add a simple main() function which calls rabbit() with a value the user supplies. Try running the program with small values like 5 and 6 and make sure the results are correct. Now, try the program with a larger value, like 45. Notice approximately how long it takes for the program to run. Now, do steps 1 and 2 with the iterative solution. Notice approximately how long it takes for the program to run. In your reply to this discussion, post your main function, and indicate approximately how long it took your program to run for the recursive approach and also for the iterative approach for the larger value 45.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
