CS35: Project 3

CS35: Programming and Problem Solving
Ray Ontko
Department of Computer Science
Earlham College

Due Friday, 1999/10/29

Choose one of the following programming projects. Read the problem carefully and implement it exactly as described, to the best of your ability. Test it on one or more input files of your choosing. Turn in a print-out of the working program, a print-out of the input file, and a print-out of the output of your program (or, you can send all three to me in an e-mail).

  1. Write a program which extends our fraction-adding program to include fraction subtraction, multiplication, and division, and which always reduces the result fraction to lowest terms. The program should first read a fraction, then read an operator (+, -, *, or /, any of which may be preceeded by spaces), read a second fraction, and then print the entire equation including the answer. It should repeat this process until it reaches the end of input.

    The dialogue from your program should look something like this:

    $ ./fraction_calc
    1/3 + 1/4
    1/3 + 1/4 = 7/12
    2/3 - 1/6
    2/3 - 1/6 = 1/2
    2/3 * 3/4
    2/3 * 3/4 = 1/2
    3/6 / 1/2
    3/6 / 1/2 = 1/1
    ^D
    $
    

    Use functions to break the problem down into appropriate sub-problems.

  2. Powerball is a popular lottery game offered by the Multi-State Lottery Association. In this game, 5 numbers are drawn from a drum containing 49 white balls, and 1 number is drawn from a drum containing 42 red balls. There are 9 ways to win, depending on how many of the player's white numbers match the white balls, and whether or not the player's red number matches the red ball. For complete information about the game, visit: http://www.musl.com/pbhowtoplay.htm.

    Your goal is to write a program which reads 5 numbers between 1 and 49, and 1 number between 1 and 42 and then "plays" that set of numbers 35 times by using rand() to randomly generate draws. Your program should report any winnings (e.g., "You won the Grand Prize", or "You won $100,000", or "Sorry, try again").

    The dialogue from your program should look something like this:

    $ ./power_ball
    Enter 5 numbers between 1 and 49.
    4 9 26 12 11
    Enter 1 number between 1 and 42.
    35
    Play 4 9 11 12 26 PB 35
    Game 1 Draw 3 6 14 29 30 PB 4 : Sorry, try again.
    Game 2 Draw 5 6 18 19 39 PB 24 : Sorry, try again.
    Game 3 Draw 17 19 23 27 29 PB 17 : Sorry, try again.
    .
    .
    .
    

    Use functions to break the problem down into appropriate sub-problems. Note that a user may not "pick" the same number twice, and that as each of the 5 white balls is picked from the drum, it is not replaced until the next round. Your program should sort the 5 white numbers as it prints them.

Copyright © 1999, Ray Ontko (rayo@ontko.com).