Alright, so this is the exercise:
Define a class named student,
containing three grades of students.
The class will have a function that
calculates the grades average. Now,
define a class named student1 which
will be derived from student and will
add a function to calculate the sum of
the grades.In the Main program, define
a student variable and object of type
student1. Perform placement of the
object to variable and run the
function of student1.
Note: This is not homework, I’m learning this my own.
This is the code:
class Student
{
protected int grade1, grade2, grade3;
public Student(int grade1, int grade2, int grade3)
{
this.grade1 = grade1;
this.grade2 = grade2;
this.grade3 = grade3;
}
public double Average()
{
return (grade1 + grade2 + grade3) / 3;
}
}
class Student1 : Student
{
public Student1(int grade1, int grade2, int grade3)
: base(grade1, grade2, grade3)
{
}
public double Sum()
{
return grade1 + grade2 + grade3;
}
}
class Program
{
static void Main(string[] args)
{
}
}
I don’t really know what to do in the main class, how do I perform this placement and also, I wanted to know what’s the benefit of doing it, let me know if I have mistakes so far, thanks alot.
OK: I guess this is what they’re looking for, although the english is a little ropey:
1) Declare student variable
2) Declare Student1 object
3) Perform placement of object to variable:
4) Run the function (Note you’ll have to cast s to Student1 type to access the Type specific function Sum)