CS 2500 Spring 2011
Lab 3

Recursion

The goal of these programs is to work with recursive functions.


Program A

Write a recursive C++ function that writes the digits of a positive integer n in reverse order. Then write a main function to ask the user for the integer n, insure that n is a positive integer, and call your function.


Program B

Revise the writeBackward function discussed in our book (starting on page 76) so that the base case is a string of length one. Then write a main function to ask the user for a string, insure that n is a string, and call your function.


Here is the required comment format for significant functions (courtesy of Dr. Sarraille):

/****************************************
    FUNCTION NAME:
    INPUT:
    OUTPUT:
    PRECONDITIONS:
    POSTCONDITIONS:
    CALLERS:
    CALLEES:
*****************************************/



What to Submit

Name your source code file for part A reverseInt.cpp and your script script_reverseInt
Name your source code file for part A backwardStr.cpp and your script script_backwardStr


Your script should test both valid and invalid input. The valid input should include very small values. Five test runs for each program should be reasonable.

Turn in your program and script to the CS Homework Submission System at
https://hopper.csustan.edu/cshomework/
             Choose instructor:  cs2500mm
             Choose course: CS2500
             Choose assignment: Lab3