Homework # 5

Due: Oct. 15, 2004 (F)

Your assignment is to complete the Powerball lottery program started in class. You can download the partial program from http://www.cs.uni.edu/~fienup/cs036f04/homework/pgm5.c .

Recall that the InitializeBins function fills the arrays with "balls" (integers) as

The DrawWinner function randomly selects 5 white balls from the whiteBin to fill index positions 0 to 4 of the drawingResult array, and then it fills position 5 of the drawingResult by randomly selecting a ball from the redBin. For example, the resulting drawingResult might contain the values:

Note that none of the white balls should be repeated since they are not returned to the bin after each is drawn.

The PrintTicket function displays the lottery ticket to the screen using printf. For example, the above ticket might print as:

White Balls: 21 12 53 5 14 Powerball: 12

For extra credit, write a second program (call it pgm5EC.c) that draws a winning lottery ticket, and then generates random lottery tickets until a matching lottery ticket is drawn. The program should count and report the number of random lottery tickets needed before the matching lottery ticket is drawn. Hint: use a "long int" variable for the counter since it might take a while.

Again, use the Linux system to edit, compile, execute, and debug your programs.

To submit your assignment, click on the link at the bottom of the homework page for the course: http://www.cs.uni.edu/~fienup/cs036f04/homework/index.htm

You will need to

  1. log on to the submission system using your CNS account information
  2. select the "810:036, C++ Fienup" course
  3. select the radio button corresponding to lab being submitted
  4. enter the name of the file you wish to submit which needs to be accessable on the computer from which you are submitting