Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CSLightFirst
- {
- class Program
- {
- private static void Main()
- {
- List<Patient> patients = GeneratePatients();
- while (true)
- {
- Console.WriteLine("Выберите, что Вам нужно сделать:\n" +
- " 1 - Отсортировать всех больных по ФИО\n" +
- " 2 - Отсортировать всех больных по возрасту\n" +
- " 3 - Вывести больных с определенным заболеванием\n");
- Console.Write("Ваш ответ: ");
- switch (Console.ReadLine())
- {
- case "1":
- MakeFullNameSelection(patients);
- break;
- case "2":
- MakeAgeSelection(patients);
- break;
- case "3":
- MakeDiseaseSelection(patients);
- break;
- default:
- Console.WriteLine("Некорректное введенное значение, попробуйте ещё раз...");
- break;
- }
- }
- }
- private static void MakeFullNameSelection(IEnumerable<Patient> patients)
- {
- ShowSelection(
- patients.OrderBy(patient => patient.Surname).ThenBy(patient => patient.Name),
- "Пациенты, отсортированы по возрасту:\n");
- }
- private static void MakeAgeSelection(IEnumerable<Patient> patients)
- {
- ShowSelection(
- patients.OrderBy(patient => patient.Age),
- "Пациенты, отсортированы по возрасту:\n");
- }
- private static void MakeDiseaseSelection(IEnumerable<Patient> patients)
- {
- Console.Clear();
- Console.Write("Введите болезнь, которую хотите найти: ");
- string disease = Console.ReadLine();
- ShowSelection(patients.Where(patient => patient.Disease == disease), $"Пациенты с болезнью {disease}:\n");
- }
- private static void ShowSelection(IEnumerable<Patient> selection, string text = "")
- {
- Console.Clear();
- Console.WriteLine(text);
- foreach (Patient patient in selection)
- patient.ShowInfo();
- }
- private static List<Patient> GeneratePatients()
- {
- Random rand = new Random();
- string[] names = { "Джон", "Хью", "Энн", "Джек", "Уил", "Марк", "Лиз", "Майкл", "Дэвис" };
- string[] surnames = { "Сильвер", "Морган", "Смит", "Джонс", "Уильямс", "Сноу", "Миллер", "Борк" };
- string[] diseases = { "ОРВИ", "Грипп", "ВИЧ", "Язва", "Корь", "Ветрянка", "Сифилис", "Оспа"};
- List<Patient> patients = new List<Patient>(rand.Next(10, 16));
- for (int i = 0; i < patients.Capacity; i++)
- patients.Add(new Patient(
- names[rand.Next(0, names.Length)],
- surnames[rand.Next(0, surnames.Length)],
- rand.Next(10, 71),
- diseases[rand.Next(0, diseases.Length)]));
- return patients;
- }
- }
- class Patient
- {
- public string Name { get; }
- public string Surname { get; }
- public int Age { get; }
- public string Disease { get; }
- public Patient(string name, string surname, int age, string disease)
- {
- Name = name;
- Surname = surname;
- Age = age;
- Disease = disease;
- }
- public void ShowInfo()
- {
- Console.WriteLine($" Пациент: {Surname} {Name}\n" +
- $" Возраст: {Age}\n" +
- $" Болезнь: {Disease}\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement