[Solved] Store the score grade and mark for them in array, beginner [closed]


Lets break your question down in an attempt to solve it.

Reads the scores of a test

Simple, you could use something like Console.ReadLine which can take in a user input of a test grade.

string grade = Console.ReadLine(); // save the user input in a string

Determines the mark of a test

I’ll assume you mean percentage-wise. Try taking the user input, dividing it by the total of the test, and getting that value should be fine. Since Console.ReadLine will return a string, expect the need to convert the string to an int.

int mark;

if (int.TryParse(grade, out _grade))
{
    mark = (double percentage = _grade / total_of_test) * 100;
}

Store the grades and marks in an array

You could write a class called TestResults, create 2 variables, one for the grades, and another for the marks, then add that class to an array of TestResults[]. This will allow you to directly call either the marks or the grade depending on what you’d prefer.

public class TestResults
{
    int marks;
    int grades;
}

I hope this was somewhat helpful. Please be mindful next time and post some code showing you have atleast tried to tackle the problem.

Edit: In terms of creating an array, lets look at an example

Here’s an example of an array:

int[] this_int_array = new int[] { 4, 5, 6, 7, 8, 9 }

This code will automatically get the length of the array to be 6, therefore we do not need to specify a length initially. It can be accessed by:

this_int_array[0] // till 5, since programming starts counting at 0.

In your case, something like this should work. First, lets look at our test results class. We have 2 fields, marks and grades. We can access these directly from within an instantiated field (TestResults tr = new TestResults is an example of instantiation. Anything being defined as a new is being instantiated)

public class TestResults
{
    int marks;
    int grades;
}

Then, in order to make it an array, do the following:

TestResult student_A = new TestResult {
                                marks = 9;
                                grades = 90; // as an example
                            }

then, once you’ve got a nice list of students, we can add them to an array.

TestResult[] all_results = new TestResults[] {
                                    student_A,
                                    student_B,
                                    student_C
                                }

I hope this was more clear.

2

solved Store the score grade and mark for them in array, beginner [closed]