Advertisement
Guest User

Untitled

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