CS 230 Spring 2005                        Assignment 6 –More Looping, A Little Exposure to Functions                      100 points

 

Assigned: 02/28/2005

Due: 03/16/2005 at the start of class. I will be giving out a new assignment on 3/14, so don’t plan on leaving a lot of work for the end.

 

Pre-Lab (Do Before Lab):  Bring a new disk. Plan out tasks, objects, and events needed for program. Plan out major pseudocode

 

Main Assignment:

We’re going to simulate the workings of a lottery. You will simulate a given number of drawing dates based on assumptions detailed below. You will report

·        drawing by drawing details,

·        and totals – total winnings by all winners during the simulation,

·        and total government share over all drawings.  

We’ll keep the numbers fairly small for convenience (perhaps the lottery is being run by the government of Berwyn PA, rather than say the state of PA). Inputs from the user include:

·        Cost of a lottery ticket. Default to 1.00, acceptable range is 0.05 to 5.00.

·        Government share of ticket revenues. Of ticket sales, a proportion goes to the government (or other sponsor) and the rest goes in the pot. Default to 0.50 (half to the government, half to pot). Acceptable range 0.01 to 0.99

·        Number of drawings to simulate. Default to 10, acceptable range 1 to 100

Details of the simulation include (all numbers in this section below should be named constants in your program):

·        The number of customers participating in a given drawing will be at least 2000. When the pot gets large, more people get interested. One extra customer joins for every $10 in the pot over $5000.

·        Revenues from the sales of customer tickets (at the user entered price) are split between the government for Senior Citizen’s programs and the pot for winners (based on the user entered government share)

·        Whether there is a winner is simulated using (pseudo) randomness and statistics. I am providing a function/procedure/method named “isWinner”  that will be passed the current number of customers and will return whether there is a winner or not.  Grab it from my WWW page, put it near the top of your code (after your constants, before your event procedures).  “Call” it from your code when you need to know if there is a winner in a drawing.

·        If there is a winner, make sure you keep track of that as part of the total winnings by customers. Reset the pot to 1000 (before any ticket sales for the next drawing). The 1000 dollars kicked in should be deducted from the government’s share from the lottery.

·        If there is no winner to a drawing, the current pot carries over to the next drawing (along with money from new ticket sales for the new drawing)

Drawing-by-drawing details should be displayed in a list box so the results can be checked. Include:

·        The pot at the start of ticket sales

·        The number of customers entered in the drawing

·        The government income from the current customers

·        The pot at drawing time (after all ticket sales)

·        Customer winnings (0.00 if no winner)

Provide capabilities for the simulation, plus to clear the input and output to start again, and to exit.

 

Hand in:

 

Miscellaneous:

·        The government share should be entered as a decimal instead of a percent (this makes your job a little easier).

·        If any questions, please ask!!!  Your calculations need to meet the requirements of the task.

·        To add items to the list box, use lstboxname.Items.Add( a string ). You can build a string out of pieces using “concatenation” . E.g.  “Interest: “ & interest.toString(“c”). To clear the contents of a list box, use lstboxname.Items.Clear()

·        Note that we have now covered specifying how many decimal places to display – display a number appropriate for the results. But don’t expect formatting in input textboxes, and don’t reformat input textboxes (if the cost of a ticket includes a dollar sign, you would need to do more work before converting to a double!!!) 

·        We’re no longer going to assume that the clerk enters valid and reasonable values, so ensure that values entered are numbers and that they are in acceptable range, as specified above.  

·        MAKE SURE YOUR PROGRAM WORKS! (i.e. gets the correct answers). Now that our program is branching and looping, we need to try more examples to make sure they work. Think, “what different possibilities need to be checked?” For each, calculate the correct answer by hand and see if your program gets it! Since the randomness is only pseudo-random with a constant “seed”, the program should come out the same way each time you run it – which will help in your debugging!!!!

·        You must turn on Option Explicit and Option Strict.

·        Make sure you save your work before running your program. It is possible that an “infinite loop” could have to be terminated. Usually that will be ok, but if you ever had to kill VB using the task manager you could lose unsaved work.

·        Put YOUR NAME, and e-mail address in comments at the beginning of the program.

·        You MUST include comments that explain your program in order to get full credit.

·        Remember to use meaningful variable names, and indent to show the structure of the program (VB usually does this correctly).

·        Put your name on the form as a Label or as part of the form title.

·        Try to use good user interface design. Make clear what user needs to do and what the answers mean.