Date: Thu, 27 Jul 2006 14:18:29 -0500 (CDT) From: Mark Jacobson To: 810-030-01@uni.edu Subject: Study guide for test later today... Hi VB students, Your exam tommorrow will include: http://www.cns.uni.edu/~jacobson/email030NETmidterm.txt which we went over today in class.... and will also include: ---------------------------------------------------------------------------- 17. Know how to read a file that contains numbers separated by spaces or semicolons on each line. Display the name of each student followed by the sum of the 3 scores, i.e. their total points: (Display the name and total points in a Label named lblScores) Example data file (named scores.txt): Frodo Baggins;95;83;71 <--------- What is GIVEN? Cinderella;100;88;96 Bilbo Baggins;59;72;81 The INPUT or data Jimi Hendrix;75;77;68 is a file named: Joan Osbourne;91;81;71 Wes Montgomery;100;97;98 scores.txt on Carlos Santana;94;81;99 C:\VB\scores.txt path. ---------------- Here is what the output shown in lblResults would look like for the above data: ---------- Frodo Baggins 249 Cinderella 284 Bilbo Baggins 212 Jimi Hendrix 220 Joan Osbourne 243 Wes Montgomery 295 Carlos Santana 284 We solved this in class today, but added to it reporting the AVERAGE points achieved, which required keeping a sum and a count, so the final lines of output in lblResults would be something like this: Frodo Baggins 249 Cinderella 284 Bilbo Baggins 212 Jimi Hendrix 220 Joan Osbourne 243 Wes Montgomery 295 Carlos Santana 284 The average points of the 7 students was = 255.2857 Highest score was 295 ***** Lowest score was 212 ***** ***** Note, we also talked about keeping track of the largest or the smallest value, so I have shown that in the output too. ***** Dim smallest, largest, tot As Integer, _ a() As String Dim myFile As New System.IO.StreamReader("C\:VB030class\students.txt") Dim n, sum as Integer smallest = 9999 largest = -9999 sum = 0 n = 0 rec = myFile.Readline() <----------- Read FIRST record... Do Until rec Is Nothing a = rec.Split(";) Or else use only one line: ... --------------------------------------- For i as Integer = 1 to 3 tot = Val(a(1)) + Val(a(2)) + Val(a(3)) tot += Val(a(i)) --------------------------------------- Next i sum = sum + tot <------------- To later be able n = n + 1 to calculate average... If tot < smallest Then <-------------- keep record of lowest tot smallest = tot end if If tot > largest Then <-------------- keep track of biggest tot largest = tot end if ... lblResults.Text &= a(0) & " " & tot & vbCrLf rec = myFile.Readline() <------ Read NEXT record Loop lblResult.Text &= vbCrLf & vbCrLf & _ "Average score was = " & sum / n & vbCrLf & _ " Low was = " & smallest & vbCrLf & _ " High was = " & highest & vbCrLf & _ n & " students took the tests." ----------------------------------------------------------------------------- 18. TBA (To Be Announced) later today 19. NEW TOPICS since midterm exam.... 20. 21. Check back later... http://www.cns.uni.edu/~jacobson/c030NET.html --------------------------------------------- ----------------------------------------------------------------------------- I have to run some errands, but will try to get it done by 4 or 5 p.m. today. Obviously with #17 and the midterm exam study guide list of topics and skills, the added couple things from #18 to #21 will not be too huge a portion of the test nor will they be that difficult as #17 shown above. #17 ties together files, for next loops, if statements, Split() for splitting a string into separate pieces, arrays and classic Input, Processing, Output (IPO) algorithms. Mark