Hospital Management System in C++
Introduction:
This tutorial covers the working of the management of the Hospital Management System using a C++ programming language. The capabilities which need to be implemented are shown below, along with hospital names, contact information, and information about doctors and patients.
Functions Supported:
The important functions in the program:
- Hospital_Data (): Every hospital's information will be printed.
- Patient_data (): All of the patient’s information will be printed.
- Sorting_by_hospitalname (): It will arrange every hospital by name.
- Sorting_by_hospitalrating (): Hospitals are arranged according to their rating.
- Sorting_by_totalbedsavailable (): Hospitals should be arranged based on the number of beds available.
- Sorting_by_beds_price (): Hospitals should be arranged by lowest cost.
Program:
#include <bits/stdc++.h>
using namespace std;
class Hospital_details {
public:
string Name_of_hospital;
string Hospital_location;
int Total_available_beds;
float Hospital_rating;
string Hospital_phn_num;
string name_of_doctor;
int total_price;
};
class Patient_details : public Hospital_details {
public:
string P_name;
int P_id;
};
void Hospital_Data (
vector<Hospital_details>& hospitals)
{
cout << "Displaying the hospital's data : "
<< endl;
cout << "Hospital Name "
<< "Hospital Location "
<< "Total Beds Available "
<< "Hospital Rating "
<< "Hospital Contact "
<< "Doctor Name "
<< "Price of each bed \n";
for (int j = 0; j < 4; j++) {
cout << hospitals[j].Name_of_hospital
<< " "
<< ""
<< hospitals[j].Hospital_location
<< " "
<< hospitals[j].Total_available_beds
<< " "
<< hospitals[j].Hospital_rating
<< " "
<< hospitals[j].Hospital_phn_num
<< " "
<< hospitals[j].name_of_doctor
<< ""
<< " "
<< hospitals[j].total_price
<< " "
<< endl;
}
cout << endl
<< endl;
}
void Patient_data (
vector<Patient_details>& patients,
vector<Hospital_details>& hospitals)
{
cout << " Displaying patients information :"
<< endl;
cout << "Patient Name "
<< "Patient Id "
<< "Patient Contact "
<< "Allotted Hospital "
<< "Patient Expenditure \n";
for (int j = 0; j < 4; j++) {
cout << patients[j].P_name
<< " "
<< " "
<< patients[j].P_id
<< " "
<< " "
<< patients[j].Hospital_phn_num
<< " "
<< hospitals[j].Name_of_hospital
<< " "
<< patients[j].total_price
<< " "
<< endl;
}
cout << endl
<< endl;
}
bool name(Hospital_details& A, Hospital_details& B)
{
return A.Name_of_hospital > B.Name_of_hospital;
}
void Sorting_by_hospitalname(
vector<Hospital_details> hospitals)
{
sort(hospitals.begin(), hospitals.end(), name);
cout << "Displaying by name :"
<< endl
<< endl;
Hospital_Data(hospitals);
}
bool rating(Hospital_details& A, Hospital_details& B)
{
return A.Hospital_rating > B.Hospital_rating;
}
void Sorting_by_hospitalrating(vector<Hospital_details> hospitals)
{
sort(hospitals.begin(),
hospitals.end(),
rating);
cout << "Displaying by rating :"
<< endl
<< endl;
Hospital_Data(hospitals);
}
bool beds(Hospital_details& A, Hospital_details& B)
{
return A.Total_available_beds > B.Total_available_beds;
}
void Sorting_by_totalbedsavailable(
vector<Hospital_details> hospitals)
{
sort(hospitals.begin(), hospitals.end(), beds);
cout << "Displaying by total number of beds available :"
<< endl
<< endl;
Hospital_Data(hospitals);
}
bool beds_price(Hospital_details& A, Hospital_details& B)
{
return A.total_price < B.total_price;
}
void Sorting_by_beds_price(
vector<Hospital_details> hospitals)
{
sort(hospitals.begin(),
hospitals.end(),
beds_price);
cout << " Displaying through price of the beds :"
<< endl
<< endl;
Hospital_Data(hospitals);
}
void Hospital_through_city(
string city, vector<Hospital_details> hospitals)
{
cout << " Displaying through hospital City :"
<< city << endl;
cout << "HospitalName "
<< "Hospital Location "
<< "Total Beds Available "
<< "Hospital Rating "
<< "Hospital Contact "
<< "Doctor Name "
<< "Price of each bed \n";
for (int j = 0; j < 4; j++) {
if (hospitals[j].Hospital_location != city)
continue;
cout << hospitals[j].Name_of_hospital
<< " "
<< " "
<< hospitals[j].Hospital_location
<< " "
<< hospitals[j].Total_available_beds
<< " "
<< hospitals[j].Hospital_rating
<< " "
<< hospitals[j].Hospital_phn_num
<< " "
<< hospitals[j].name_of_doctor
<< ""
<< " "
<< hospitals[j].total_price
<< " "
<< endl;
}
cout << endl
<< endl;
}
void Hospital_management_system(
string P_name[], int P_id[],
string P_phone_num[], int cost_for_booking[],
string Name_of_hospital[], string location_of_hospital[], int available_beds[],
float rating_of_hospital[], string Hospital_phn_num[],
string name_of_doctor[], int total_cost[])
{
vector<Hospital_details> hospitals;
Hospital_details h;
for (int j = 0; j < 4; j++) {
h.Name_of_hospital = Name_of_hospital[j];
h.Hospital_location = location_of_hospital[j];
h.Total_available_beds = available_beds[j];
h.Hospital_rating = rating_of_hospital[j];
h.Hospital_phn_num = Hospital_phn_num[j];
h.name_of_doctor = name_of_doctor[j];
h.total_price = total_cost[j];
hospitals.push_back(h);
}
vector<Patient_details> patients;
Patient_details p;
for (int j = 0; j < 4; j++) {
p.P_name = P_name[j];
p.P_id = P_id[j];
p.Hospital_phn_num = P_phone_num[j];
p.total_price = cost_for_booking[j];
patients.push_back(p);
}
cout << endl;
Hospital_Data(hospitals);
Patient_data(patients, hospitals);
Sorting_by_hospitalname(hospitals);
Sorting_by_hospitalrating(hospitals);
Hospital_through_city("Hyderabad", hospitals);
Sorting_by_totalbedsavailable(hospitals);
Sorting_by_beds_price(hospitals);
}
int main()
{
string P_name[] = { "Patient 1", "Patient 2", "Patient 3", "Patient 4" };
int P_id[] = { 211, 212, 213, 214 };
string P_phone_num[] = { "9999999999", "8888888888", "7777777777", "6666666666" };
int cost_for_booking[] = { 1500, 2100, 900, 1900 };
string Name_of_hospital[] = { "Hospital 1", "Hospital 2", "Hospital 3", "Hospital 4" };
string location_of_hospital[] = { "Hyderabad", "Pune ", "Hyderabad", "Kerala " };
int available_beds[] = { 6, 9, 4, 8 };
float rating_of_hospital[] = { 6.5, 8.9, 4.5, 6.9 };
string Hospital_phn_num[] = { "1111111111", "2222222222", "3333333333", "4444444444" };
string name_of_doctor[] = { "Doctor 1", "Doctor 2", "Doctor 3", "Doctor 4" };
int total_cost[] = { 150, 180, 200, 350 };
Hospital_management_system (P_name, P_id, P_phone_num, cost_for_booking, Name_of_hospital, location_of_hospital, available_beds, rating_of_hospital, Hospital_phn_num, name_of_doctor, total_cost);
return 0;
}
Output:
![Hospital Management System in C++](https://static.tutorialandexample.com/cpp/hospital-management-system-in-cpp1.png)
![Hospital Management System in C++](https://static.tutorialandexample.com/cpp/hospital-management-system-in-cpp2.png)
Conclusion:
This is complete tutorial about the hospital management system in C++ language.