Класс "Студент" и "Студенческая группа" - C#
Формулировка задачи:
Класс «СТУДЕНТ» содержит закрытые поля: номер студенческого билета, фамилия, имя, отчество, дата рождения, массив из пяти оценок и метод подсчета среднего балла. Класс «СТУДЕНЧЕСКАЯ ГРУППА» содержит закрытые поля: название группы, курс, объекты класса студент, метод подсчета среднего балла для группы и метод вывода списка студентов, отсортированный по фамилиям в алфавитном порядке.
Помогите пожалуйста, очень срочно нужно.
Решение задачи: «Класс "Студент" и "Студенческая группа"»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CyberF
- {
- class Student
- {
- public string Card;
- public string FirstName;
- public string LastName;
- public string MiddleName;
- public DateTime BirthDay;
- public int[] Evaluations = new int[5];
- public Student(string card, string firstName, string lastName, string middleName, DateTime birthDay, int[] evaluations)
- {
- Card = card;
- FirstName = firstName;
- LastName = lastName;
- MiddleName = middleName;
- BirthDay = birthDay;
- Evaluations = evaluations;
- }
- public double GetAverageScore() => Evaluations.Average();
- public override string ToString()
- {
- return $"#{Card} {LastName} {FirstName.Substring(0, 1)}. {MiddleName.Substring(0, 1)}. [Average score: {GetAverageScore():N2}]";
- }
- }
- class StudentGroup
- {
- List<Student> _students = new List<Student>();
- public string Name;
- public string Course;
- public StudentGroup(string name, string course, List<Student> students)
- {
- Name = name;
- Course = course;
- _students.AddRange(students);
- }
- public double GetAverageScore()
- {
- return _students.Average(x => x.GetAverageScore());
- }
- public IEnumerable<string> SortByLastName()
- {
- foreach (var item in _students.OrderBy(x => x.LastName))
- {
- yield return item.ToString();
- }
- }
- public override string ToString()
- {
- return $"Group: {Name}, course {Course}. Number of students: {_students.Count}";
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> students = new List<Student>()
- {
- new Student("1", "Alexey", "Frolov", "Igorevich", new DateTime(1990, 11, 2), new int[] { 3, 4, 4, 5, 3}),
- new Student("2", "Sergey", "Semenov", "Alexeevich", new DateTime(1992, 1, 12), new int[] { 4, 3, 3, 3, 4}),
- new Student("3", "Andrey", "Volkov", "Konstantinovich", new DateTime(1993, 10, 6), new int[] { 3, 5, 4, 4, 3}),
- new Student("4", "Ilya", "Ivanov", "Igorevich", new DateTime(1991, 8, 19), new int[] { 3, 4, 4, 5, 4}),
- new Student("5", "Arseniy", "Kot", "Arkadievich", new DateTime(1990, 6, 22), new int[] { 4, 5, 4, 3, 4}),
- new Student("6", "Pavel", "Fedorov", "Dmitrievich", new DateTime(1992, 5, 11), new int[] { 3, 5, 4, 5, 5})
- };
- Console.WriteLine("Students without sorting:");
- foreach (var student in students)
- {
- Console.WriteLine(student);
- }
- StudentGroup group = new StudentGroup("CyberF", "1", students);
- Console.WriteLine($"\n{group}" +
- $"\nAverage score of the group: {group.GetAverageScore():N2}.");
- Console.WriteLine("\nSorted students by lastname:");
- foreach (var student in group.SortByLastName())
- {
- Console.WriteLine(student);
- }
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д