0% found this document useful (0 votes)
156 views17 pages

Hospital Management System in C++ - GeeksforGeeks

The document discusses a C++ program designed to manage a Hospital Management System, detailing functionalities such as printing hospital and patient data, and sorting hospitals by various criteria. Key functions include printing hospital data, sorting by name, rating, available beds, and price, as well as filtering hospitals by city. The implementation involves creating classes for hospitals and patients, initializing data, and executing various operations to manage hospital information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views17 pages

Hospital Management System in C++ - GeeksforGeeks

The document discusses a C++ program designed to manage a Hospital Management System, detailing functionalities such as printing hospital and patient data, and sorting hospitals by various criteria. Key functions include printing hospital data, sorting by name, rating, available beds, and price, as well as filtering hospitals by city. The implementation involves creating classes for hospitals and patients, initializing data, and executing various operations to manage hospital information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Hospital Management System in C++

In this article, a C++ program is discussed to manage the Hospital Management


System. Given data of Hospitals with the name of hospital, contact and doctors
and patients below are the functionalities that needed to be implemented:

Functions Supported:

Print Hospital DATA


Print Patients data
SORT BY Beds Price
SORT BY Available Beds
SORT BY NAME
SORT BY Rating and reviews
Print hospital of any specific city

The important functions in the program:

1. PrintHospitalData() : It will print all the hospitals data.


2. PrintPatientData() : It will print all the hospitals data.
3. SortHospitalByName(): Sort all the hospitals from name
4. SortHospitalByRating(): Sort hospitals according to rating
5. SortByBedsAvailable() : Sort hospitals according to beds available
6. SortByBedsPrice(): Sort hospitals according to the minimum price.

Approach:

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 1 of 17
:
Create
classes
for both the Hospital dataset and Patient data.
Initialize variables that store Hospital dataset and Patient data.
Create
Objects
for hospitals and Patient classes that access the Hospital dataset and Patient
data.
use two
arrays
that hold the Hospital dataset and Patient data.
Implement the given functionality as shown below.

Below is the implementation of the above approach.

C++

// C++ program to implement the Hospital


// Management System
#include <bits/stdc++.h>
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

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 2 of 17
:
class Patient : public Hospital {
public:
string P_name;
int P_id;
};

// Hospital Data
void PrintHospitalData(
vector<Hospital>&
C++ Data hospitals)
Types C++ Input/Output C++ Arrays C++ Pointers C++ OOPs C++ STL C++ Interview
{
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<Patient>& patients,

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 3 of 17
:
vector<Hospital>& 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<Hospital> hospitals)
{
// Sort the date
sort(hospitals.begin(),
hospitals.end(),
name);

cout << "SORT BY NAME:"


<< endl

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 4 of 17
:
<< 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<Hospital> 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<Hospital> hospitals)
{
sort(hospitals.begin(),
hospitals.end(),
beds);

cout << "SORT BY Available Beds:"


<< endl
<< endl;

PrintHospitalData(hospitals);
}

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 5 of 17
:
// 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<Hospital> 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<Hospital> 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

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 6 of 17
:
<< " "
<< 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<Hospital> 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<Patient> patients;
Patient p;

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 7 of 17
:
// 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,

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 8 of 17
:
ratings, hospital_Contact, doctor_Name, prices);

return 0;
}

Output:

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 9 of 17
:
Your options after clearing GATE Examinations can be:
1. Go for higher studies in prestigious IITs
2. Apply for job roles in PSUs or MNCs
3. Specialize further in AI or Cybersecurity
4. Take up teaching roles
5. And much more!

Sounds like something you wish to learn more about? Register for Free GATE
Counselling session with our experts and they shall guide you in the right
direction.

Also get assured GfG T-Shirts if you attend the counselling. Register Now.
NOTE: This service is exclusively for the students in Delhi/NCR Region as
the classroom program for GATE is in our Noida Center only. We are soon
coming up with more all across India!

Maximize your earnings for your published articles in Dev Scripter 2024!
Showcase expertise, gain recognition & get extra compensation while elevating
your tech profile.

Last Updated : 18 Jan, 2021 7

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 10 of 17
:
Previous Next

Share your thoughts in the comments Add Your Comment

Similar Reads
Hospital Management Application Hospital Appointment System using
using MERN Stack Express

Menu-Driven Program for Bank Student Information Management


Management System System

GUI Application for the Student Program for Employee Management


Management System System

Project Idea | Water Management


ATM Management System using C++
System

Bookshop management system Employee Management System


using file handling using doubly linked list in C

ajaykr00kj

Article Tags : Technical Scripter 2020 , C++ , C++ Programs , Project ,


Technical Scripter

Practice Tags :CPP

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 11 of 17
:
A-143, 9th Floor, Sovereign Corporate
Tower, Sector-136, Noida, Uttar Pradesh -
201305

Company

About Us

Legal

Careers

In Media

Contact Us

Advertise with us

GFG Corporate Solution

Placement Training Program

Explore

Job-A-Thon Hiring Challenge

Hack-A-Thon

GfG Weekly Contest

Offline Classes (Delhi/NCR)

DSA in JAVA/C++

Master System Design

Master CP

GeeksforGeeks Videos

Geeks Community

Languages
Python

Java

C++

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 12 of 17
:
C++

PHP

GoLang

SQL

R Language

Android Tutorial

DSA

Data Structures

Algorithms

DSA for Beginners

Basic DSA Problems

DSA Roadmap

DSA Interview Questions

Competitive Programming

Data Science & ML

Data Science With Python

Data Science For Beginner

Machine Learning Tutorial

ML Maths

Data Visualisation Tutorial

Pandas Tutorial

NumPy Tutorial

NLP Tutorial

Deep Learning Tutorial

Web Technologies

HTML

CSS

JavaScript

TypeScript

ReactJS

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 13 of 17
:
ReactJS

NextJS

NodeJs

Bootstrap

Tailwind CSS

Python
Python Programming Examples

Django Tutorial

Python Projects

Python Tkinter

Web Scraping

OpenCV Python Tutorial

Python Interview Question

Computer Science
GATE CS Notes

Operating Systems

Computer Network

Database Management System

Software Engineering

Digital Logic Design

Engineering Maths

DevOps

Git

AWS

Docker

Kubernetes

Azure

GCP

DevOps Roadmap

System Design

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 14 of 17
:
System Design
High Level Design

Low Level Design

UML Diagrams

Interview Guide

Design Patterns

OOAD

System Design Bootcamp

Interview Questions

School Subjects
Mathematics

Physics

Chemistry

Biology

Social Science

English Grammar

Commerce
Accountancy

Business Studies

Economics

Management

HR Management

Finance

Income Tax

UPSC Study Material

Polity Notes

Geography Notes

History Notes

Science and Technology Notes

Economy Notes

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 15 of 17
:
Economy Notes

Ethics Notes

Previous Year Papers

Preparation Corner

Company-Wise Recruitment Process

Resume Templates

Aptitude Preparation

Puzzles

Company-Wise Preparation

Companies

Colleges

Competitive Exams

JEE Advanced

UGC NET

SSC CGL

SBI PO

SBI Clerk

IBPS PO

IBPS Clerk

More Tutorials
Software Development

Software Testing

Product Management

Project Management

Linux

Excel

All Cheat Sheets

Free Online Tools


Typing Test

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 16 of 17
:
Image Editor

Code Formatters

Code Converters

Currency Converter

Random Number Generator

Random Password Generator

Write & Earn


Write an Article

Improve an Article

Pick Topics to Write

Share your Experiences

Internships

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

https://www.geeksforgeeks.org/hospital-management-system-in-c/ 12/03/24, 3 00 PM
Page 17 of 17
:

You might also like