Advertisement
Dr_Max_Experience

Task 3

Jul 25th, 2022 (edited)
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ООП
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Archive archive = new Archive(new List<Patient> {
  14.                 new Patient("ФИО_0", 35,"грипп"),
  15.                 new Patient("ФИО_1", 19,"учит питон"),
  16.                 new Patient("ФИО_2", 24,"ангина"),
  17.                 new Patient("ФИО_3", 67,"диабет"),
  18.                 new Patient("ФИО_4", 45,"ангина"),
  19.                 new Patient("ФИО_5", 72,"простатит"),
  20.                 new Patient("ФИО_6", 26,"сотрясение мозга"),
  21.                 new Patient("ФИО_7", 1,"смотрит хауди хо и дударя"),
  22.                 new Patient("ФИО_8", 57,"ангина"),
  23.                 new Patient("ФИО_9", 41,"плоскоземельщик"),
  24.             });
  25.  
  26.             archive.Work();
  27.         }
  28.     }
  29.  
  30.     class Patient
  31.     {
  32.         public string Initials { get; private set; }
  33.  
  34.         public int Age { get; private set; }
  35.  
  36.         public string Disease { get; private set; }
  37.  
  38.         public Patient(string initials, int age, string disease)
  39.         {
  40.             Initials = initials;
  41.             Age = age;
  42.             Disease = disease;
  43.         }
  44.  
  45.         public void ShowInfo()
  46.         {
  47.             Console.WriteLine($"{Initials} | {Age} лет | заболевание: {Disease}");
  48.         }
  49.     }
  50.  
  51.     class Archive
  52.     {
  53.         private List<Patient> _patients;
  54.  
  55.         public Archive(List<Patient> patients)
  56.         {
  57.             _patients = patients;
  58.         }
  59.  
  60.         public void Work()
  61.         {
  62.             bool IsOpen = true;
  63.             string userInput;
  64.  
  65.             while (IsOpen)
  66.             {
  67.                 Console.Clear();
  68.                 Console.Write("1. Отсортировать всех больных по фио\n2. Отсортировать всех больных по возрасту\n3. Вывести больных с определенным заболеванием\nВведите номер пункта: ");
  69.                 userInput = Console.ReadLine();
  70.  
  71.                 switch (userInput)
  72.                 {
  73.                     case "1":
  74.                         SortAtInitials();
  75.                         break;
  76.  
  77.                     case "2":
  78.                         SortAtAge();
  79.                         break;
  80.  
  81.                     case "3":
  82.                         ShowByDisease();
  83.                         break;
  84.  
  85.                     default:
  86.                         Console.Write("Такой команды нет!");
  87.                         break;
  88.                 }
  89.  
  90.                 Console.ReadKey();
  91.             }
  92.         }
  93.  
  94.         private void SortAtInitials()
  95.         {
  96.             var result = _patients.OrderBy(pacient => pacient.Initials).ToList();
  97.  
  98.             ShowPatients(result);
  99.         }
  100.  
  101.         private void SortAtAge()
  102.         {
  103.             var result = _patients.OrderByDescending(pacient => pacient.Age).ToList();
  104.  
  105.             ShowPatients(result);
  106.         }
  107.         private void ShowByDisease()
  108.         {
  109.             Console.Write("Введите заболевание, для вывода пациентов с ним: ");
  110.             string disease = Console.ReadLine();
  111.  
  112.             var result = _patients.Where(pacient => pacient.Disease == disease).ToList();
  113.  
  114.             ShowPatients(result);
  115.         }
  116.  
  117.         private void ShowPatients(List<Patient> patients)
  118.         {
  119.             foreach (var patient in patients)
  120.             {
  121.                 patient.ShowInfo();
  122.             }
  123.         }
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement