📜  C ++中的医院管理系统

📅  最后修改于: 2021-05-31 16:49:18             🧑  作者: Mango

在本文中,讨论了用于管理医院管理系统的C++程序。给定医院名称,医院名称,联系方式以及以下医生和患者的数据,这些是需要实现的功能:

支持的功能:

  • 打印医院数据
  • 打印患者数据
  • 床价格排序
  • 按可用床排序
  • 按名称分类
  • SORT BY评分和评论
  • 打印任何特定城市的医院

该程序中的重要功能:

  1. PrintHospitalData():它将打印所有医院数据。
  2. PrintPatientData():它将打印所有医院数据。
  3. SortHospitalByName():按名称对所有医院进行排序
  4. SortHospitalByRating():根据等级对医院进行排序
  5. SortByBedsAvailable():根据可用床位对医院进行排序
  6. SortByBedsPrice():根据最低价格对医院进行排序。

方法:

  • 为Hospital数据集Patient数据创建类。
  • 初始化存储医院数据集和患者数据的变量。
  • 为访问医院数据集和患者数据的医院和患者类别创建对象。
  • 使用两个数组保存医院数据集和患者数据。
  • 实现给定的功能,如下所示。

下面是上述方法的实现。

C++
// C++ program to implement the Hospital
// Management System
#include 
using namespace std;
  
// Store the data of Hospital
class Hospital {
public:
    string H_name;
    string location;
    int available_beds;
    float rating;
    string contact;
    string doctor_name;
    int price;
};
  
// Stores the data of Patient
class Patient : public Hospital {
public:
    string P_name;
    int P_id;
};
  
// Hospital Data
void PrintHospitalData(
    vector& hospitals)
{
    cout << "PRINT hospitals DATA:"
         << endl;
  
    cout << "HospitalName     "
         << "Location     "
         << "Beds_Available     "
         << "Rating     "
         << "Hospital_Contact     "
         << "Doctor_Name     "
         << "Price_Per_Bed     \n";
  
    for (int i = 0; i < 4; i++) {
        cout << hospitals[i].H_name
             << "                 "
             << "        "
             << hospitals[i].location
             << "           "
             << hospitals[i].available_beds
             << "                    "
             << hospitals[i].rating
             << "            "
             << hospitals[i].contact
             << "             "
             << hospitals[i].doctor_name
             << "                  "
             << "        "
             << hospitals[i].price
             << "            "
             << endl;
    }
  
    cout << endl
         << endl;
}
  
// Function to print the patient
// data in the hospital
void PrintPatientData(
    vector& patients,
    vector& hospitals)
{
    cout << "PRINT patients DATA:"
         << endl;
    cout << "Patient_Name     "
         << "Patient_Id     "
         << "Patient_Contact     "
         << "Alloted_Hospital     "
         << "Patient_Expenditure     \n";
  
    for (int i = 0; i < 4; i++) {
        cout << patients[i].P_name
             << "                "
             << "          "
             << patients[i].P_id
             << "              "
             << "          "
             << patients[i].contact
             << "                   "
             << hospitals[i].H_name
             << "                   "
             << patients[i].price
             << "            "
             << endl;
    }
  
    cout << endl
         << endl;
}
  
// Comparator function to sort the
// hospital data by name
bool name(Hospital& A, Hospital& B)
{
    return A.H_name > B.H_name;
}
  
// Function to sort the hospital
// data by name
void SortHospitalByName(
    vector hospitals)
{
    // Sort the date
    sort(hospitals.begin(),
         hospitals.end(),
         name);
  
    cout << "SORT BY NAME:"
         << endl
         << endl;
    PrintHospitalData(hospitals);
}
  
// Comparator function to sort the
// hospital data by rating
bool rating(Hospital& A, Hospital& B)
{
    return A.rating > B.rating;
}
  
// Function to sort the hospital
// data by namerating
void SortHospitalByRating(vector hospitals)
{
    sort(hospitals.begin(),
         hospitals.end(),
         rating);
  
    cout << "SORT BY Rating:"
         << endl
         << endl;
  
    PrintHospitalData(hospitals);
}
  
// Comparator function to sort the
// hospital data by Bed Available
bool beds(Hospital& A, Hospital& B)
{
    return A.available_beds > B.available_beds;
}
  
// Function to sort the hospital
// data by Bed Available
void SortByBedsAvailable(
    vector hospitals)
{
    sort(hospitals.begin(),
         hospitals.end(),
         beds);
  
    cout << "SORT BY Available Beds:"
         << endl
         << endl;
  
    PrintHospitalData(hospitals);
}
  
// Comparator function to sort the
// hospital data by Bed Price
bool beds_price(Hospital& A, Hospital& B)
{
    return A.price < B.price;
}
  
// Function to sort the hospital
// data by Bed Price
void SortByBedsPrice(
    vector hospitals)
{
    sort(hospitals.begin(),
         hospitals.end(),
         beds_price);
  
    cout << "SORT BY Available Beds Price:"
         << endl
         << endl;
  
    PrintHospitalData(hospitals);
}
  
// Comparator function to sort the
// hospital data by City
void PrintHospitalBycity(
    string city, vector hospitals)
{
    cout << "PRINT hospitals by Name :"
         << city << endl;
  
    cout << "HospitalName     "
         << "Location     "
         << "Beds_Available     "
         << "Rating     "
         << "Hospital_Contact     "
         << "Doctor_Name     "
         << "Price_Per_Bed     \n";
  
    for (int i = 0; i < 4; i++) {
  
        if (hospitals[i].location != city)
            continue;
        cout << hospitals[i].H_name
             << "                  "
             << "       "
             << hospitals[i].location
             << "           "
             << hospitals[i].available_beds
             << "                    "
             << hospitals[i].rating
             << "            "
             << hospitals[i].contact
             << "             "
             << hospitals[i].doctor_name
             << "                "
             << "          "
             << hospitals[i].price
             << "            "
             << endl;
    }
    cout << endl
         << endl;
}
  
// Function to implement Hospital
// Management System
void HospitalManagement(
    string patient_Name[], int patient_Id[],
    string patient_Contact[], int bookingCost[],
    string hospital_Name[], string locations[], int beds[],
    float ratings[], string hospital_Contact[],
    string doctor_Name[], int prices[])
{
    // Stores the Hospital data
    // and user data
    vector hospitals;
  
    // Create Objects for hospital
    // and the users
    Hospital h;
  
    // Initialize the data
    for (int i = 0; i < 4; i++) {
        h.H_name = hospital_Name[i];
        h.location = locations[i];
        h.available_beds = beds[i];
        h.rating = ratings[i];
        h.contact = hospital_Contact[i];
        h.doctor_name = doctor_Name[i];
        h.price = prices[i];
        hospitals.push_back(h);
    }
  
    // Stores the patient data
    vector patients;
    Patient p;
  
    // Initialize the data
    for (int i = 0; i < 4; i++) {
        p.P_name = patient_Name[i];
        p.P_id = patient_Id[i];
        p.contact = patient_Contact[i];
        p.price = bookingCost[i];
        patients.push_back(p);
    }
  
    cout << endl;
  
    // Call the various operations
    PrintHospitalData(hospitals);
    PrintPatientData(patients, hospitals);
  
    SortHospitalByName(hospitals);
    SortHospitalByRating(hospitals);
    PrintHospitalBycity("Bangalore", hospitals);
    SortByBedsAvailable(hospitals);
    SortByBedsPrice(hospitals);
}
  
// Driver Code
int main()
{
    // Stores hospital data and
    // the user data
    string patient_Name[] = { "P1", "P2", "P3", "P4" };
    int patient_Id[] = { 2, 3, 4, 1 };
    string patient_Contact[]
        = { "234534XXX7", "234576XXX2", "857465XXX9",
            "567657XXX0" };
    int bookingCost[] = { 1000, 1200, 1100, 600 };
  
    string hospital_Name[] = { "H1", "H2", "H4", "H3" };
    string locations[] = { "Bangalore", "Bangalore",
                           "Mumbai   ", "Prayagraj" };
    int beds[] = { 4, 5, 6, 9 };
    float ratings[] = { 5.2, 4.1, 3.4, 5.9 };
    string hospital_Contact[]
        = { "657534XXX7", "298766XXX2", "324565XXX9",
            "343456XXX4" };
    string doctor_Name[] = { "D1", "D4", "D3", "D2" };
    int prices[] = { 100, 200, 100, 290 };
  
    // Function Call
    HospitalManagement(
        patient_Name, patient_Id, patient_Contact,
        bookingCost, hospital_Name, locations, beds,
        ratings, hospital_Contact, doctor_Name, prices);
  
    return 0;
}


输出:

想要从精选的最佳视频中学习并解决问题,请查看有关从基础到高级C++的C++基础课程以及有关语言和STL的C++ STL课程。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”