/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa
Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/
// Grades.cs -- Uses a two-dimensional array to store grades for students
//
// Compile this program with the following command line:
// C:>csc Grades.cs
namespace nsGrades
{
using System;
public class Grades
{
static public void Main ()
{
DateTime now = DateTime.Now;
Random rand = new Random ((int) now.Millisecond);
int [,] Grades = new int [5,10];
for (int x = 0; x < Grades.GetLength (0); ++x)
{
for (int y = 0; y < Grades.GetLength(1); ++y)
{
Grades [x, y] = 70 + rand.Next () % 31;
}
}
int [] Average = new int [10];
Console.WriteLine ("Grade summary:\r\n");
Console.WriteLine ("Student 1 2 3 4 5 6 7 8 9 10");
Console.WriteLine (" ----------------------------------------");
for (int x = 0; x < Grades.GetLength (0); ++x)
{
Console.Write ("Test " + (x + 1) + " ");
for (int y = 0; y < Grades.GetLength(1); ++y)
{
Average[y] += Grades[x,y];
Console.Write ("{0,4:D}", Grades[x,y]);
}
Console.WriteLine ();
}
Console.Write ("\r\n Avg. ");
foreach (int Avg in Average)
{
Console.Write ("{0,4:D}", Avg / Grades.GetLength(0));
}
Console.WriteLine ();
}
}
}
|