Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Clight_40_LINQ_Hospital
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<string> fio = new List<string> { "Иванов А.Г.", "Владимиров Б.У.", "Оксанин Г.В." , "Генацвали А.В." ,
- "Маринин С.А.", "Игорян Х.А.", "Евгенов С.М.", "Мариуполев С.В", "Надеждина Н.Т.", "Русланков В.А.",
- "Сергеев Н.Н.", "Иринина И.П.", "Маринок Ж.А.", "Игрил Х.Х.", "Оксанн П.С.", "Возбудидзе А.Ю.",
- "Попин М.Ю.", "Сааркян С.И." };
- List<string> disease = new List<string> { "орви", "дипрессия", "аритмия", "диарея" };
- Hospital hospital = new Hospital();
- hospital.CreatePacients(fio, disease);
- while (true)
- {
- Console.Clear();
- Console.WriteLine("Меню больницы.\n");
- Console.WriteLine("F1 - Сортировка больных по фамилии.");
- Console.WriteLine("F2 - Сортировка больных по возрасту.");
- Console.WriteLine("F3 - Вывод больных по заболеванию.");
- Console.CursorVisible = false;
- ConsoleKeyInfo key = Console.ReadKey();
- Console.WriteLine();
- switch (key.Key)
- {
- case ConsoleKey.F1:
- hospital.ShowPacientByFio();
- Console.ReadKey();
- break;
- case ConsoleKey.F2:
- hospital.ShowPacientByAge();
- Console.ReadKey();
- break;
- case ConsoleKey.F3:
- Console.CursorVisible = true;
- Console.Write("Введите название заболевания (орви, дипрессия, аритмия, диарея): ");
- string inputUser = Console.ReadLine();
- Console.CursorVisible = false;
- Console.WriteLine();
- hospital.ShowPacientByDisease(inputUser);
- Console.ReadKey();
- break;
- default:
- Console.WriteLine("Не корректный ввод пункта меню.");
- break;
- }
- }
- }
- }
- class Hospital
- {
- Random random = new Random();
- private List<Pacient> _pacients;
- public void CreatePacients(List<string> fio, List<string> diseas)
- {
- _pacients = new List<Pacient> { };
- foreach (var item in fio)
- {
- int age = random.Next(18, 66);
- int typeOfDisease = random.Next(0, diseas.Count);
- Pacient tempPacient = new Pacient(item, age, diseas[typeOfDisease]);
- _pacients.Add(tempPacient);
- }
- }
- public void ShowPacientByFio()
- {
- var sortPacients = _pacients.OrderBy(pacient => pacient.Fio);
- foreach (var pacient in sortPacients)
- {
- pacient.ShowInfo();
- }
- }
- public void ShowPacientByAge()
- {
- var sortPacients = _pacients.OrderBy(pacient => pacient.Age);
- foreach (var pacient in sortPacients)
- {
- pacient.ShowInfo();
- }
- }
- public void ShowPacientByDisease(string inputDisease)
- {
- var sortPacients = _pacients.Where( pacient => pacient.Disease == inputDisease);
- if (sortPacients.Count() > 0)
- {
- foreach (var pacient in sortPacients)
- {
- pacient.ShowInfo();
- }
- }
- else
- {
- Console.WriteLine($"Больных с заболеванием {inputDisease} не найдено.");
- }
- }
- }
- class Pacient
- {
- public string Fio { get; private set; }
- public int Age { get; private set; }
- public string Disease { get; private set; }
- public Pacient(string fio, int age, string disease)
- {
- Fio = fio;
- Age = age;
- Disease = disease;
- }
- public void ShowInfo()
- {
- Console.WriteLine($"Ф.И.О.: {Fio}, Возраст: {Age} лет, Заболевание: {Disease}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement