JORDAN UNIVERSITY OF SCIENCE AND TECHNOLOGY

CS 116 (Visual Basic 6)

Sections 1 and 2 (Dr. Monther Aldwairi)

Assignment # 2

Due Date 30/10/2007

Objective:

1.       Understand how to generate random numbers.

2.       To understand the use of decision structures (IF/ELSE and Case Select).

Exercise 1:

Interface

Write a VB program using the form in the Fig 1. below

Figure 1. Interface

Note the following:

1.       All fonts are bold, “MS San Serif”,  size 12

2.       All labels are right aligned  except for the Status label, which is centered

3.       Use proper naming standards

Functionality

1. Each time the “Toss the Coin” button is pressed, Rnd is used to simulate a coin toss and the values are updated as shown the Fig 2.

Figure 2: results after 346 tosses

Note: you can produce tosses quickly by holding down the Enter key

The following table lists the objects with their functionality

 Object Displays txtOutcome Current Toss outcome “Heads” or “Tails” txtHeads Total number of Heads txtTails Total number of Tails txtTosses Total Number of Tosses txtPercent Percentage of Heads cmdToss Generate a Rnd toss and updated all boxes

Hint: Use FormatPercent

1. Each time the “Status” button is clicked, a sentence will be displayed in the picture box describing the Toss status as show in the Fig 3.

Figure 3 Status!

The Status depends on the value of txtPercent as shown in the table below:

 TxtPercent value (v) Status v=50 Perfect Toss:) 49<= v <50 Or 50< v <=51 Close Enough :-) 48<= v <49, 51< v <=52 Toss more! 0 <= v <48 Tails Biased Toss :( 52< v <=100 Heads Biased Toss :( v>100 or  v<0 Error!

Hint: Use Select case

Hint: Don’t forget to Cls

More Examples

Bonus:  (optional)

Error Detection

Your system should detect if the status button is clicked before any tosses are done!

Display the status message:

"Toss the Coin First"

Bonus