CSD203_-_PE1_-_FA2024_2925.webp
G

CSD203_-_PE1_-_FA2024_2925.webp

Zoom

(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.)
150%
7
static void Notify (int oldNumber, int newNumber)
8
{
9
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
c.AddStudent(s, 7.5);
16
c.AddStudent(new Student(2, "Hoa"), 7.8);
17
c.AddStudent(new Student(3, "Vinh"), 7.4);Console.WriteLine(c);
18
19
c.RemoveStudent(2);
20
Console.WriteLine("\n---After remove:");
21
Console.WriteLine(c);
22
23
24
25
Console.WriteLine("\n----After add event handler:");
c.OnNumberOfStudentChange += Notify;
c.AddStudent(new Student(4, "Hoang Anh"), 8);
26
c.RemoveStudent(1);
27
Console.WriteLine(c);
28
Console.ReadLine();
29
}
Figure 1: Main function
Close
Chưa có bình luận nào.

Thông tin

Category
CSD203
Thêm bởi
graceful_beauty1
Ngày thêm
Lượt xem
1,188
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Image metadata

Filename
CSD203_-_PE1_-_FA2024_2925.webp
File size
258.7 KB
Dimensions
1920px x 867px

Share this media

Back
Bên trên Bottom