Advertisement
Guest User

joelb

a guest
Nov 27th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. Private Sub cmdGrade_Click()
  2. 'Dims all of the variables
  3. Dim coursework_mark(1 To 15) As Integer
  4. Dim exam_mark(1 To 15) As Integer
  5. Dim Percentage(1 To 15) As Integer
  6. Dim Grade(1 To 15) As String
  7. Dim total_mark(1 To 15) As Integer
  8. Dim valid_mark As Boolean
  9. Dim student_names(1 To 15) As String
  10. Dim Counter As Integer
  11. Dim position As Integer
  12.  
  13. 'Calls each of the sub programs
  14. Call user_input(student_names(), coursework_mark(), exam_mark())
  15. Call calculate_percentage(coursework_mark(), exam_mark(), Percentage(), total_mark())
  16. Call calculate_grade(Percentage(), Grade())
  17. Call display_results(student_names(), coursework_mark(), exam_mark(), Grade())
  18. Call count_occurences(student_names(), Grade())
  19. Call find_maximum(coursework_mark(), exam_mark(), position, total_mark())
  20. Call write_to_file(student_names(), position, total_mark())
  21.  
  22.  
  23. End Sub
  24.  
  25. Private Sub calculate_percentage(ByRef coursework_mark() As Integer, exam_mark() As Integer, ByRef Percentage() As Integer, total_mark() As Integer)
  26. 'Calculate the percentage, firstly the total mark is calculated, whcih then the total mark is used to calculate the percentage
  27. Dim Counter As Integer
  28. For Counter = 1 To 15
  29. total_mark(Counter) = coursework_mark(Counter) + exam_mark(Counter)
  30. Percentage(Counter) = ((total_mark(Counter) / 150) * 100)
  31. Next
  32. End Sub
  33.  
  34. Private Sub calculate_grade(ByRef Percentage() As Integer, Grade() As String)
  35. 'Determines the grade with the percentage
  36. Dim Counter As Integer
  37. For Counter = 1 To 15
  38. If Percentage(Counter) >= 70 Then
  39. Grade(Counter) = "A"
  40. ElseIf Percentage(Counter) >= 60 And Percentage(Counter) <= 69 Then
  41. Grade(Counter) = "B"
  42. ElseIf Percentage(Counter) >= 50 And Percentage(Counter) <= 59 Then
  43. Grade(Counter) = "C"
  44. ElseIf Percentage(Counter) >= 45 And Percentage(Counter) <= 49 Then
  45. Grade(Counter) = "D"
  46. ElseIf Percentage(Counter) < 45 Then
  47. Grade(Counter) = "No Grade"
  48. End If
  49. Next
  50. End Sub
  51.  
  52. Private Sub count_occurences(ByRef student_names() As String, Grade() As String)
  53. 'This sub program uses count occurence
  54. Dim Pointer As Integer
  55. Dim target As String
  56. target = "A"
  57. Counter = 0
  58. For Pointer = 1 To 15
  59. If Grade(Pointer) = target Then Counter = Counter + 1
  60. Next
  61.  
  62. End Sub
  63.  
  64. Private Sub cmdEnd_Click()
  65. 'Ends the program
  66. End
  67. End Sub
  68.  
  69. Private Sub display_results(ByRef student_names() As String, coursework_mark() As Integer, prelim_mark() As Integer, Grade() As String)
  70. 'Displays the complete results
  71. Dim Counter As Integer
  72. For Counter = 1 To 15
  73. picOutput.Print student_names(Counter); Tab(30); coursework_mark(Counter); Tab(40); prelim_mark(Counter); Tab(50); Grade(Counter)
  74. Next
  75. End Sub
  76.  
  77. Private Sub user_input(ByRef student_names() As String, coursework_mark() As Integer, prelim_mark() As Integer)
  78. 'PicOutput displays the results, the file with the data is then opened by using the correct file path
  79. Dim Index As Integer
  80. picOutput.Print "student_names"; Tab(25); "coursework_mark"; Tab(45); "prelim_mark"; Tab(60); "Grade"
  81. Open "H:\computing\Computing Science\Higher Computing\SDD\Software Design and Development Assignment\Programming Task\Name and Grades.csv" For Input As #1
  82. For Index = 1 To 15
  83. Input #1, student_names(Index), coursework_mark(Index), prelim_mark(Index)
  84. Next
  85. Close #1
  86. End Sub
  87.  
  88. Private Sub find_maximum(ByRef coursework_mark() As Integer, prelim_mark() As Integer, position As Integer, total_mark() As Integer)
  89. Dim Counter As Integer
  90. Dim maximum As Integer
  91. maximum = 0
  92. For Counter = 1 To 15
  93. 'A fixed loop for the remaining value 2 to 10
  94. total_mark(Counter) = coursework_mark(Counter) + prelim_mark(Counter)
  95. If total_mark(Counter) > maximum Then
  96. 'The second value is checked to see if it is less than maximum
  97. maximum = total_mark(Counter)
  98. position = Counter
  99. 'maximum is assigned the third value
  100. End If
  101. Next Counter
  102.  
  103. 'This continues until all numbers are checked
  104. End Sub
  105.  
  106. Private Sub write_to_file(ByRef student_names() As String, position As Integer, total_mark() As Integer)
  107. 'File will open using the appropriate file path which allows the user to write to the file
  108. MsgBox ("The student with the top mark is " & student_names(position))
  109.  
  110. Open "H:\computing\Computing Science\Higher Computing\SDD\Software Design and Development Assignment\Programming Task\Top Mark.csv" For Output As #1
  111. Write #1, student_names(position), total_mark(position)
  112. Close #1
  113. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement