|
-
Dec 3rd, 2009, 05:20 PM
#1
Thread Starter
New Member
VB 2008: Array, Grades
I'm an instructor trying to use data from a .txt file to list the grades in a list box. I just want to grab the data from a .txt file, list the total amount of grades in a list box, the mean (avg) and the standard deviation. Any suggestions or links for arrays?
I've reread the book over and over and am extremely confused now more than ever.
Thanks in advance.
-
Dec 3rd, 2009, 08:01 PM
#2
Re: VB 2008: Array, Grades
how is the textfile structured?
can you post it?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 3rd, 2009, 08:06 PM
#3
Re: VB 2008: Array, Grades
As you haven't said that this is homework I'll assume that you don't have to do it a specific way but that you just want the quickest and easiest way.
1. Call File.ReadAllLines to get a String array containing the values from the file.
2. Call Array.ConvertAll to create an Integer array containing the number values represented by the strings in the file.
3. Use the Length property of the array to get the number of grades.
4. Call the Average method of the array to get the average value. Note that, if the values are Integers then Average will return an Integer too. If you want decimal places then you have to call Sum to get the total and then divide that by the number of values yourself.
5. There is no inbuilt functionality for that. You may be able to use LINQ although probably not. You should just find the formula for std dev and write some code to implement it. I reckon there'd be examples on the web already.
-
Dec 3rd, 2009, 08:15 PM
#4
Re: VB 2008: Array, Grades
 Originally Posted by jmcilhinney
You should just find the formula for std dev and write some code to implement it. I reckon there'd be examples on the web already.
there are examples in this forum
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 4th, 2009, 03:06 PM
#5
Thread Starter
New Member
Re: VB 2008: Array, Grades
I'm still having trouble figuring out some things. There are "20" grades total. Why is my Mean and Standard Deviation still way off? Here is my coding so far:
lstBox1.Items.Clear()
Dim name As String
Dim total, x, n As Double
Dim sr As IO.StreamReader = IO.File.OpenText("scores.txt")
Dim count As Double
Do While sr.Peek <> -1
name = sr.ReadLine
total += CDbl(sr.ReadLine)
count += 1
Loop
sr.Dispose()
sr = IO.File.OpenText("scores.txt")
Do While sr.Peek <> -1
name = sr.ReadLine
x = CDbl(sr.ReadLine)
n += ((x - total) ^ 2)
Loop
lstBox1.Items.Add("There were " & (CInt(count)) & " exams.")
lstBox1.Items.Add("Mean = " & (total / count))
lstBox1.Items.Add("Standard Deviation = " & Math.Sqrt(n / count))
lstBox1.Items.Add(" ")
Dim fmtStr0 As String = "{0,2}{1,11}"
lstBox1.Items.Add(String.Format(fmtStr0, "Score", "Grade"))
Dim grade0 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade0, "59", "D"))
Dim grade1 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade1, "60", "D"))
Dim grade2 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade2, "65", "C"))
Dim grade3 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade3, "75", "C"))
Dim grade4 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade4, "56", "D"))
Dim grade5 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade5, "90", "B"))
Dim grade6 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade6, "66", "C"))
Dim grade7 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade7, "62", "D"))
Dim grade8 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade8, "98", "B"))
Dim grade9 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade9, "72", "C"))
Dim grade10 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade10, "95", "B"))
Dim grade11 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade11, "71", "C"))
Dim grade12 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade12, "63", "D"))
Dim grade13 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade13, "77", "C"))
Dim grade14 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade14, "65", "C"))
Dim grade15 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade15, "77", "C"))
Dim grade16 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade16, "65", "C"))
Dim grade17 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade17, "50", "F"))
Dim grade18 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade18, "85", "B"))
Dim grade19 As String = "{0,2}{1,12}"
lstBox1.Items.Add(String.Format(grade19, "62", "D"))
-
Dec 4th, 2009, 04:12 PM
#6
Re: VB 2008: Array, Grades
theres nothing wrong with your mean calculation.
the standard deviation:
n += ((x - total) ^ 2)
should be:
n += ((x - mean) ^ 2)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|