Functions, Loose Ends

Tom Kelliher, CS17

Mar. 27, 1996

Style Considerations

Modular Program Design Problems

  1. Design a modular program which computes factorials of non-negative integers:

    The program should accept positive integers from the user, asking them if they want to continue, and output the factorial of the input.

  2. Using modules from the previous program, write a modular program which computes combinations. The formula is:

    C(n,r) is the number of ways in which r objects can be drawn from a set of n objects, assuming that order doesn't matter. The user interface of this program should be similar to the previous one. I.e., accept input for several computations, ask the user if they want to continue, etc.

  3. Design a modular program that plays a number guessing game with the user. Here is a sample run for the program:
    Welcome to the game of Guess It!
    I will choose a number between 1 and 100.
    You will try to guess that number.  If you guess wrong,
    I will tell you if you guessed too high or too low.
    You have 6 tries to get the number.
    
    OK, I am thinking of a number.  Try to guess it.
    
    Your guess? 50
    Too high!
    Your guess? 12
    Too low!
    Your guess? 112
    Illegal guess.  Your guess must be between 1 and 100.
    Try again.  Your guess? 23
    **** CORRECT ****
    
    Want to play again? y
    OK, I am thinking of a number.  Try to guess it.
    
    Your guess? 23
    **** CORRECT ****
    
    Want to play again? n
    Goodbye, it was fun.  Play again soon.
    



Thomas P. Kelliher
Tue Mar 26 12:59:56 EST 1996
Tom Kelliher