Uses a two-dimensional array to store grades for students : Array Dimension « Collections Data Structure « C# / C Sharp






Uses a two-dimensional array to store grades for students

Uses a two-dimensional array to store grades for students
 
/*
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 ();
        }
    }
}



           
         
  








Related examples in the same category

1.Demonstrate a two-dimensional arrayDemonstrate a two-dimensional array
2.Sum the values on a diagonal of a 3x3x3 matrixSum the values on a diagonal of a 3x3x3 matrix
3.Initialize a two-dimensional arrayInitialize a two-dimensional array
4.Demonstrate jagged arraysDemonstrate jagged arrays
5.Use the Length array property on a 3-D arrayUse the Length array property on a 3-D array
6.Call GetLength for two dimenional array
7.Demonstrate Length with jagged arraysDemonstrate Length with jagged arrays
8.illustrates the use of a two-dimensional rectangular arrayillustrates the use of a two-dimensional rectangular array
9.initialize a two-dimensional rectangular array, and use the array properties and methodsinitialize a two-dimensional rectangular array, and use the array properties and methods
10.the use of a three-dimensional rectangular arraythe use of a three-dimensional rectangular array
11.the use of a jagged arraythe use of a jagged array
12.Uses a jagged array to store sales figuresUses a jagged array to store sales figures
13.Multidimensional and Jagged Arrays:Jagged ArraysMultidimensional and Jagged Arrays:Jagged Arrays
14.Multi dimensional Arrays 1Multi dimensional Arrays 1
15.Catch OutOfMemoryException
16.Catch IndexOutOfRangeException Exception
17.Defines a 2D Array