Wylie, Earl CIS 1 Chapter 6 Exercise 1: 10/24/12

Total Page:16

File Type:pdf, Size:1020Kb

Wylie, Earl CIS 1 Chapter 6 Exercise 1: 10/24/12

Wylie, Earl CIS 1 Chapter 6 Exercise 1: 10/24/12

Chapter 6 exercise 1 – This exercise introduces for next loops, and dimensioned parallel arrays. The form size = 475 , 435, name= frmgrade, start position= center screen, text= grade. Three labels: label1 – text=grades, size=82x25,location=150,-1,font=16pt. Label2 –text=click process to enter name and score; font=16pt, bold; location=12,370;size=417x25. ; lable3-, name=lblaverage, text=blank; location =43,299. Textbox: name=txtresult, location 71,27; size=311,255; multiline=true. Three buttons: name=btnprocess, text=&Process, location=34,344; size=75,25. Name= btnclear, text=&Clear, location=153,344, size=75,25.name= btnexit, location 295,344; text=&Exit, size=75,25..

Public Class Form1 Private strname(40) As String ‘ this creates at the modular scope and dimensioned array that will Private intgrade(40) As Integer ‘contain 41 elements.

Private Sub btnprocess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprocess.Click Dim intloop As Integer Dim intindex As Integer intloop = InputBox("How many student are you entering", _ "Number of students") Dim intcounter As Integer = 0 Dim dectotal As Decimal = 0 Dim decaverage As Decimal Dim strgrade As String 'initilize array For intindex = 1 To intloop strname(intindex) = InputBox("Enter student full name", "Name please") intgrade(intindex) = InputBox("Enter student final score 1 to 100", "Score Please")

'compute grade and average score

intcounter = intcounter + 1 dectotal = dectotal + intgrade(intindex) If intgrade(intindex) >= 90 Then strgrade = " A" ElseIf intgrade(intindex) >= 80 Then strgrade = " B" ElseIf intgrade(intindex) >= 70 Then strgrade = " C" ElseIf intgrade(intindex) >= 60 Then strgrade = " D" Else strgrade = " F" End If txtresult.Visible = True txtresult.AppendText(vbCrLf & strname(intindex) & " " & intgrade(intindex) & " which is a " & strgrade) Next decaverage = dectotal / intcounter lblaverage.Text = "Class average is " & decaverage.ToString("n2") End Sub

Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click Me.Close() End Sub

Private Sub btnclear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnclear.Click lblaverage.Text = "" txtresult.Clear() btnprocess.Focus() txtresult.visible=false

End Sub End Class

Recommended publications