Freedom*

i want to create a program with the grades in a school. we have to find the average of the grades depending on how many courses the student has chosen.

also, we have to find how many courses each studend has passed.

• the user has to give the number of the students in a class

• for each student we have to give the number of the courses he has taken

• for each course, we have to give the grades from a test and from the final exams

my teacher gave me the main class. i have solved a part from the problem but i don't think that it's correct. Need your help

``````using System;

namespace Lab6Exercise1
{
class MainClass
{
public static void Main(string[] args)
{
int N;

Console.WriteLine ("Number Of Students");

Students[] M=new Students[N];

for (int i = 0; i < N; i++)
{
Console.WriteLine("Number of courses for the {0}st student:", i + 1);

M[i] = new Students(n);

Console.WriteLine("Name:");
Console.WriteLine("Code");

double average;
M[i].AVERAGE(out average);

Console.WriteLine("{0},{1},AVERAGE:{2:.00},Passed_Courses:{3}", M[i].GetCode(), M[i].GetName(), average, M[i].GetNumberPass());
}
}
}
}

using System;

namespace Project1lab6
{
{

//the variables given from the teacher
double test;
double final_exams;
bool pass;

{

for (int i = 0; i < n; i++)
{

do
{
} while (test < 0 || test > 10);

do
{
} while (final_exams < 0 || final_exams > 10);

}
}

public double AVERAGE(out double average)
{
average = test * 0.4 + final_exams * 0.6;

if (average >= 5.0)
pass = true;

return average;

}
}
}

using System;

namespace Project1lab6
{
public class Students
{

//the variables given from  the teacher
string name;
string Code;
int NumberPass = 0;

//set&get

public void SetName(string Name)
{
this.name = Name;

}

public string GetName()
{
return name;
}

public void SetCode(string Code)
{
this.Code = Code;

}

public string GetCode()
{
return Code;
}

public void SetNumberPass(bool pass)
{

if (pass == true)
NumberPass++;
}

public int GetNumberPass()
{
return NumberPass;
}

}
}
``````

Mitja Bonca 557

Why dont you tell us exactly what is troubling you. You are the one who needs it to be done, not we.
And you came with a manner, like we have to correct it, so dont expect from any of us to do the whole code instead of you. We are here to help, not to do the code instead of you.

------

One thing to mention, your Students class has no constructor, so you cannot pass any argument to ti, like you did:

``````  M[i] = new Students(n); //incorrect
//correct way according to your code is:
M[i] = new Students();
``````

One more thing, you better needa course class, and a grate.
Because one student has one or more courses, and each course can have one or more grades.
If you want to make it right.
Else tell your teacher she needs some more work to do :)

Freedom*

ok. the main class is right for sure. if there there are mistakes are at the other classes. (Students & Grades).

i didn't use any constructor in my class because i have the Set&gets to give values to my variables. do i have to use always constructors?

also, i need your help with the the arrays... i don't know how to use them.

bleedi 3

The getters and setters are only for the variables. If you want to create an object, you always need a constructor.

As with the arrays, what is it you want to achieve? If you are having trouble with understanding the principles of arrays, I suggest you to read through your course material. :)

Mitja Bonca 557

The getters and setters are only for the variables. If you want to create an object, you always need a constructor.

No, not true. Constructor is just some method (like all others) that are access before any other. Only the static constructor is called before it (but this is not out debate now).

As said, you dont need not get,set accessors, nor constructor(s) of a class. You can simply have fields (like you have) and public (or private) methods. Public can be access from other classes, while private cannot (only from inside this class. There are even protrected members of a class, that can be access from derived classes (from this one).

Freedom*

well, i know that we define an array like this for example

int array[]=new int [20]

and we can use it like this

for(int i=0; i<20; i++)
array[i]= something;

but the array that i used in the problem generates an object, i think. right? so, i don't know how i can put my information in it.

sorry for the bad english. hope you can understand what i'm trying to say

Freedom*

how can i use this?

``````int[] TheArray = new int[20]; //Declaring TheArray to hold 20 objects

TheArray[0] = 5; //Arrays always start at 0, so 0-19 in this case.
TheArray[1] = 10;
TheArray[2] = 15;

//Reading from the first entry in TheArray
Console.WriteLine(TheArray[0]);

foreach(int in TheArray)
{
Console.WriteLine(int);
}
``````

Hope that explains it simply :)

Freedom*

That would create an array of 'Grades'

Edit: Completely mis-understood the last bit, its covered in bleedi's post below

bleedi 3

No, not true. Constructor is just some method (like all others) that are access before any other. Only the static constructor is called before it (but this is not out debate now).

In the case where you don't explicitly specify a constructor, a default one will be generated, which just instantiates a new object from the class without any parameters or user-defined initialization.

As for the array problem, think of the 'int' example you mentioned as an object. It's not an object, but the object arrays work very similarly.

``````Grade[] grades = new Grade[20];

for(int i = 0; i < 20; ++i) {
}
``````

This would generate 20 'Grade' objects. Then you can access them like this:

``````grades[5].DoSomething();
``````

Freedom*

ok guys. thank you for your help and time. i'll try it more :)