class Program
{
static void Main(string[] args)
{
Console.Write("Enter the number of students in the class: ");
int count = int.Parse(Console.ReadLine());
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);
}
}
Comments
Leave a comment