Question: CSE 202 Lab 7: Recursion 1. Perform the following exercises under lab7 sub directory. 2. The following simple program decides whether a phrase is a
CSE 202 Lab 7: Recursion
1. Perform the following exercises under lab7 sub directory.
2. The following simple program decides whether a phrase is a palindrome. Note the program is case sensitive; so, 'A' != 'a'.
/************************************************************** * name * palindrome.cpp * date * description **************************************************************/ #include#include #include using namespace std; bool is_palindrome(string s) { if (s.length() Make sure you understand how the program works, then type it in, compile, and run:
$ g++ palindrome.cpp -o palindrome $ palindromeMake sure "rotor" and "RoToR" are flagged as palindromes. Here are more examples of what is and is not a palindrome: "Rotor" is not a palindrome, "exammaxe" is a palindrome, "ex ammaxe" is not a palindrome, "A man, a plan, a canal - Panama!" is not a palindrome, "a man a plan a canal panama" is not a palindrome, "a man a plan a c a nalp a nam a" is a palindrome, "Madam, I'm Adam" is not a palindrome, and "Madam,I,madaM" is a palindrome.
3. Modify the program so that all above examples are flagged as palindrome. In other words, the program should ignore white spaces and punctuation marks, and should not be case sensitive. Two useful helper functions for this task are: bool is_letter(char c); // returns true if c was a letter; otherwise, returns false char to_lower(char c); // returns the lower case version of c; otherwise, returns c unchanged
Write and use your own is_letter() and to_lower() functions.
4. Draw stack of activation records for input "Madam, I'm Adam" at its largest size and right before the first call to palindrome() returns. Activation record for main() should include input; activation record for palindrome() should include s, first, last, shorter, and return value.
5. Hand in printouts of your new palindrome.cpp, percent completed, and typescript of a sample run. Also, include the drawing from 4.
GDB
You may use gdb (Gnu Debugger) to debug your programs. Type in the following program that computes sum of the first n integers. We will set n to 10 for now, the program can be easily modified to be more general and input any value for n.
// your name // sum.cpp // date #includeusing namespace std; main() { int i, n = 10, total = 0; for (i = 1; i Compile with -g flag and run the program with the debugger.
$ g++ -g sum.cpp $ gdb a.out $Now the debugger is running your program. Set two break points at line 11 and 13.
> break 11 > break 13Don't type > , it signifies gdb prompt. Run your program.
> runThe program runs until it reaches line 11. Examine (print) the values of variables i and total.
> p i > p totalExecute line 11 and stop (next).
> nPrint total again.
> p totalNow its value is 1. Command n executes current line and stops on the next line. Command c continues execution until the next break point. In this case, we continue one more iteration of the for-loop and stop at line 11 again. Continue and print both i and total.
> c > p i > p totaltotal is still 1 but i has been incremented. If you continue one more time total value will be 3 as expected. Continue several times until the debugger stops at line 13. You may print the values of i and total just before cout executes.
One more continue will execute the rest of program because there are no more break points. You may run the program again by typing run or exit out of debugger by typing quit.
> quit $There are multitude of other commands that you may use. For example, you may change the value of variables if you wish, place a "watch" on a variable or object, or "list" current source code lines being executed. Type help to get more info.
CSE 202 ?.ab 7: Recursion Perform the following exercises ?1nder lab sub directory. 2 The allwing kimpldes whether pi Note the progrn is case sensitive; , A- palindrome description lastrear ?include ? using navespace stdj bool i5 palindrore strings return true st 11-st .. last) string shorter - .substril, s.lergth3-2 return 15 plindronehorter return talre 1n( ) cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts



