107 309
Assignments Done
98.9%
Successfully Done
In March 2023

# Answer to Question #146323 in C# for KAMRAN

Question #146323
We want to calculate the total marks of each student of a class in Physics,Chemistry and Mathematics and the average marks of the class. The number of students in the class are entered by the user. Create a class named Marks with data members for roll number, name and marks. Create three other classes inheriting the Marks class, namely Physics, Chemistry and Mathematics, which are used to define marks in individual subject of each student. Roll number of each student will be generated automatically.
1
2020-11-24T05:44:50-0500
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of students in the class: ");

Physics physics = new Physics(count);
Chemistry chemistry = new Chemistry(count);
Mathematic mathematic = new Mathematic(count);

Console.WriteLine(physics);
Console.WriteLine(chemistry);
Console.WriteLine(mathematic);

Console.WriteLine($"Physics Class: Total: {physics.GetTotal()}, Average: {physics.GetTotal() / count}"); Console.WriteLine($"Chemistry Class: Total: {chemistry.GetTotal()}, Average: {chemistry.GetTotal() / count}");
Console.WriteLine($"Mathematic Class: Total: {mathematic.GetTotal()}, Average: {mathematic.GetTotal() / count}"); Console.ReadKey(); } } class Mark { static readonly Random random = new Random(); public int RollNumber { get; set; } public string Name { get; set; } public double[] Marks { get; set; } protected void GenerateMarks(int count) { Marks = new double[count]; for (int i = 0; i < count; i++) { Marks[i] = random.Next(1, 5); } } public double GetTotal() { return Marks.Sum(); } public override string ToString() { return$"Name: {Name}, Marks: [{string.Join(" ", Marks)}]";
}
}

class Physics : Mark
{
public Physics(int count)
{
Name = "Physics";
GenerateMarks(count);
}
}

class Chemistry: Mark
{
public Chemistry(int count)
{
Name = "Chemistry";
GenerateMarks(count);
}
}

class Mathematic: Mark
{
public Mathematic(int count)
{
Name = "Mathematic";
GenerateMarks(count);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!