Lab 12:
Randomization and Procedures
Spring 2001
Reading to be done prior
to Lab 12:
·
p. 272-275 (Random
Numbers) in Chapter 10 of Computer Programming Fundamentals with
Applications in Visual Basic 6.0
Introduction:
This lab adds to the Lab 11 practice with condition statements and procedure calls. You will add simple code that incorporates the use of random numbers as you alter the voter’s ballot that tallies votes for two candidates.
Objectives:
TO DO:
The Scenario:
This is the now the ballot for the presidential elections
for Florida in 2004. Your goal is to
add to the program that tallies the number of votes for a candidate. You will only be adding statements to your
existing program, not taking any away.
You are now voting in Florida. Many of
you may remember the fiasco of the “hanging chad” vote count from the 2000
election. Well, the problem has not
been fixed, and in fact it has now moved into the electronic voting realm.
Many people suspect that the election in Florida was fixed, but the truth can never really be known. However, you are now responsible for the design and functionality of the electoral ballot for the 2004 election. Secretly, you are being paid to alter the vote count slightly in favor of George Bush. However, you have to be sly about it. The Chicago Ballot from Lab 11 is way too obvious to use on the general public.
You will now alter the ballot slightly to make subtle voting changes that benefit the Bush campaign.
In the readings for lecture and lab, you learned a little about using a particular code statement and function to create a randomly generated number. You will use the concept of random numbers as a way choose how many votes a particular candidate will receive on the click of the vote button.
The Randomize Statement
When a person clicks the Vote button, a random number will be generated and stored in a variable.
The only place in the program you will use the random number
function is in the Vote button Click event.
The rest of the code you write for this program will be located there.
Dim <some
variable name> as Integer
Randomize
<some variable name> = Int((Rnd * 2) + 1)
·
This nested If/Then will be just under the statement
If theCan = "George" Then
· It should check the value of the random number. IF it is 1 (an odd number), then increment the votes for George by 1.
·
Otherwise, increment the votes for George by 2.
·
The second nested If/then will be just under the
statement
ElseIf theCan = "Some slob" Then
· It should also check the value of the random number. IF it is 1 (an odd number), then increment the votes for the other candidate by 1.
·
Otherwise, DO NOT INCREMENT!