project computer science
Extra Credit Projects
Visual Basic Applications
I. Project 1
Write a Visual Basic program which will find the sum and average of three numbers. Your form will
contain the following controls:
Label controls
o Number 1
o Number 2
o Number 3
o Sum
o Average
Text Box controls
o Num1
o Num2
o Num3
o Sum
Num1 + Num2 + Num3
o Avg
(Num1 + Num2 + Num3) / 3
Button Controls
o Calc
When clicked the sum and average will be calculated and output in the Sum and Avg text
box controls
o Clear
When clicked all text box controls will be cleared
o Quit
When clicked the application will end and the form will close
Specific coding instructions.
CALCULATE SUM AND AVERAGE OF THREE NUMBERS
Between the dashed lines below is the code for the Visual Basic Project that
will find the sum and average of three numbers entered by the user to the
form textbox controls. The code that you will type is in bold red text. It
assumes that the three input text boxes are named as follows:
Num1
Num2
Num3
It also assumes that the output text boxes are named as follows:
Sum
Avg
Buttons are assumed to be named as follows:
Calc
Clear
Quit
Remember to add the controls to the form before you begin coding. The code
that you will type is in bold red text. Begin coding by double clicking on
one of the three button controls to enter the code for the click method of
that button control.
-----------------------------------------------------------------------
Public Class Form1
Private Sub Quit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Quit.Click
End
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Clear.Click
Num1.Text = ""
Num2.Text = ""
Num3.Text = ""
Sum.Text = ""
Avg.Text = ""
End Sub
Private Sub Calc_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Calc.Click
Sum.Text = Val(Num1.Text) + Val(Num2.Text) + Val(Num3.Text)
Avg.Text = Val(Sum.Text) / 3
End Sub
End Class
---------------------------------------------------------------------
What to upload:
1. Copy and paste program instruction listing from Visual Basic editor to
a Microsoft Word document. (Your listing should be similar to the one
above)
2. Run the form, enter values into the text boxes and press the Calc
button on your form. Capture the screen by hitting the PrtScr key.
3. Paste the screen capture of the form to the same Word document
containing the program listing.
Submit a printout of the above document with your final exam on the day of the final.