Advertisement
eitherlast

помогите

Dec 4th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. class Student : IComparable
  2.     {
  3.     string lastName, firstName;
  4.     int groupNumber;
  5.     static int[] progress = new int[5];
  6.  
  7.     public Student() { }
  8.  
  9.     public static int[] Progress
  10.     {
  11.         get
  12.         {
  13.             return progress;
  14.         }
  15.         set
  16.         {
  17.             progress = value;
  18.         }
  19.     }
  20.  
  21.     public Student(string lastName, string firstName, int groupNumber, int[] progress)
  22.     {
  23.         this.lastName = lastName;
  24.         this.firstName = firstName;
  25.         this.groupNumber = groupNumber;
  26.     }
  27.  
  28.     static double MediumGrade(int[] progress)
  29.     {
  30.         double medGrade = 0.0;
  31.         for (int i = 0; i < progress.Length; i++)
  32.         {
  33.             medGrade = medGrade + progress[i];
  34.         }
  35.         return medGrade / progress.Length;
  36.     }
  37.  
  38.     double medGrade = MediumGrade(Progress);
  39.  
  40.    
  41.     public int CompareTo(object obj)
  42.     {
  43.         if (obj == null) return 1;
  44.         Student s1 = obj as Student;
  45.         if (s1 != null)
  46.         {
  47.             return this.medGrade.CompareTo(s1.medGrade);
  48.         }
  49.         else throw new NotImplementedException ();
  50.     }
  51. }
  52.  
  53.  
  54. class Program
  55.     {
  56.        
  57.  
  58.         static void Main(string[] args)
  59.         {
  60.         Student s = new Student("Иванов", "Иван", 3115, new[] { 5, 4, 5, 5, 3 });
  61.         Student[] st = new Student[3];
  62.         st[0] = s;
  63.         Student n = new Student("Нотова", "Ната", 3111, new[] { 5, 5, 4, 4, 5 });
  64.         Student k = new Student("Котов", "Котя", 324, new[] { 4, 5, 4, 4, 5 });
  65.         st[1] = n;
  66.         st[2] = k;
  67.         Console.WriteLine(n.CompareTo(s));
  68.  
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement