![]() |
hospital management system project in c++ Code |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Patient class
class Patient {
private:
string name;
int age;
string disease;
string doctor;
int room_number;
public:
Patient(string name, int age, string disease, string doctor, int room_number) {
this->name = name;
this->age = age;
this->disease = disease;
this->doctor = doctor;
this->room_number = room_number;
}
void setName(string name) {
this->name = name;
}
void setAge(int age) {
this->age = age;
}
void setDisease(string disease) {
this->disease = disease;
}
void setDoctor(string doctor) {
this->doctor = doctor;
}
void setRoomNumber(int room_number) {
this->room_number = room_number;
}
string getName() {
return name;
}
int getAge() {
return age;
}
string getDisease() {
return disease;
}
string getDoctor() {
return doctor;
}
int getRoomNumber() {
return room_number;
}
};
// Hospital class
class Hospital {
private:
vector<Patient> patients;
public:
void addPatient(Patient patient) {
patients.push_back(patient);
}
void removePatient(string name) {
for (int i = 0; i < patients.size(); i++) {
if (patients[i].getName() == name) {
patients.erase(patients.begin() + i);
cout << "Patient "
<< name << " has been removed." << endl;
break;
}
}
}
void displayPatients() {
if (patients.size() == 0) {
cout << "No patients currently in the hospital." << endl;
return;
}
cout << "Patients in the hospital: " << endl;
for (int i = 0; i < patients.size(); i++) {
cout << "Name: "
<< patients[i].getName()
<< ", Age: "
<< patients[i].getAge()
<< ", Disease: "
<< patients[i].getDisease()
<< ", Doctor: "
<< patients[i].getDoctor()
<< ", Room Number: "
<< patients[i].getRoomNumber() << endl;
}
}
};
int main() {
Hospital hospital;
Patient patient1
("bilal Smith",
35,
"Flu",
"Dr. bilal",
101);
Patient patient2
("farhad marri",
42,
"Broken leg",
"Dr. Smith",
102);
hospital.addPatient(patient1);
hospital.addPatient(patient2);
hospital.displayPatients();
hospital.removePatient("bilal Smith");
hospital.displayPatients();
return 0;
}
0 Comments