Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- 'Program: Lab6jtgrkb
- 'Author: Tre Griffin, 16054704,lab K, Oct 14, 2010
- 'Description: program to determine mid-term grades,read from files,using byref sub procedures and fucntions
- Dim studentname As String
- Private Sub btncalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculate.Click
- '1. Determine file to read.
- lstdisplay.Items.Clear()
- Dim filename As String = FindFilename(cbofile.Text)
- Dim sr As IO.StreamReader
- sr = IO.File.OpenText(filename)
- '2. Display the table header in the list box
- Dim fmtzone As String = " {0,-20}{1,15}{2,15}{3,15}{4,15}{5,15}{6,15}{7,15}"
- lstdisplay.Items.Add(String.Format(fmtzone, "Reading From" & " " & filename, " " & "Today's Date:" & mtxt.Text, "", "", "", "", "", ""))
- lstdisplay.Items.Add(String.Format(fmtzone, "Student Name", "Mid-Term", "Hw/Exerc", "Written", "Total", "Grade", "Points", " Make it?"))
- '3. Start Loop: repeat 10 times, once for each line of the file.
- Dim counter As Integer = 0
- Do While counter < 10
- ' 4. Read a line from the file.
- Dim Line As String
- Line = sr.ReadLine
- ' 5. Split line into useful vaules
- ' This is a good place for ByRef subroutine.
- Dim midtermscore, homeworkscore, writtenscore As Integer
- Call splitline(Line, studentname, midtermscore, homeworkscore, writtenscore)
- ' 6. Process the line:
- ' a. swap the first and last name, add a comma.(Function)(swap Names)
- Dim positionspace As Integer
- Dim last, first As String
- positionspace = studentname.IndexOf(" ")
- first = studentname.Substring(0, positionspace)
- last = studentname.Substring(positionspace + 1).Trim
- studentname = last & "," & first
- ' b. calculate total score (sum of all the scores).
- Dim totalscore As Double
- totalscore = midtermscore + homeworkscore + writtenscore
- ' c. Determine the current letter grade.(total out of 300)
- Dim grade As String
- Select Case totalscore
- Case Is >= 270
- grade = "A"
- Case Is >= 240
- grade = "B"
- Case Is >= 210
- grade = "C"
- Case Is >= 180
- grade = "D"
- Case Else
- grade = "F"
- End Select
- ' d. calculate the points needed on the final to get an A.
- Dim totalneeded As Double
- totalneeded = 450 - totalscore
- ' determine makeitvaule
- Dim makeit As String
- makeit = letsdoit(totalneeded)
- ' 7. Display output for this student in the list box.
- lstdisplay.Items.Add(String.Format(fmtzone, studentname, midtermscore, homeworkscore, writtenscore, totalscore, grade, totalneeded, makeit))
- ' 8. Increment loop counter.
- counter += 1
- ' 9. End the loop.
- Loop
- ' 10. close the file
- sr.Close()
- End Sub
- 'Sub: to part the line and get the student name and scored.
- 'Input: line from the scores file.
- 'Output: the student name and scores.
- Sub splitline(ByVal line As String, ByRef studentname As String, ByRef midterm As Integer, _
- ByRef homework As Integer, ByRef written As Integer)
- Dim pos1, pos2, pos3 As Integer
- pos1 = line.IndexOf(",")
- pos2 = line.IndexOf(",", pos1 + 1)
- pos3 = line.IndexOf(",", pos2 + 1)
- studentname = line.Substring(0, pos1)
- midterm = line.Substring(pos1 + 1, pos2 - (pos1 + 1)).Trim
- homework = line.Substring(pos2 + 1, pos3 - (pos2 + 1)).Trim
- written = line.Substring(pos3 + 1).Trim
- End Sub
- 'Function: decide whether or no student can make the right grade
- 'Input: points needed
- 'Return: No way, Possible, Good Chance
- Function letsdoit(ByVal pointsneeded As Double) As String
- Select Case pointsneeded
- Case Is > 200
- Return "No Way"
- Case Is > 180
- Return " Possible"
- Case Is > 160
- Return " Good Chance"
- Case Else
- Return "Good Chance"
- End Select
- End Function
- 'Function: to pick a file based off of a combo box
- 'Input: user's selection
- 'Return: filename
- Function FindFilename(ByVal selection As String) As String
- Dim filename As String
- Select Case selection
- Case "Anthropology"
- filename = "Anthropology.txt"
- Case "Environmental Science"
- filename = "EnvironmentalScience.txt"
- Case "Geography"
- filename = "Geography.txt"
- Case "Mathematics"
- filename = "Mathematics.txt"
- Case Else
- cbofile.Text = "Anthropology"
- filename = "Anthropology.txt"
- MsgBox("You forgot to select a file - will use Anthropology file")
- End Select
- Return filename
- End Function
- Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
- End
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement