Класс "Студент" и "Студенческая группа" - C#

Узнай цену своей работы

Формулировка задачи:

Класс «СТУДЕНТ» содержит закрытые поля: номер студенческого билета, фамилия, имя, отчество, дата рождения, массив из пяти оценок и метод подсчета среднего балла. Класс «СТУДЕНЧЕСКАЯ ГРУППА» содержит закрытые поля: название группы, курс, объекты класса студент, метод подсчета среднего балла для группы и метод вывода списка студентов, отсортированный по фамилиям в алфавитном порядке. Помогите пожалуйста, очень срочно нужно.

Решение задачи: «Класс "Студент" и "Студенческая группа"»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CyberF
  6. {
  7.     class Student
  8.     {
  9.         public string Card;
  10.         public string FirstName;
  11.         public string LastName;
  12.         public string MiddleName;
  13.         public DateTime BirthDay;
  14.         public int[] Evaluations = new int[5];
  15.  
  16.         public Student(string card, string firstName, string lastName, string middleName, DateTime birthDay, int[] evaluations)
  17.         {
  18.             Card = card;
  19.             FirstName = firstName;
  20.             LastName = lastName;
  21.             MiddleName = middleName;
  22.             BirthDay = birthDay;
  23.             Evaluations = evaluations;
  24.         }
  25.  
  26.         public double GetAverageScore() => Evaluations.Average();
  27.  
  28.         public override string ToString()
  29.         {
  30.             return $"#{Card} {LastName} {FirstName.Substring(0, 1)}. {MiddleName.Substring(0, 1)}. [Average score: {GetAverageScore():N2}]";
  31.         }
  32.     }
  33.  
  34.     class StudentGroup
  35.     {
  36.         List<Student> _students = new List<Student>();
  37.         public string Name;
  38.         public string Course;
  39.        
  40.         public StudentGroup(string name, string course, List<Student> students)
  41.         {
  42.             Name = name;
  43.             Course = course;
  44.             _students.AddRange(students);
  45.         }
  46.  
  47.         public double GetAverageScore()
  48.         {
  49.             return _students.Average(x => x.GetAverageScore());
  50.         }
  51.  
  52.         public IEnumerable<string> SortByLastName()
  53.         {
  54.             foreach (var item in _students.OrderBy(x => x.LastName))
  55.             {
  56.                 yield return item.ToString();
  57.             }
  58.         }
  59.  
  60.         public override string ToString()
  61.         {
  62.             return $"Group: {Name}, course {Course}. Number of students: {_students.Count}";
  63.         }
  64.     }
  65.  
  66.     class Program
  67.     {
  68.         static void Main(string[] args)
  69.         {
  70.             List<Student> students = new List<Student>()
  71.             {
  72.                 new Student("1", "Alexey", "Frolov", "Igorevich", new DateTime(1990, 11, 2), new int[] { 3, 4, 4, 5, 3}),
  73.                 new Student("2", "Sergey", "Semenov", "Alexeevich", new DateTime(1992, 1, 12), new int[] { 4, 3, 3, 3, 4}),
  74.                 new Student("3", "Andrey", "Volkov", "Konstantinovich", new DateTime(1993, 10, 6), new int[] { 3, 5, 4, 4, 3}),
  75.                 new Student("4", "Ilya", "Ivanov", "Igorevich", new DateTime(1991, 8, 19), new int[] { 3, 4, 4, 5, 4}),
  76.                 new Student("5", "Arseniy", "Kot", "Arkadievich", new DateTime(1990, 6, 22), new int[] { 4, 5, 4, 3, 4}),
  77.                 new Student("6", "Pavel", "Fedorov", "Dmitrievich", new DateTime(1992, 5, 11), new int[] { 3, 5, 4, 5, 5})
  78.             };
  79.  
  80.             Console.WriteLine("Students without sorting:");
  81.             foreach (var student in students)
  82.             {
  83.                 Console.WriteLine(student);
  84.             }
  85.  
  86.             StudentGroup group = new StudentGroup("CyberF", "1", students);
  87.  
  88.             Console.WriteLine($"\n{group}" +
  89.                 $"\nAverage score of the group: {group.GetAverageScore():N2}.");
  90.  
  91.             Console.WriteLine("\nSorted students by lastname:");
  92.             foreach (var student in group.SortByLastName())
  93.             {
  94.                 Console.WriteLine(student);
  95.             }
  96.         }
  97.     }
  98. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 3.786 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы