Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ООП
- {
- class Program
- {
- static void Main(string[] args)
- {
- Archive archive = new Archive(new List<Patient> {
- new Patient("ФИО_0", 35,"грипп"),
- new Patient("ФИО_1", 19,"учит питон"),
- new Patient("ФИО_2", 24,"ангина"),
- new Patient("ФИО_3", 67,"диабет"),
- new Patient("ФИО_4", 45,"ангина"),
- new Patient("ФИО_5", 72,"простатит"),
- new Patient("ФИО_6", 26,"сотрясение мозга"),
- new Patient("ФИО_7", 1,"смотрит хауди хо и дударя"),
- new Patient("ФИО_8", 57,"ангина"),
- new Patient("ФИО_9", 41,"плоскоземельщик"),
- });
- archive.Work();
- }
- }
- class Patient
- {
- public string Initials { get; private set; }
- public int Age { get; private set; }
- public string Disease { get; private set; }
- public Patient(string initials, int age, string disease)
- {
- Initials = initials;
- Age = age;
- Disease = disease;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"{Initials} | {Age} лет | заболевание: {Disease}");
- }
- }
- class Archive
- {
- private List<Patient> _patients;
- public Archive(List<Patient> patients)
- {
- _patients = patients;
- }
- public void Work()
- {
- bool IsOpen = true;
- string userInput;
- while (IsOpen)
- {
- Console.Clear();
- Console.Write("1. Отсортировать всех больных по фио\n2. Отсортировать всех больных по возрасту\n3. Вывести больных с определенным заболеванием\nВведите номер пункта: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "1":
- SortAtInitials();
- break;
- case "2":
- SortAtAge();
- break;
- case "3":
- ShowByDisease();
- break;
- default:
- Console.Write("Такой команды нет!");
- break;
- }
- Console.ReadKey();
- }
- }
- private void SortAtInitials()
- {
- var result = _patients.OrderBy(pacient => pacient.Initials).ToList();
- ShowPatients(result);
- }
- private void SortAtAge()
- {
- var result = _patients.OrderByDescending(pacient => pacient.Age).ToList();
- ShowPatients(result);
- }
- private void ShowByDisease()
- {
- Console.Write("Введите заболевание, для вывода пациентов с ним: ");
- string disease = Console.ReadLine();
- var result = _patients.Where(pacient => pacient.Disease == disease).ToList();
- ShowPatients(result);
- }
- private void ShowPatients(List<Patient> patients)
- {
- foreach (var patient in patients)
- {
- patient.ShowInfo();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement