Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- //Написать программу ,которая хранит и рассчитывает сред. арифметическую оценку студента.
- //Реализовать поиск студентов по этому среднему баллу .
- //Выберите корректные структуры данных и типы для решения задачи.
- namespace Student
- {
- class Program
- {
- public struct Student
- {
- string Name;
- string Surname;
- public List<int> Balls;
- public Student(string name, string surnamr)
- {
- Name = name;
- Surname = surnamr;
- Balls = new List<int>();
- }
- public double GetMidBall()
- {
- double balls = 0;
- if (Balls.Count == 0) throw new Exception("Нет оценок");
- foreach (int ball in Balls)
- {
- balls += ball;
- }
- return balls/Balls.Count;
- }
- static void Main(string[] args)
- {
- List<Student> students = new List<Student>();
- Student Vasiljev = new Student("Василий", "Васильев");
- Vasiljev.Balls.AddRange(new int[] { 3, 4, 4, 5, 5});
- Student Ivanov = new Student("Иван", "Иванов");
- Ivanov.Balls.AddRange(new int[] { 3, 4, 4, 3, 5 });
- Student Petrov = new Student("Петр", "Петров");
- Petrov.Balls.AddRange(new int[] { 5, 5, 4, 5, 5 });
- students.Add(Vasiljev);
- students.Add(Ivanov);
- students.Add(Petrov);
- Console.WriteLine("Средний бал Васильева: " + Vasiljev.GetMidBall());
- Console.WriteLine("Средний бал Иванова: " + Ivanov.GetMidBall());
- Console.WriteLine("Средний бал Петрова: " + Petrov.GetMidBall());
- double rightBall = 4.8;
- Console.WriteLine("Cреднй балл " + rightBall + " у студента: " + Search (students,rightBall).Surname );
- }
- //Ищем студента с указанным баллом
- public static Student Search (List<Student> students, double rightBall)
- {
- for (int i = 0; i < students.Count; i++)
- {
- if (students[i].GetMidBall() == rightBall)
- return students[i];
- }
- return new Student(null, "студента с таким баллом нет");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement