-
Notifications
You must be signed in to change notification settings - Fork 0
/
29.02.24.cs
74 lines (60 loc) · 2.33 KB
/
29.02.24.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp28
{
class Student
{
public string FirstName { get; set; }
public string LastName { get; set; }
public double AverageGrade { get; set; }
}
class StudentList
{
private List<Student> students = new List<Student>();
public void AddStudent(Student student)
{
students.Add(student);
}
public void RemoveStudent(Student student)
{
students.Remove(student);
}
public void ProcessStudents(StudentActionDelegate action)
{
foreach (var student in students)
{
action(student);
}
}
}
delegate void StudentActionDelegate(Student student);
class Program
{
static void PrintStudentInfo(Student student)
{
Console.WriteLine($"Студент: {student.FirstName} {student.LastName}, Средняя оценка: {student.AverageGrade}");
}
static void IncreaseAverageGrade(Student student)
{
student.AverageGrade += 0.5;
}
static void Main(string[] args)
{
StudentList studentList = new StudentList();
studentList.AddStudent(new Student { FirstName = "John", LastName = "Doe", AverageGrade = 4.0 });
studentList.AddStudent(new Student { FirstName = "Alice", LastName = "Smith", AverageGrade = 3.5 });
studentList.AddStudent(new Student { FirstName = "Bob", LastName = "Johnson", AverageGrade = 3.7 });
StudentActionDelegate printDelegate = new StudentActionDelegate(PrintStudentInfo);
StudentActionDelegate increaseGradeDelegate = new StudentActionDelegate(IncreaseAverageGrade);
Console.WriteLine("Исходная информация об ученике: ");
studentList.ProcessStudents(printDelegate);
Console.WriteLine("\nПосле повышения средних оценок:");
studentList.ProcessStudents(increaseGradeDelegate);
studentList.ProcessStudents(printDelegate);
Console.ReadLine();
}
}
}