Zoom
(0.5 point) The public override function ToString() to return string that present all information about the course: id, title, list of students and their GPA. (The code on line 18, 21, 27 of function Main below must work).
(0.5 point) The public event OnNumberOfStudentChange that is raised when the number of students of the course changes (it means when adding or removing student).
With the main function given in Figure 1 below, your code must have the same result as the Figure 2.
(You can find this code in the Given Materials.)
static void Notify(int oldNumber, int newNumber)
{
Console.WriteLine($"Number of student has changed from (oldNumber} to {newNumber}.");}
10
O references
11
static void Main(string[] args)
12
{
13
Student s new Student(1, "Trung");
14
Course c new Course (1, "PRN211_Sum21");
15
16
17
18
19
20
21
22
23
24
25
26
27
28
c.AddStudent(s, 7.5);
c.AddStudent(new Student(2, "Hoa"), 7.8);
c.AddStudent(new Student(3, "Vinh"), 7.4);
Console.WriteLine(c);c.RemoveStudent(2);
Console.WriteLine("-After remove:");
Console.WriteLine(c);
Console.WriteLine("-After add event handler:");
c.OnNumberOfStudentChange += Notify;
c.AddStudent(new Student(4, "Hoang Anh"), 8);
c.RemoveStudent(1);
Console.WriteLine(c);
Console.ReadLine();
29
}
The output should be the same as below
+ 100%
Figure 1: Main function
Close