-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentCollection.cs
More file actions
107 lines (95 loc) · 3.23 KB
/
StudentCollection.cs
File metadata and controls
107 lines (95 loc) · 3.23 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace lab1
{
class StudentCollection
{
private List<Student> _students = new List<Student>();
public List<Student> Students
{
get
{
return _students;
}
set
{
_students = value;
}
}
public void AddDefaults() //добавить некоторое число элементов типа Student для инициализации коллекции по умолчанию
{
for (int i = 0; i < 2; i++)
{
_students.Add(new Student());
}
}
public void AddStudents(params Student[] students) //добавление элементов
{
_students.AddRange(students);
}
public override string ToString() //перегруженный метод ToString
{
string StudentsString = "";
foreach (Student student in _students)
{
StudentsString = StudentsString + student.ToString() + "\n";
}
return StudentsString;
}
public string ToShortString() //перегруженный метод ToShortString
{
string StudentsString = "";
foreach (Student student in _students)
{
StudentsString = StudentsString + student.ToShortString() + "\n";
}
return StudentsString;
}
public void SortByLastName() //сортировка по фамилии
{
_students.Sort((x, y) => x.LastName.CompareTo(y.LastName));
}
public void SortByDateOfBirth() //сортировка по дате рождения
{
_students.Sort();
}
public void SortByGPA() //сортировка по среднему баллу
{
StudentComparer comp = new StudentComparer();
_students.Sort(comp);
}
public double MaxGPA //максимальный средний балл
{
get
{
if (_students.Count == 0)
{
return 0;
}
return _students.Max(student => student.GPA);
}
}
public IEnumerable<Student> GetSpecialists //находим специалистов
{
get
{
IEnumerable<Student> Specialists = _students.Where(student => student.DegreeOfEducation == Education.Specialist);
return Specialists;
}
}
public List<Student> AverageMarkGroup(double value) //находим студентов с заданным средним баллом
{
IEnumerable<IGrouping<double,Student>> StudentsWithGPA = _students.GroupBy(student => student.GPA);
foreach (IGrouping<double, Student> student in StudentsWithGPA)
{
if (student.Key == value)
{
return student.ToList<Student>();
}
}
return null;
}
}
}