Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Created June 22, 2025 09:07
Show Gist options
  • Save StrikerXx798/60f9af00531093541d0e486dd000cc12 to your computer and use it in GitHub Desktop.
Save StrikerXx798/60f9af00531093541d0e486dd000cc12 to your computer and use it in GitHub Desktop.
ДЗ: Анархия в больнице
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
public class Program
{
static void Main(string[] args)
{
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
Hospital hospital = new Hospital();
hospital.StartWork();
}
}
class Patient
{
public Patient(string fullName, int age, string disease)
{
FullName = fullName;
Age = age;
Disease = disease;
}
public string FullName { get; }
public int Age { get; }
public string Disease { get; }
public void ShowInfo()
{
Console.WriteLine($"ФИО: {FullName} | Возраст: {Age} | Заболевание: {Disease}");
}
}
class Hospital
{
private const int CommandShowAllPatients = 1;
private const int CommandShowPatientsSortedByName = 2;
private const int CommandShowPatientsSortedByAge = 3;
private const int CommandShowPatientsByDisease = 4;
private const int CommandExit = 0;
public Hospital()
{
_patients = new List<Patient>
{
new Patient("Иванов Иван Иванович", 34, "Грипп"),
new Patient("Петрова Мария Сергеевна", 28, "Пневмония"),
new Patient("Сидоров Георгий Павлович", 41, "Диабет"),
new Patient("Шмидт Анна Викторовна", 22, "Грипп"),
new Patient("Браун Виктор Александрович", 37, "Гастрит"),
new Patient("Иванов Сергей Владимирович", 29, "ОРВИ"),
new Patient("Романова Людмила Петровна", 31, "Грипп"),
new Patient("Дрозд Павел Николаевич", 45, "Гипертония"),
new Patient("Вайс Эмма Андреевна", 26, "Пневмония"),
new Patient("Грин Алексей Сергеевич", 39, "Диабет"),
};
}
private List<Patient> _patients;
public void StartWork()
{
bool isWorking = true;
while (isWorking)
{
Console.WriteLine("\n--- МЕНЮ БОЛЬНИЦЫ ---");
Console.WriteLine($"{CommandShowAllPatients} - Вывести всех больных");
Console.WriteLine(
$"{CommandShowPatientsSortedByName} - Отсортировать всех больных по ФИО"
);
Console.WriteLine(
$"{CommandShowPatientsSortedByAge} - Отсортировать всех больных по возрасту"
);
Console.WriteLine(
$"{CommandShowPatientsByDisease} - Вывести больных с определённым заболеванием"
);
Console.WriteLine($"{CommandExit} - Выйти");
int input = GetNumberInput("Введите команду: ");
switch (input)
{
case CommandShowAllPatients:
ShowPatientsInfo(_patients);
break;
case CommandShowPatientsSortedByName:
ShowPatientsSortedByName();
break;
case CommandShowPatientsSortedByAge:
ShowPatientsSortedByAge();
break;
case CommandShowPatientsByDisease:
ShowPatientsByDisease();
break;
case CommandExit:
isWorking = false;
break;
default:
Console.WriteLine("Неизвестная команда.");
break;
}
}
}
private int GetNumberInput(string message)
{
Console.WriteLine(message);
string input = Console.ReadLine();
int number;
while (int.TryParse(input, out number) == false)
{
Console.WriteLine("Некорректный ввод. Попробуйте снова.");
input = Console.ReadLine();
}
return number;
}
private void ShowPatientsInfo(List<Patient> patients)
{
foreach (var patient in patients)
{
patient.ShowInfo();
}
}
private void ShowPatientsSortedByName()
{
var sorted = _patients.OrderBy(p => p.FullName).ToList();
Console.WriteLine("\nСписок больных (отсортировано по ФИО):");
ShowPatientsInfo(sorted);
}
private void ShowPatientsSortedByAge()
{
var sorted = _patients.OrderBy(p => p.Age).ToList();
Console.WriteLine("\nСписок больных (отсортировано по возрасту):");
ShowPatientsInfo(sorted);
}
private void ShowPatientsByDisease()
{
Console.Write("Введите название заболевания: ");
string disease = Console.ReadLine();
var filtered = _patients
.Where(p => p.Disease.Equals(disease, StringComparison.OrdinalIgnoreCase))
.ToList();
if (filtered.Count <= 0)
{
Console.WriteLine("Нет больных с таким заболеванием.");
return;
}
Console.WriteLine($"\nБольные с заболеванием \"{disease}\":");
ShowPatientsInfo(filtered);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment