Results 1 to 4 of 4

Thread: Arrays in C#

  1. #1
    Join Date
    Jul 2010
    Posts
    1

    Arrays in C#

    I am new to the site and also to programming. I am having problems with an assignment due on tomorrow and was hoping to get advice on what I may be doing wrong or missing. The assignment and code is included below:



    1. A two-dimensional array for storing the three quiz grades for a class of 5 students; this array must be initialized to the following:
    { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } }
    2. A one-dimensional array for storing the average quiz grade for each student.

    Your application should perform the following tasks:

    1. Calculate and store the average grade for each student.
    2. Print to the console a nicely formatted two-dimensional table with headings listing the student number (0 to 4), the grade for each quiz (Quiz 1, ... Quiz 3), and the average.
    3. Bonus: For 2 bonus points, also provide the data structures and processing for storing last names for the students and including these last names in the two-dimensional table printed out on the console


    CODE:
    //Two-Dimensional Arrays.cs
    //Student Quiz Grades
    using System;

    class StudentQuizGrades
    {
    static void Main(string[] args)
    {
    //array of student grades
    decimal[,] Quizzes = { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };
    Quizzes[4, 2];

    //average quiz grade array
    decimal[,] QuizAverage = {{}, {}, {}, {}, {}};

    //student name array
    string[] Name = new string {{James}, {Johnson}, {Smith}, {Michaels}, {Roberts}};

    count NumQuiz = 3;
    Decimal total = 0;
    for (student = 0; student < QuizLength; student++)
    {
    for (quizCount = 0; quizCount < NumQuiz; quizCount++)
    total = total + Quiz[student.quizCount];
    Average[student] = total / NumQuiz;
    }
    }
    }

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Arrays in C#

    Declaring a two-dimensional array has the following form:

    Code:
    type arr-name[NUM_ROWS][NUM_COLS];
    where type is the data type for the array, arr-name is the variable name for the array, NUM_ROWS is the maximum number of rows for the array, and NUM_COLS is the maximum number of columns for the array. To declare an integer array of five rows and three columns, the following code could be used:

    Code:
    int arr[5][3];
    More information can be found here.

  3. #3
    jimsmithusa123 Guest

    Re: Arrays in C#

    hello friends

    i am new to this forum. i am jim smith and i am web designer,
    i want to know,
    does anyone know how to define 3 dimensional array in c . also how to fetch the value from array.

  4. #4
    Join Date
    Oct 2010
    Location
    Jaipur
    Posts
    2

    Re: Arrays in C#

    here is the solution
    using System;


    class Program
    {
    static void Main(string[] args)
    {
    int[,] quiz = new int[,] { { 87, 68, 94 }, { 100, 83, 78 }, { 85, 91, 76 }, { 65, 81, 66 }, { 65, 71, 56 } };
    float[] avg = new float[5];
    string[] names = { " James", "Johnson", "Smith", "Michaels", "Roberts" };
    for (int x = 0; x < 5; x++)
    {
    int total = 0;
    Console.WriteLine("Quiz Marks for : " + names[x]);
    Console.WriteLine("Quiz1\tQuiz2\tQuiz3");
    for (int y = 0; y < 3; y++)
    {
    total += quiz[x,y];

    Console.Write(quiz[x,y] + "\t");

    }
    avg[x] = total/3;
    Console.WriteLine();
    }
    int p = 0;
    foreach (int t in avg)
    {
    Console.WriteLine("Average for " + names[p] + " : " + t);
    p++;
    }
    Console.Read();
    }

    }
    Last edited by Vigil.M; 07-10-2010 at 10:02 PM. Reason: No external links allowed

Similar Threads

  1. Arrays in C++
    By Acolapissa in forum Software Development
    Replies: 3
    Last Post: 19-12-2010, 10:05 AM
  2. Challenge with Arrays 3d 4d
    By daniel_at_work in forum Software Development
    Replies: 1
    Last Post: 20-08-2010, 10:31 AM
  3. How to use an Arrays in PHP?
    By Jacques25 in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 01:24 AM
  4. Arrays in C#
    By DotNetUser in forum Guides & Tutorials
    Replies: 2
    Last Post: 03-12-2008, 05:31 PM
  5. Problem with arrays in C++
    By fellah in forum Software Development
    Replies: 3
    Last Post: 05-09-2008, 04:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,250,307.92758 seconds with 17 queries