Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub cmdGrade_Click()
- 'Dims all of the variables
- Dim coursework_mark(1 To 15) As Integer
- Dim exam_mark(1 To 15) As Integer
- Dim Percentage(1 To 15) As Integer
- Dim Grade(1 To 15) As String
- Dim total_mark(1 To 15) As Integer
- Dim valid_mark As Boolean
- Dim student_names(1 To 15) As String
- Dim Counter As Integer
- Dim position As Integer
- 'Calls each of the sub programs
- Call user_input(student_names(), coursework_mark(), exam_mark())
- Call calculate_percentage(coursework_mark(), exam_mark(), Percentage(), total_mark())
- Call calculate_grade(Percentage(), Grade())
- Call display_results(student_names(), coursework_mark(), exam_mark(), Grade())
- Call count_occurences(student_names(), Grade())
- Call find_maximum(coursework_mark(), exam_mark(), position, total_mark())
- Call write_to_file(student_names(), position, total_mark())
- End Sub
- Private Sub calculate_percentage(ByRef coursework_mark() As Integer, exam_mark() As Integer, ByRef Percentage() As Integer, total_mark() As Integer)
- 'Calculate the percentage, firstly the total mark is calculated, whcih then the total mark is used to calculate the percentage
- Dim Counter As Integer
- For Counter = 1 To 15
- total_mark(Counter) = coursework_mark(Counter) + exam_mark(Counter)
- Percentage(Counter) = ((total_mark(Counter) / 150) * 100)
- Next
- End Sub
- Private Sub calculate_grade(ByRef Percentage() As Integer, Grade() As String)
- 'Determines the grade with the percentage
- Dim Counter As Integer
- For Counter = 1 To 15
- If Percentage(Counter) >= 70 Then
- Grade(Counter) = "A"
- ElseIf Percentage(Counter) >= 60 And Percentage(Counter) <= 69 Then
- Grade(Counter) = "B"
- ElseIf Percentage(Counter) >= 50 And Percentage(Counter) <= 59 Then
- Grade(Counter) = "C"
- ElseIf Percentage(Counter) >= 45 And Percentage(Counter) <= 49 Then
- Grade(Counter) = "D"
- ElseIf Percentage(Counter) < 45 Then
- Grade(Counter) = "No Grade"
- End If
- Next
- End Sub
- Private Sub count_occurences(ByRef student_names() As String, Grade() As String)
- 'This sub program uses count occurence
- Dim Pointer As Integer
- Dim target As String
- target = "A"
- Counter = 0
- For Pointer = 1 To 15
- If Grade(Pointer) = target Then Counter = Counter + 1
- Next
- End Sub
- Private Sub cmdEnd_Click()
- 'Ends the program
- End
- End Sub
- Private Sub display_results(ByRef student_names() As String, coursework_mark() As Integer, prelim_mark() As Integer, Grade() As String)
- 'Displays the complete results
- Dim Counter As Integer
- For Counter = 1 To 15
- picOutput.Print student_names(Counter); Tab(30); coursework_mark(Counter); Tab(40); prelim_mark(Counter); Tab(50); Grade(Counter)
- Next
- End Sub
- Private Sub user_input(ByRef student_names() As String, coursework_mark() As Integer, prelim_mark() As Integer)
- 'PicOutput displays the results, the file with the data is then opened by using the correct file path
- Dim Index As Integer
- picOutput.Print "student_names"; Tab(25); "coursework_mark"; Tab(45); "prelim_mark"; Tab(60); "Grade"
- Open "H:\computing\Computing Science\Higher Computing\SDD\Software Design and Development Assignment\Programming Task\Name and Grades.csv" For Input As #1
- For Index = 1 To 15
- Input #1, student_names(Index), coursework_mark(Index), prelim_mark(Index)
- Next
- Close #1
- End Sub
- Private Sub find_maximum(ByRef coursework_mark() As Integer, prelim_mark() As Integer, position As Integer, total_mark() As Integer)
- Dim Counter As Integer
- Dim maximum As Integer
- maximum = 0
- For Counter = 1 To 15
- 'A fixed loop for the remaining value 2 to 10
- total_mark(Counter) = coursework_mark(Counter) + prelim_mark(Counter)
- If total_mark(Counter) > maximum Then
- 'The second value is checked to see if it is less than maximum
- maximum = total_mark(Counter)
- position = Counter
- 'maximum is assigned the third value
- End If
- Next Counter
- 'This continues until all numbers are checked
- End Sub
- Private Sub write_to_file(ByRef student_names() As String, position As Integer, total_mark() As Integer)
- 'File will open using the appropriate file path which allows the user to write to the file
- MsgBox ("The student with the top mark is " & student_names(position))
- Open "H:\computing\Computing Science\Higher Computing\SDD\Software Design and Development Assignment\Programming Task\Top Mark.csv" For Output As #1
- Write #1, student_names(position), total_mark(position)
- Close #1
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement