RMarK0

Макса задание студенты

Apr 25th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.21 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Student
  6.     {
  7.         public string Name;
  8.         public double[] Marks = new double[5];
  9.         public double avgMark;
  10.  
  11.         public Student(string name, double[] marks)
  12.         {
  13.             Name = name;
  14.             Marks = marks;
  15.  
  16.             double temp = 0;
  17.             for (int i = 0; i < Marks.Length; i++)
  18.             {
  19.                 temp += Marks[i];
  20.             }
  21.  
  22.             avgMark = (temp / Marks.Length);
  23.         }
  24.  
  25.         public static void Sort(ref Student[] array)
  26.         {
  27.             for (int i = 0; i < array.Length; i++)
  28.             {
  29.                 for (int ii = 0; ii < array.Length-1; ii++)
  30.                 {
  31.                     if (array[ii + 1].avgMark > array[ii].avgMark)
  32.                     {
  33.                         Student temp = array[ii + 1];
  34.                         array[ii + 1] = array[ii];
  35.                         array[ii] = temp;
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.  
  41.     }
  42.  
  43.     class Program
  44.     {
  45.         static void DeleteBad(Student student) // удаление тех кто не сдал 3 и более экзаменов
  46.         {
  47.             Console.WriteLine("Студент {0} не сдал 3 и более экзаменов", student.Name);
  48.         }
  49.  
  50.         static void WriteTwoArrays(Student[] array) // успевающие и не сдавшие 1 экз
  51.         {
  52.             foreach (Student student in array)
  53.             {
  54.                 int temp = 0;
  55.                 foreach (var mark in student.Marks)
  56.                 {
  57.                     if (mark <= 2)
  58.                         temp++;
  59.                 }
  60.                 if (temp >= 3)
  61.                     DeleteBad(student);
  62.                 else
  63.                 {
  64.                     Console.Write("{0} - ", student.Name);
  65.                     foreach (var mark in student.Marks)
  66.                     {
  67.                         if (mark <= 2)
  68.                             Console.ForegroundColor = ConsoleColor.Red;
  69.                         Console.Write("{0} ",mark);
  70.                         Console.ResetColor();
  71.                     }
  72.                     Console.WriteLine("\t {0}", student.avgMark);
  73.  
  74.                 }
  75.             }
  76.  
  77.         }
  78.         static void Main(string[] args)
  79.         {
  80.             const int n = 4;
  81.             Student[] StudentArray = new Student[n];
  82.             StudentArray[0] = new Student("Vanya", new double[5] {4,3,4,2,4});
  83.             StudentArray[1] = new Student("Petya", new double[5] {2,3,3,2,2});
  84.             StudentArray[2] = new Student("Vova", new double[5] {5,5,4,4,5});
  85.             StudentArray[3] = new Student("Vasya", new double[5] {4,3,4,4,4});
  86.  
  87.             foreach (var student in StudentArray)
  88.             {
  89.                 Console.Write("{0} - ", student.Name);
  90.                 foreach (var mark in student.Marks)
  91.                 {
  92.                     Console.Write("{0} ", mark);
  93.                 }
  94.                 Console.WriteLine("\t {0}", student.avgMark);
  95.             }
  96.             Student.Sort(ref StudentArray);
  97.  
  98.             Console.WriteLine();
  99.             WriteTwoArrays(StudentArray);
  100.             Console.Read();
  101.         }
  102.     }
  103. }
Add Comment
Please, Sign In to add comment