Advertisement
Vlad_Savitskiy

Hospital

Jun 30th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CSLightFirst
  6. {
  7.     class Program
  8.     {
  9.         private static void Main()
  10.         {
  11.             List<Patient> patients = GeneratePatients();
  12.  
  13.             while (true)
  14.             {
  15.                 Console.WriteLine("Выберите, что Вам нужно сделать:\n" +
  16.                                   "  1 - Отсортировать всех больных по ФИО\n" +
  17.                                   "  2 - Отсортировать всех больных по возрасту\n" +
  18.                                   "  3 - Вывести больных с определенным заболеванием\n");
  19.                 Console.Write("Ваш ответ: ");
  20.  
  21.                 switch (Console.ReadLine())
  22.                 {
  23.                     case "1":
  24.                         MakeFullNameSelection(patients);
  25.                         break;
  26.                     case "2":
  27.                         MakeAgeSelection(patients);
  28.                         break;
  29.                     case "3":
  30.                         MakeDiseaseSelection(patients);
  31.                         break;
  32.                     default:
  33.                         Console.WriteLine("Некорректное введенное значение, попробуйте ещё раз...");
  34.                         break;
  35.                 }
  36.             }
  37.         }
  38.  
  39.         private static void MakeFullNameSelection(IEnumerable<Patient> patients)
  40.         {
  41.             ShowSelection(
  42.                 patients.OrderBy(patient => patient.Surname).ThenBy(patient => patient.Name),
  43.                 "Пациенты, отсортированы по возрасту:\n");
  44.         }
  45.  
  46.         private static void MakeAgeSelection(IEnumerable<Patient> patients)
  47.         {
  48.             ShowSelection(
  49.                 patients.OrderBy(patient => patient.Age),
  50.                 "Пациенты, отсортированы по возрасту:\n");
  51.         }
  52.  
  53.         private static void MakeDiseaseSelection(IEnumerable<Patient> patients)
  54.         {
  55.             Console.Clear();
  56.             Console.Write("Введите болезнь, которую хотите найти: ");
  57.             string disease = Console.ReadLine();
  58.  
  59.             ShowSelection(patients.Where(patient => patient.Disease == disease), $"Пациенты с болезнью {disease}:\n");
  60.         }
  61.  
  62.         private static void ShowSelection(IEnumerable<Patient> selection, string text = "")
  63.         {
  64.             Console.Clear();
  65.             Console.WriteLine(text);
  66.  
  67.             foreach (Patient patient in selection)
  68.                 patient.ShowInfo();
  69.         }
  70.  
  71.         private static List<Patient> GeneratePatients()
  72.         {
  73.             Random rand = new Random();
  74.  
  75.             string[] names = { "Джон", "Хью", "Энн", "Джек", "Уил", "Марк", "Лиз", "Майкл", "Дэвис" };
  76.             string[] surnames = { "Сильвер", "Морган", "Смит", "Джонс", "Уильямс", "Сноу", "Миллер", "Борк" };
  77.             string[] diseases = { "ОРВИ", "Грипп", "ВИЧ", "Язва", "Корь", "Ветрянка", "Сифилис", "Оспа"};
  78.  
  79.             List<Patient> patients = new List<Patient>(rand.Next(10, 16));
  80.  
  81.             for (int i = 0; i < patients.Capacity; i++)
  82.                 patients.Add(new Patient(
  83.                     names[rand.Next(0, names.Length)],
  84.                     surnames[rand.Next(0, surnames.Length)],
  85.                     rand.Next(10, 71),
  86.                     diseases[rand.Next(0, diseases.Length)]));
  87.  
  88.             return patients;
  89.         }
  90.     }
  91.  
  92.     class Patient
  93.     {
  94.         public string Name { get; }
  95.         public string Surname { get; }
  96.         public int Age { get; }
  97.         public string Disease { get; }
  98.  
  99.         public Patient(string name, string surname, int age, string disease)
  100.         {
  101.             Name = name;
  102.             Surname = surname;
  103.             Age = age;
  104.             Disease = disease;
  105.         }
  106.  
  107.         public void ShowInfo()
  108.         {
  109.             Console.WriteLine($"  Пациент: {Surname} {Name}\n" +
  110.                               $"  Возраст: {Age}\n" +
  111.                               $"  Болезнь: {Disease}\n");
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement