Загрузка данных


#include "hospital.h"
#include <iostream>
using namespace std;

// Демонстрация конструктора копирования (передача по значению)
void showPatientCopy(Patient p) {
    p.Show();
}

// Демонстрация конструктора копирования (возврат значения)
Patient createPatient() {
    char name[50];
    int age;
    cout << "Введите имя временного больного: ";
    cin >> name;
    cout << "Введите возраст: ";
    cin >> age;
    return Patient(name, age);
}

int main() {
    // ========== ВВОД БОЛЬНЫХ ==========
    int patientCount;
    cout << "Сколько больных хотите ввести? ";
    cin >> patientCount;
    
    Patient patients[10];
    for (int i = 0; i < patientCount; i++) {
        char name[50];
        int age;
        cout << "Больной #" << i + 1 << ":" << endl;
        cout << "  Имя: ";
        cin >> name;
        cout << "  Возраст: ";
        cin >> age;
        patients[i].SetName(name);
        patients[i].SetAge(age);
    }
    
    // ========== ВВОД ВРАЧЕЙ ==========
    int doctorCount;
    cout << "\nСколько врачей хотите ввести? ";
    cin >> doctorCount;
    
    Doctor doctors[10];
    for (int i = 0; i < doctorCount; i++) {
        char name[50], spec[50];
        int exp;
        cout << "Врач #" << i + 1 << ":" << endl;
        cout << "  Имя: ";
        cin >> name;
        cout << "  Специальность: ";
        cin >> spec;
        cout << "  Стаж (лет): ";
        cin >> exp;
        doctors[i].SetName(name);
        doctors[i].SetSpecialty(spec);
        doctors[i].SetExperience(exp);
    }
    
    // ========== ВВОД ПАЛАТ ==========
    int wardCount;
    cout << "\nСколько палат хотите создать? ";
    cin >> wardCount;
    
    Ward wards[10];
    for (int i = 0; i < wardCount; i++) {
        int num, cap;
        cout << "Палата #" << i + 1 << ":" << endl;
        cout << "  Номер: ";
        cin >> num;
        cout << "  Вместимость: ";
        cin >> cap;
        wards[i].SetRoomNumber(num);
        wards[i].SetCapacity(cap);
    }
    
    // ========== РАЗМЕЩЕНИЕ БОЛЬНЫХ ПО ПАЛАТАМ ==========
    cout << "\nРазмещение больных по палатам:" << endl;
    for (int i = 0; i < patientCount; i++) {
        cout << "\nБольной " << patients[i].GetName() << " (" << patients[i].GetAge() << " лет)" << endl;
        for (int j = 0; j < wardCount; j++) {
            cout << "  " << j + 1 << ". Палата №" << wards[j].GetRoomNumber() 
                 << " (свободно: " << wards[j].GetCapacity() - wards[j].GetCurrentCount() << ")" << endl;
        }
        int choice;
        cout << "Выберите палату (0 - не размещать): ";
        cin >> choice;
        if (choice > 0 && choice <= wardCount) {
            if (wards[choice - 1].AddPatient(&patients[i])) {
                cout << "Больной размещён в палате №" << wards[choice - 1].GetRoomNumber() << endl;
            } else {
                cout << "В палате нет мест!" << endl;
            }
        }
    }
    
    // ========== СОЗДАНИЕ ОТДЕЛЕНИЯ ==========
    char deptName[50];
    cout << "\nВведите название отделения: ";
    cin >> deptName;
    Department dept(deptName);
    
    for (int i = 0; i < doctorCount; i++) {
        dept.AddDoctor(doctors[i]);
    }
    for (int i = 0; i < wardCount; i++) {
        dept.AddWard(wards[i]);
    }
    
    // ========== ВВОД ГРАФИКОВ ПРИЕМА ==========
    int receptionCount;
    cout << "\nСколько приемов хотите добавить? ";
    cin >> receptionCount;
    
    ReceptionSchedule receptions[10];
    for (int i = 0; i < receptionCount; i++) {
        char docName[50], date[20], st[20], et[20];
        int maxP;
        cout << "Прием #" << i + 1 << ":" << endl;
        cout << "  Имя врача: ";
        cin >> docName;
        cout << "  Дата: ";
        cin >> date;
        cout << "  Время начала: ";
        cin >> st;
        cout << "  Время окончания: ";
        cin >> et;
        cout << "  Максимум больных: ";
        cin >> maxP;
        receptions[i].SetDoctor(docName);
        receptions[i].SetDate(date);
        receptions[i].SetStartTime(st);
        receptions[i].SetEndTime(et);
        receptions[i].SetMaxPatients(maxP);
    }
    
    // ========== ДЕМОНСТРАЦИЯ КОНСТРУКТОРА КОПИРОВАНИЯ ==========
    Patient patientCopy = patients[0];
    showPatientCopy(patients[0]);
    Patient patientFromFunc = createPatient();
    
    // ========== УКАЗАТЕЛЬ НА ОБЪЕКТ ==========
    Patient* pPtr = &patients[0];
    
    // ========== УКАЗАТЕЛЬ НА КОМПОНЕНТНУЮ ФУНКЦИЮ ==========
    void (Patient::*funcPtr)() = &Patient::Show;
    (patients[0].*funcPtr)();
    (pPtr->*funcPtr)();
    
    void (Doctor::*docFuncPtr)() = &Doctor::Show;
    (doctors[0].*docFuncPtr)();
    
    // ========== ВЫВОД ВСЕЙ ИНФОРМАЦИИ ==========
    cout << "\n=== БОЛЬНЫЕ ===" << endl;
    for (int i = 0; i < patientCount; i++) {
        patients[i].Show();
    }
    
    cout << "\n=== ВРАЧИ ===" << endl;
    for (int i = 0; i < doctorCount; i++) {
        doctors[i].Show();
    }
    
    cout << "\n=== ОТДЕЛЕНИЕ ===" << endl;
    dept.Show();
    
    cout << "\n=== ГРАФИКИ ПРИЕМА ===" << endl;
    for (int i = 0; i < receptionCount; i++) {
        receptions[i].Show();
    }
    
    return 0;
}
#include "hospital.h"
#include <iostream>
#include <cstring>
using namespace std;

// ==================== MedicalHistory ====================

MedicalHistory::MedicalHistory() {
    strcpy(diagnosis, "Не установлен");
    strcpy(treatment, "Не назначено");
}

MedicalHistory::MedicalHistory(const char* d, const char* t) {
    strcpy(diagnosis, d);
    strcpy(treatment, t);
}

MedicalHistory::MedicalHistory(const MedicalHistory& other) {
    strcpy(diagnosis, other.diagnosis);
    strcpy(treatment, other.treatment);
}

MedicalHistory::~MedicalHistory() {
}

void MedicalHistory::SetDiagnosis(const char* d) { strcpy(diagnosis, d); }
void MedicalHistory::SetTreatment(const char* t) { strcpy(treatment, t); }
char* MedicalHistory::GetDiagnosis() { return diagnosis; }
char* MedicalHistory::GetTreatment() { return treatment; }

void MedicalHistory::Show() {
    cout << "    История болезни: " << diagnosis << " -> Лечение: " << treatment << endl;
}

// ==================== Patient ====================

Patient::Patient() {
    strcpy(name, "Неизвестно");
    age = 0;
}

Patient::Patient(const char* n, int a) : history("Не установлен", "Не назначено") {
    strcpy(name, n);
    age = a;
}

Patient::Patient(const Patient& other) : history(other.history) {
    strcpy(name, other.name);
    age = other.age;
}

Patient::~Patient() {
}

void Patient::SetName(const char* n) { strcpy(name, n); }
void Patient::SetAge(int a) { age = a; }
char* Patient::GetName() { return name; }
int Patient::GetAge() { return age; }

void Patient::Show() {
    cout << "  Больной: " << name << ", Возраст: " << age << endl;
    history.Show();
}

// ==================== Doctor ====================

Doctor::Doctor() {
    strcpy(name, "Неизвестно");
    strcpy(specialty, "Не указана");
    experience = 0;
}

Doctor::Doctor(const char* n, const char* spec, int exp) {
    strcpy(name, n);
    strcpy(specialty, spec);
    experience = exp;
}

Doctor::Doctor(const Doctor& other) {
    strcpy(name, other.name);
    strcpy(specialty, other.specialty);
    experience = other.experience;
}

Doctor::~Doctor() {
}

void Doctor::SetName(const char* n) { strcpy(name, n); }
void Doctor::SetSpecialty(const char* spec) { strcpy(specialty, spec); }
void Doctor::SetExperience(int exp) { experience = exp; }
char* Doctor::GetName() { return name; }
char* Doctor::GetSpecialty() { return specialty; }
int Doctor::GetExperience() { return experience; }

void Doctor::Show() {
    cout << "  Врач: " << name << ", Специальность: " << specialty 
         << ", Стаж: " << experience << " лет" << endl;
}

// ==================== Ward ====================

Ward::Ward() {
    roomNumber = 0;
    capacity = 4;
    currentCount = 0;
}

Ward::Ward(int num, int cap) {
    roomNumber = num;
    capacity = cap;
    currentCount = 0;
}

Ward::Ward(const Ward& other) {
    roomNumber = other.roomNumber;
    capacity = other.capacity;
    currentCount = other.currentCount;
    for (int i = 0; i < currentCount; i++) {
        patients[i] = other.patients[i];
    }
}

Ward::~Ward() {
}

void Ward::SetRoomNumber(int num) { roomNumber = num; }
void Ward::SetCapacity(int cap) { capacity = cap; }
int Ward::GetRoomNumber() { return roomNumber; }
int Ward::GetCapacity() { return capacity; }
int Ward::GetCurrentCount() { return currentCount; }

bool Ward::AddPatient(Patient* p) {
    if (currentCount < 10 && currentCount < capacity) {
        patients[currentCount] = p;
        currentCount++;
        return true;
    }
    return false;
}

bool Ward::RemovePatient(Patient* p) {
    for (int i = 0; i < currentCount; i++) {
        if (patients[i] == p) {
            for (int j = i; j < currentCount - 1; j++) {
                patients[j] = patients[j + 1];
            }
            currentCount--;
            return true;
        }
    }
    return false;
}

void Ward::Show() {
    cout << "  Палата №" << roomNumber << " (вместимость: " << capacity 
         << ", занято: " << currentCount << ")" << endl;
    for (int i = 0; i < currentCount; i++) {
        cout << "    - " << patients[i]->GetName() << endl;
    }
}

// ==================== Department ====================

Department::Department() {
    strcpy(name, "Отделение");
    wardCount = 0;
    doctorCount = 0;
}

Department::Department(const char* n) {
    strcpy(name, n);
    wardCount = 0;
    doctorCount = 0;
}

Department::Department(const Department& other) {
    strcpy(name, other.name);
    wardCount = other.wardCount;
    doctorCount = other.doctorCount;
    for (int i = 0; i < wardCount; i++) {
        wards[i] = other.wards[i];
    }
    for (int i = 0; i < doctorCount; i++) {
        doctors[i] = other.doctors[i];
    }
}

Department::~Department() {
}

void Department::SetName(const char* n) { strcpy(name, n); }
char* Department::GetName() { return name; }

void Department::AddWard(Ward w) {
    if (wardCount < 5) {
        wards[wardCount] = w;
        wardCount++;
    }
}

void Department::AddDoctor(Doctor d) {
    if (doctorCount < 5) {
        doctors[doctorCount] = d;
        doctorCount++;
    }
}

Ward* Department::GetWard(int index) { return &wards[index]; }
Doctor* Department::GetDoctor(int index) { return &doctors[index]; }
int Department::GetWardCount() { return wardCount; }
int Department::GetDoctorCount() { return doctorCount; }

void Department::Show() {
    cout << "=== Отделение: " << name << " ===" << endl;
    cout << "Врачи (" << doctorCount << "):" << endl;
    for (int i = 0; i < doctorCount; i++) {
        doctors[i].Show();
    }
    cout << "Палаты (" << wardCount << "):" << endl;
    for (int i = 0; i < wardCount; i++) {
        wards[i].Show();
    }
}

// ==================== ReceptionSchedule ====================

ReceptionSchedule::ReceptionSchedule() {
    strcpy(doctorName, "Не назначен");
    strcpy(date, "Не указана");
    strcpy(startTime, "Не указано");
    strcpy(endTime, "Не указано");
    maxPatients = 10;
}

ReceptionSchedule::ReceptionSchedule(const char* doc, const char* d, const char* st, const char* et, int max) {
    strcpy(doctorName, doc);
    strcpy(date, d);
    strcpy(startTime, st);
    strcpy(endTime, et);
    maxPatients = max;
}

ReceptionSchedule::ReceptionSchedule(const ReceptionSchedule& other) {
    strcpy(doctorName, other.doctorName);
    strcpy(date, other.date);
    strcpy(startTime, other.startTime);
    strcpy(endTime, other.endTime);
    maxPatients = other.maxPatients;
}

ReceptionSchedule::~ReceptionSchedule() {
}

void ReceptionSchedule::SetDoctor(const char* doc) { strcpy(doctorName, doc); }
void ReceptionSchedule::SetDate(const char* d) { strcpy(date, d); }
void ReceptionSchedule::SetStartTime(const char* t) { strcpy(startTime, t); }
void ReceptionSchedule::SetEndTime(const char* t) { strcpy(endTime, t); }
void ReceptionSchedule::SetMaxPatients(int max) { maxPatients = max; }
char* ReceptionSchedule::GetDoctorName() { return doctorName; }
char* ReceptionSchedule::GetDate() { return date; }
char* ReceptionSchedule::GetStartTime() { return startTime; }
char* ReceptionSchedule::GetEndTime() { return endTime; }
int ReceptionSchedule::GetMaxPatients() { return maxPatients; }

void ReceptionSchedule::Show() {
    cout << "  Прием: " << doctorName << ", " << date 
         << " " << startTime << "-" << endTime 
         << ", макс. " << maxPatients << " пациентов" << endl;
}
#ifndef HOSPITAL_H
#define HOSPITAL_H

#include <iostream>
#include <cstring>
using namespace std;

// ========== История болезни ==========
class MedicalHistory {
private:
    char diagnosis[100];
    char treatment[100];

public:
    MedicalHistory();
    MedicalHistory(const char* d, const char* t);
    MedicalHistory(const MedicalHistory& other);
    ~MedicalHistory();

    void SetDiagnosis(const char* d);
    void SetTreatment(const char* t);
    char* GetDiagnosis();
    char* GetTreatment();

    void Show();
};

// ========== Больной ==========
class Patient {
private:
    char name[50];
    int age;
    MedicalHistory history;

public:
    Patient();
    Patient(const char* n, int a);
    Patient(const Patient& other);
    ~Patient();

    void SetName(const char* n);
    void SetAge(int a);
    char* GetName();
    int GetAge();

    void Show();
};

// ========== Врач ==========
class Doctor {
private:
    char name[50];
    char specialty[50];
    int experience;

public:
    Doctor();
    Doctor(const char* n, const char* spec, int exp);
    Doctor(const Doctor& other);
    ~Doctor();

    void SetName(const char* n);
    void SetSpecialty(const char* spec);
    void SetExperience(int exp);
    char* GetName();
    char* GetSpecialty();
    int GetExperience();

    void Show();
};

// ========== Палата ==========
class Ward {
private:
    int roomNumber;
    int capacity;
    int currentCount;
    Patient* patients[10];

public:
    Ward();
    Ward(int num, int cap);
    Ward(const Ward& other);
    ~Ward();

    void SetRoomNumber(int num);
    void SetCapacity(int cap);
    int GetRoomNumber();
    int GetCapacity();
    int GetCurrentCount();
    bool AddPatient(Patient* p);
    bool RemovePatient(Patient* p);

    void Show();
};

// ========== Отделение ==========
class Department {
private:
    char name[50];
    Ward wards[5];
    int wardCount;
    Doctor doctors[5];
    int doctorCount;

public:
    Department();
    Department(const char* n);
    Department(const Department& other);
    ~Department();

    void SetName(const char* n);
    char* GetName();
    void AddWard(Ward w);
    void AddDoctor(Doctor d);
    Ward* GetWard(int index);
    Doctor* GetDoctor(int index);
    int GetWardCount();
    int GetDoctorCount();

    void Show();
};

// ========== График приема ==========
class ReceptionSchedule {
private:
    char doctorName[50];
    char date[20];
    char startTime[20];
    char endTime[20];
    int maxPatients;

public:
    ReceptionSchedule();
    ReceptionSchedule(const char* doc, const char* d, const char* st, const char* et, int max);
    ReceptionSchedule(const ReceptionSchedule& other);
    ~ReceptionSchedule();

    void SetDoctor(const char* doc);
    void SetDate(const char* d);
    void SetStartTime(const char* t);
    void SetEndTime(const char* t);
    void SetMaxPatients(int max);
    char* GetDoctorName();
    char* GetDate();
    char* GetStartTime();
    char* GetEndTime();
    int GetMaxPatients();

    void Show();
};

#endif