Ok, the program is supposed to take a .DATA file of names and quiz grades, and then display all the grades and the averaged grade score. Now, I have most of it working, all I need to do is use a single dimensional array to read the list and calculate all the information, but not just one piece at a time(what I have now). In the end it will be nicely organized with each students name, grade, and 6 quiz grades displayed.

I know this looks confusing, I have my sorry attempt at an array commented out. I think I tried mixing a single dimensional array with a multi dimensional, and I got confused. My assignment is almost two weeks late, and the C# tutor doesn't know arrays. Any help would be great, my finals are soon, and I have to get this done ASAP. Thank you.

using System;
using System.Collections.Generic;
using System.Text;

namespace QuizStatistics
{
public class ClassStatistics
{
private string firstName;
private string lastName;
private double[] quizGrades;


public ClassStatistics()
{


}

public ClassStatistics(string firstName, string lastName, double[] scores)
{
this.firstName = firstName;
this.lastName = lastName;
this.quizGrades = scores;
}

public void DisplayObjectState()
{
//for (int kk = 0; kk < studentCount; ++kk)
//{
// Console.WriteLine("{0,7}{1,6}{2,6}{3,6}{4,6}{5,6}{6,6}{7,6}{8,6}{9,6}"
// , FirstName[kk]
// , LastName[kk]
// , avgGradeRounded(kk)
// , quizGrades[kk, 0]
// , quizGrades[kk, 1]
// , quizGrades[kk, 2]
// , quizGrades[kk, 3]
// , quizGrades[kk, 4]
// , quizGrades[kk, 5]



// );


//}

}


public double lowestGrade()
{
double lowest = quizGrades[0];
foreach (double dbl in quizGrades)
{
if (dbl < lowest)
{
lowest = dbl;
}
}

return lowest;

}
public int gradeAverageRoundUp()
{

double average = (sumOfGrades() - lowestGrade()) / (quizGrades.Length - 1);
int averageRoundDown = (int)average;
if (average == (double)averageRoundDown)
{
return averageRoundDown;
}
else
{
return averageRoundDown + 1;
}

}

public char LetterGrade()
{
int Total = (int)gradeAverageRoundUp();

if ((Total) >= 90)
{
return 'A';
}
if ((Total >= 80) && (Total <= 89))
{
return 'B';
}
if ((Total >= 70) && (Total <= 79))
{
return 'C';
}
if ((Total >= 60) && ((Total) >= 69))
{
return 'D';
}
if (Total <= 59)
{
return 'F';
}

else
return '0';
}

public double sumOfGrades()
{
double accumulator = 0;

for (int row = 0; row < quizGrades.Length; ++row)
{
accumulator += quizGrades[row];
}
return accumulator;
}

//public double[] ClassQuizAvgArray()
//{
// double[] AvgArray = new double[quizGrades.GetLength(1)];

// for (int col = 0; col < quizGrades.GetLength(1); ++col)
// {
// AvgArray[col] = (double)sumOfGrades(col) / studentCount;
// }
// return AvgArray;
//}

//public void DisplayLine()
//{
// for (int kk = 0; kk < studentCount; ++kk)
// {
// Console.WriteLine("{0,8:f0}{1,8:f0} {2,6:f0}{3,6:f0}{4,6:f0}{5,6:f0}{6,6:f0}{6,7:f0}"

// , lastName
// , firstName
// , avgGradeRounded(kk)
// , quizGrades[0]
// , quizGrades[1]
// , quizGrades[2]
// , quizGrades[3]
// , quizGrades[4]
// , quizGrades[5]
// );

// }

// Console.WriteLine("\n");



// double[] classDouble = avgGradeRounded();
// Console.WriteLine
// ("Average \n{0,6:f1}\n{1,6:f1}\n{2,6:f1}\n{3,6:f1}\n{4,6:f1}"



// , classDouble[0]
// , classDouble[1]
// , classDouble[2]
// , classDouble[3]
// , classDouble[4]);


}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;


namespace QuizStatistics
{
class Program
{
static void Main(string[] args)
{

// Penny 78 70 76 72 82 84

string lastName = "Konga";
string firstName = "Tomas";
double[] scores = new double[] { 72, 76, 77, 90, 76, 45 };

ClassStatistics test = new ClassStatistics(firstName, lastName, scores);

// These are my tests to make sure my code was correct before I start the array.
Console.WriteLine(test.lowestGrade());
Console.WriteLine(test.gradeAverageRoundUp());
Console.WriteLine(test.sumOfGrades());
Console.WriteLine(test.LetterGrade());
Console.ReadKey(); // pause till any key pressed


}
}
}


/*
string filename = @"..\..\..\ExamGrades.data";
string lineBuf;
string[] tokens;




Stream fstream = new FileStream(filename, FileMode.Open);
StreamReader strReader = new StreamReader(fstream);

Regex theRegex = new Regex(@"\s+");

while ((lineBuf = strReader.ReadLine()) != null)
{


tokens = theRegex.Split(lineBuf);

scores[0] = double.Parse(tokens[2]);
quizgrades[studentCount, 1] = int.Parse(tokens[3]);
quizgrades[studentCount, 2] = int.Parse(tokens[4]);
quizgrades[studentCount, 3] = int.Parse(tokens[5]);
quizgrades[studentCount, 4] = int.Parse(tokens[6]);
quizgrades[studentCount, 5] = int.Parse(tokens[7]);


ClassStatistics test = new ClassStatistics(firstName, lastName, scores);

}

ClassStatistics math = new ClassStatistics(names, quizgrades, studentCount);




Console.WriteLine(" Name Avg Grade Test scores");
Console.WriteLine("----------------------------------------------------------");

math.DisplayLine();

Here is the .DATA file:


Nairuba Penny 78 70 76 72 82 84
Konga Tomas 72 76 77 90 76 45
Ayebare Da 64 93 95 83 66 56
Rukia Adam 67 78 68 75 64 46
Dalwa Syrus 67 75 97 90 57 89
Saansa Timothy 67 45 56 79 83 59
Waiswa Be 62 68 76 66 46 76

I know you didn't ask for this part but I wanted to show you something while I view what it is you're looking for help on.

This is inefficient. You can streamline this by working from bottom to top...

if ((Total) >= 90)
{
return 'A';
}
if ((Total >= 80) && (Total <= 89))
{
return 'B';
}
if ((Total >= 70) && (Total <= 79))
{
return 'C';
}
if ((Total >= 60) && ((Total) >= 69))
{
return 'D';
}
if (Total <= 59)
{
return 'F';
}


Try like this... only one check per range... Also one value check operation that is faster than '>=' Ok hope this helps. I'll look at your array thing

if (Total >89){
return 'A';
}
if (Total > 79){
return 'B';
}
if (Total > 69){
return 'C';
}
if (Total > 59){
return 'D';
}
return 'F';

OK I hope this helps you
It was something I did in gui for output... I think you should get it for accessing the elements of an array now. If you have any specific questions on this, quote me and ask I'll do my best. What is key to remember is when assigning a value to an element in a single column array you would do
arrayName[elementNumber]=valueToBeInArrayAt_elementNumber;
quizGrade[1]=98; // Place grade of 98 into the 2nd element of the array
To get the value of the element in an array you would do
variableToGetValueat-elementNumber=arayName[elementNumber];
grade=quizGrades[0]; // get grade stored in the first element of the array
when you use grade you would get the number there like 98 if that was the value of the first element (first element is always 0 in an array so count is 0 to lengthassigned-1);

I hope I don't confuse you...


private double[] quizGrades = new double[6]; /* Make array of known length 6 elements type double. Accessed as 0 thru 5 */
private double total; // Var to hold total of grades

private void Form1_Load(object sender, EventArgs e)
{
// First we are going to count through the array and place a generated grade in to each
// element in the array or we could do
// quizGrades[]={65,73,85,23,97,89};
for(int count=0;count<quizGrades.Length;count++)// Work through Array
{
quizGrades[count] = 75 + count * 3; // Insert value here as read from file or generated
}
for (int count = 0; count < quizGrades.Length; count++) // Work through Array
{
string grade; // Prepare a string to convert double to string
grade=quizGrades[count].ToString(); // Access element and convert to string
tbxGrades.Text = tbxGrades.Text + grade + "; "; /* Put string in a textbox adding each grade */
}
}

private int quizAvg()
{
for (int count = 0; count < quizGrades.Length; count++) // Work through Array
{
total = total + quizGrades[count]; // Access element and add value to total
}
return Convert.ToInt16(total / quizGrades.Length); // return Average as integer
}

This article has been dead for over six months. Start a new discussion instead.