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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
| using System;
using System.Collections.Generic;
using System.Timers;
using System.IO;
namespace ConsoleApp15
{
enum Education
{
IBM, IU, SM, RK, RL, SGN
}
public class Person : IComparable
{
protected string Name;
protected string Family;
protected byte Age;
public Person()
{
Name = "";
Family = "";
Age = 1;
}
public Person(string _f, string _n, byte _a)
{
Family = _f;
Name = _n;
Age = _a;
}
public string StudentFamily
{
get
{
return Family;
}
set
{
if (value != "") { Family = value; };
}
}
public string StudentName
{
get
{
return Name;
}
set
{
if (value != "") { Name = value; };
}
}
public byte StudentAge
{
get
{
return Age;
}
set
{
if (value != 1) { Age = value; };
}
}
public int CompareTo(object obj)
{
Person p = (Person)obj;
if (this.GetHashCode() < p.GetHashCode()) return -1;
else if (this.GetHashCode() == p.GetHashCode()) return 0;
else return 1;
}
public override bool Equals(object obj)
{
if (obj == null)
{
return false;
}
else
{
Person local = (Person)obj;
if (this.Family.Equals(local.Family) &&
this.Name.Equals(local.Name) &&
this.Age.Equals(local.Age))
{ return true; }
else
{ return false; }
}
}
public override int GetHashCode()
{
return this.Family.Length + this.Name.Length + Age;
}
class Test
{
public DateTime DateTest;
public byte TypeTest;
public string NameTest;
public byte MarkTest;
public Test()
{
this.DateTest = new DateTime(1990, 01, 01);
this.TypeTest = 0;
this.NameTest = "";
this.MarkTest = 0;
}
public Test(DateTime d, byte t, string n, byte m)
{
this.DateTest = d;
this.TypeTest = t;
this.NameTest = n;
this.MarkTest = m;
}
}
class Student : Person, IComparable
{
protected System.Collections.Generic.List<Test> Exams;
//protected string Test;
public Education Inst;
public string NameG;
public Student() : base()
{
//this.Test = "";
this.Exams = new List<Test>();
this.NameG = "";
System.Random i = new Random();
}
public Student(string d, string e, byte b, string n, int i) : base(d, e, b)
{
this.NameG = n;
System.Random p = new Random();
p.Next();
this.Exams = new List<Test>();
Exams.Add(new Test(new DateTime(), 0, "Algebra", (byte)p.Next(0,100)));
Exams.Add(new Test(new DateTime(), 0, "Informatics", (byte)p.Next(0,100)));
Exams.Add(new Test(new DateTime(), 0, "BI", (byte)p.Next(0,100)));
Exams.Add(new Test(new DateTime(), 1, "Math", (byte)p.Next(0,100)));
Exams.Add(new Test(new DateTime(), 1, "PE", (byte)p.Next(0,100)));
Exams.Add(new Test(new DateTime(), 1, "History", (byte)p.Next(0,100)));
//Random pp = new Random();
Inst = (Education)i;
}
public List<Test> ExamsList
{
get { return Exams; }
set { Exams = value; }
}
public double AverageScore()
{
double avg = 0;
foreach (Test t in Exams)
{
avg+=t.MarkTest;
}
return avg / Exams.Count;
}
}
class StudentCollection
{
protected System.Collections.Generic.List<Student> ListStudents;
public StudentCollection()
{
this.ListStudents = new List<Student>();
p = new Random();
}
Random p;
public void AddDefaults()
{
this.ListStudents.Add(new Student("White", "Elison", 20, "First",p.Next(0,5)));
this.ListStudents.Add(new Student("Black", "Tom", 19, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Mountain", "Jack", 18, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Fox", "Andrew", 20, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Little", "Nina", 21, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Fisher", "Olivia", 19, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Apple", "Madisson", 18, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Tiyson", "Rachel", 19, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Swan", "Adeline", 20, "First", p.Next(0, 5)));
this.ListStudents.Add(new Student("Simson", "Fill",
19, "First", p.Next(0, 5)));
}
void AddStudents(params Student[] Stds)
{
this.ListStudents.AddRange(Stds);
}
public double MaxAverageScore()
{
double max = ListStudents[0].AverageScore();
foreach (Student t in ListStudents)
{
if (max < t.AverageScore())
max = t.AverageScore();
}
return max;
}
public override string ToString()
{
string result = "";
foreach (Student s in ListStudents)
{
string tests;
string exams = "";
string passes = "";
foreach (Test t in s.ExamsList)
{
if (t.TypeTest == 0)
exams += t.NameTest + " " + t.MarkTest.ToString() + " ";
else
passes += exams += t.NameTest + " " + t.MarkTest.ToString() + " ";
}
tests = "Exams:" + exams + "\nTests:" + passes;
result +="Name: " + s.Family +" "+ s.Name+ "\nAge: "+ s.Age.ToString() + "\nFaculty: " + Enum.GetName(typeof(Education),(int)s.Inst) + "\nGroup: " + s.NameG + "\n" + tests + "\n\n";
}
return result;
}
public string ToShortString()
{
return this.ListStudents.ToString();
}
public List<Student> SortStudents()
{
ListStudents.Sort();
return ListStudents;
}
public StudentCollection FacultyFilter(int i)
{
StudentCollection lst = new StudentCollection();
foreach (Student s in ListStudents)
{
if ((int)s.Inst == i)
{
lst.ListStudents.Add(s);
}
}
return lst;
}
}
class TestCollections
{
private System.Collections.Generic.List<Person> ListPerson=new List<Person>();
private System.Collections.Generic.List<string> ListString=new List<string>();
private System.Collections.Generic.Dictionary<Person, Student> DictionaryPS;
private System.Collections.Generic.Dictionary<string, Student> DictionarySS;
private Dictionary<int, Student> d;
public TestCollections(int count)
{
d = new Dictionary<int, Student>();
for (int i = 0; i < count; i++)
{
d.Add(i, AddTC(i));
}
}
public void TestTime()
{
for (int i = 0; i < 100; i++)
{
ListPerson.Add(new Person("Surname"+i,"Name"+i,(byte)i));
ListString.Add("Surname" + i + " " + "Name");
}
// Timer tm = new Timer(1);
DateTime tm = DateTime.Now;
ListPerson.Find(new Predicate<Person>((p)=>(p == new Person("Surname99", "Name99", 99))));
DateTime tm1 = DateTime.Now;
Console.WriteLine("Time to find in ListPerson:" +(tm - tm1).ToString());
DateTime dt = DateTime.Now;
ListString.Find(new Predicate<String>((p) => (p == "Surname99 Name99")));
DateTime dt2 = DateTime.Now;
Console.WriteLine("Time to find in ListString:" + (dt - dt2).ToString());
}
private Student add()
{
throw new NotImplementedException();
}
public static Student AddTC(int a)
{
Student st = new Student();
return (st);
}
}
class StdCFamily : Comparer<Student>
{
public override int Compare(Student s1, Student s2)
{
return String.Compare(s1.Family, s2.Family);
}
}
class StdCAge : Comparer<Student>
{
public override int Compare(Student s1, Student s2)
{
if (s1.Age > s2.Age)
return 1;
else if (s1.Age < s2.Age)
return -1;
else
return 0;
}
}
class StdCMark : Comparer<Student>
{
public override int Compare(Student s1, Student s2)
{
if (s1.AverageScore() > s2.AverageScore())
return 1;
else if (s1.AverageScore() < s2.AverageScore())
return -1;
else
return 0;
}
}
class Program
{
static void Main(string[] args)
{
StudentCollection sc = new StudentCollection();
sc.AddDefaults();
Console.WriteLine(sc.ToString());
Console.WriteLine("\nMaximum Average Score:");
Console.WriteLine(sc.MaxAverageScore());
Console.WriteLine("\nStudents of the second faculty:");
Console.WriteLine(sc.FacultyFilter(4).ToString());
TestCollections tc = new TestCollections(100);
tc.TestTime();
Console.ReadLine();
}
}
} |