Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Student : IComparable
- {
- string lastName, firstName;
- int groupNumber;
- static int[] progress = new int[5];
- public Student() { }
- public static int[] Progress
- {
- get
- {
- return progress;
- }
- set
- {
- progress = value;
- }
- }
- public Student(string lastName, string firstName, int groupNumber, int[] progress)
- {
- this.lastName = lastName;
- this.firstName = firstName;
- this.groupNumber = groupNumber;
- }
- static double MediumGrade(int[] progress)
- {
- double medGrade = 0.0;
- for (int i = 0; i < progress.Length; i++)
- {
- medGrade = medGrade + progress[i];
- }
- return medGrade / progress.Length;
- }
- double medGrade = MediumGrade(Progress);
- public int CompareTo(object obj)
- {
- if (obj == null) return 1;
- Student s1 = obj as Student;
- if (s1 != null)
- {
- return this.medGrade.CompareTo(s1.medGrade);
- }
- else throw new NotImplementedException ();
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Student s = new Student("Иванов", "Иван", 3115, new[] { 5, 4, 5, 5, 3 });
- Student[] st = new Student[3];
- st[0] = s;
- Student n = new Student("Нотова", "Ната", 3111, new[] { 5, 5, 4, 4, 5 });
- Student k = new Student("Котов", "Котя", 324, new[] { 4, 5, 4, 4, 5 });
- st[1] = n;
- st[2] = k;
- Console.WriteLine(n.CompareTo(s));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement