Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     'Program: Lab6jtgrkb
  3.    'Author: Tre Griffin, 16054704,lab K, Oct 14, 2010
  4.    'Description: program to determine mid-term grades,read from files,using byref sub procedures and fucntions
  5.  
  6.  
  7.     Dim studentname As String
  8.     Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
  9.         '1.  Determine file to read.
  10.        lstdisplay.Items.Clear()
  11.         Dim filename As String = FindFilename(cbofile.Text)
  12.         Dim sr As IO.StreamReader
  13.         sr = IO.File.OpenText(filename)
  14.         '2. Display the table header in the list box
  15.  
  16.  
  17.         Dim fmtzone As String = " {0,-20}{1,15}{2,15}{3,15}{4,15}{5,15}{6,15}{7,15}"
  18.         lstdisplay.Items.Add(String.Format(fmtzone, "Reading From" & " " & filename, " " & "Today's Date:" & mtxt.Text, "", "", "", "", "", ""))
  19.         lstdisplay.Items.Add(String.Format(fmtzone, "Student Name", "Mid-Term", "Hw/Exerc", "Written", "Total", "Grade", "Points", " Make it?"))
  20.  
  21.  
  22.  
  23.         '3. Start Loop: repeat 10 times, once for each line of the file.
  24.        Dim counter As Integer = 0
  25.         Do While counter < 10
  26.  
  27.  
  28.             '   4. Read a line from the file.
  29.            Dim Line As String
  30.             Line = sr.ReadLine
  31.  
  32.             '   5. Split line into useful vaules
  33.            '       This is a good place for ByRef subroutine.
  34.  
  35.             Dim midtermscore, homeworkscore, writtenscore As Integer
  36.  
  37.             Call splitline(Line, studentname, midtermscore, homeworkscore, writtenscore)
  38.             '   6. Process the line:
  39.  
  40.             '       a. swap the first and last name, add a comma.(Function)(swap Names)
  41.  
  42.             Dim positionspace As Integer
  43.             Dim last, first As String
  44.             positionspace = studentname.IndexOf(" ")
  45.             first = studentname.Substring(0, positionspace)
  46.             last = studentname.Substring(positionspace + 1).Trim
  47.             studentname = last & "," & first
  48.             '       b. calculate total score (sum of all the scores).
  49.            Dim totalscore As Double
  50.             totalscore = midtermscore + homeworkscore + writtenscore
  51.             '       c. Determine the current letter grade.(total out of 300)
  52.            Dim grade As String
  53.             Select Case totalscore
  54.                 Case Is >= 270
  55.                     grade = "A"
  56.                 Case Is >= 240
  57.                     grade = "B"
  58.                 Case Is >= 210
  59.                     grade = "C"
  60.                 Case Is >= 180
  61.                     grade = "D"
  62.                 Case Else
  63.                     grade = "F"
  64.             End Select
  65.  
  66.  
  67.  
  68.  
  69.  
  70.             '       d. calculate the points needed on the final to get an A.
  71.            Dim totalneeded As Double
  72.  
  73.             totalneeded = 450 - totalscore
  74.             ' determine makeitvaule
  75.            Dim makeit As String
  76.  
  77.             makeit = letsdoit(totalneeded)
  78.             '   7. Display output for this student in the list box.
  79.  
  80.  
  81.             lstdisplay.Items.Add(String.Format(fmtzone, studentname, midtermscore, homeworkscore, writtenscore, totalscore, grade, totalneeded, makeit))
  82.  
  83.             '   8. Increment loop counter.
  84.            counter += 1
  85.             '   9. End the loop.
  86.  
  87.         Loop
  88.  
  89.         '   10. close the file
  90.  
  91.         sr.Close()
  92.  
  93.     End Sub
  94.     'Sub: to part the line and get the student name and scored.
  95.    'Input: line from the scores file.
  96.    'Output: the student name and scores.
  97.    Sub splitline(ByVal line As String, ByRef studentname As String, ByRef midterm As Integer, _
  98.                   ByRef homework As Integer, ByRef written As Integer)
  99.  
  100.         Dim pos1, pos2, pos3 As Integer
  101.         pos1 = line.IndexOf(",")
  102.         pos2 = line.IndexOf(",", pos1 + 1)
  103.         pos3 = line.IndexOf(",", pos2 + 1)
  104.  
  105.  
  106.         studentname = line.Substring(0, pos1)
  107.         midterm = line.Substring(pos1 + 1, pos2 - (pos1 + 1)).Trim
  108.         homework = line.Substring(pos2 + 1, pos3 - (pos2 + 1)).Trim
  109.         written = line.Substring(pos3 + 1).Trim
  110.  
  111.  
  112.     End Sub
  113.     'Function: decide whether or no student can make the right grade
  114.    'Input: points needed
  115.    'Return: No way, Possible, Good Chance
  116.  
  117.     Function letsdoit(ByVal pointsneeded As Double) As String
  118.         Select Case pointsneeded
  119.             Case Is > 200
  120.                 Return "No Way"
  121.             Case Is > 180
  122.                 Return " Possible"
  123.             Case Is > 160
  124.                 Return " Good Chance"
  125.             Case Else
  126.                 Return "Good Chance"
  127.         End Select
  128.     End Function
  129.     'Function: to pick a file based off of a combo box
  130.    'Input: user's selection
  131.    'Return: filename
  132.    
  133.     Function FindFilename(ByVal selection As String) As String
  134.         Dim filename As String
  135.         Select Case selection
  136.             Case "Anthropology"
  137.                 filename = "Anthropology.txt"
  138.             Case "Environmental Science"
  139.                 filename = "EnvironmentalScience.txt"
  140.             Case "Geography"
  141.                 filename = "Geography.txt"
  142.             Case "Mathematics"
  143.                 filename = "Mathematics.txt"
  144.             Case Else
  145.                 cbofile.Text = "Anthropology"
  146.                 filename = "Anthropology.txt"
  147.                 MsgBox("You forgot to select a file - will use Anthropology file")
  148.  
  149.         End Select
  150.         Return filename
  151.     End Function
  152.  
  153.  
  154.     Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
  155.         End
  156.     End Sub
  157.  
  158.  
  159.    
  160. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement