Hospital Management System
Hospital Management System
Hospital Management System
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
class User {
protected:
string name;
string address;
long int cnic;
public:
User(const string& name, const string& address, long int cnic)
: name(name), address(address), cnic(cnic) {}
public:
Staff(const string& name, const string& address, long int cnic, const string& designation)
: User(name, address, cnic), designation(designation) {}
public:
Patient(const string& name, const string& address, long int cnic, const string& doctorName)
: User(name, address, cnic), doctorName(doctorName) {}
void displayInfo() const override {
cout << "\tName: " << name << endl;
cout << "\tCNIC: " << cnic << endl;
cout << "\tAddress: " << address << endl;
cout << "\tDoctor: " << doctorName << endl;
}
public:
Doctor(const string& name, const string& address, long int cnic, const string& specialization)
: User(name, address, cnic), specialization(specialization) {}
class Hospital {
private:
vector<User*> users;
vector<string> appointments;
vector<string> feedbacks;
public:
void addUser(User* user) {
users.push_back(user);
}
void displayUserInformation() {
for (User* user : users) {
user->displayInfo();
cout << "------------------------\n";
}
}
void checkAppointments() {
cout << "\n======= Appointments =======\n";
for (const string& appointment : appointments) {
cout << appointment << endl;
}
cout << "------------------------\n";
}
void checkFeedbacks() {
cout << "\n======= Feedbacks =======\n";
for (const string& feedback : feedbacks) {
cout << feedback << endl;
}
cout << "------------------------\n";
}
void saveData() {
ofstream userFile("users.txt");
for (User* user : users) {
user->saveToFile(userFile);
}
userFile.close();
ofstream appointmentFile("appointments.txt");
for (const string& appointment : appointments) {
appointmentFile << appointment << endl;
}
appointmentFile.close();
ofstream feedbackFile("feedbacks.txt");
for (const string& feedback : feedbacks) {
feedbackFile << feedback << endl;
}
feedbackFile.close();
}
void loadData() {
ifstream userFile("users.txt");
if (userFile.is_open()) {
string userType;
while (getline(userFile, userType)) {
string name, address, doctorName, specialization, designation;
long int cnic;
getline(userFile, name);
getline(userFile, address);
userFile >> cnic;
userFile.ignore();
if (userType == "Doctor") {
getline(userFile, specialization);
users.push_back(new Doctor(name, address, cnic, specialization));
}
else if (userType == "Patient") {
getline(userFile, doctorName);
users.push_back(new Patient(name, address, cnic, doctorName));
}
else if (userType == "Staff") {
getline(userFile, designation);
users.push_back(new Staff(name, address, cnic, designation));
}
else if (userType == "AdministrativeStaff") {
getline(userFile, designation);
users.push_back(new AdministrativeStaff(name, address, cnic, designation));
}
else if (userType == "Nurse") {
getline(userFile, designation);
users.push_back(new Nurse(name, address, cnic, designation));
}
else if (userType == "Technician") {
getline(userFile, designation);
users.push_back(new Technician(name, address, cnic, designation));
}
}
userFile.close();
}
ifstream appointmentFile("appointments.txt");
if (appointmentFile.is_open()) {
string appointment;
while (getline(appointmentFile, appointment)) {
appointments.push_back(appointment);
}
appointmentFile.close();
}
ifstream feedbackFile("feedbacks.txt");
if (feedbackFile.is_open()) {
string feedback;
while (getline(feedbackFile, feedback)) {
feedbacks.push_back(feedback);
}
feedbackFile.close();
}
}
~Hospital() {
for (User* user : users) {
delete user;
}
}
};
do {
cout << "\n\n\t\t\t\t\t 1.OOP PRJECT BY ABDULLAH FAROOQ \t(ID:f2023266160)\t\t\n";
cout << "\t\t\t\t\t 2.OOP PRJECT BY AHMAD FARAZ \t(ID:f2023266185)\t\t\n";
cout << "\t\t\t\t\t ======================================================\n";
cout << "\n\t\t\t\t :-+WELCOME TO THE JINNAH HOSPITAL+-:\n";
cout << "\n\n\n\t\t======= MAIN MENU =======\n\n\n";
cout << "\t1. Check Doctor's Availability\n";
cout << "\t2. Show Staff Information\n";
cout << "\t3. Add Staff Information\n";
cout << "\t4. Make an Appointment\n";
cout << "\t5. Give Feedback\n";
cout << "\t6. Check Appointments\n";
cout << "\t7. Check Feedbacks\n";
cout << "\t8. Exit\n\n";
cout << "\tEnter your choice between (1 to 8): \n\n";
cin >> choice;
getline(cin, dummy); // Clear input buffer
if (choice == 1 || choice == 2) {
hospital.displayUserInformation();
}
else if (choice == 3) {
cout << "Adding Staff Information\n";
string name, address, designation;
long int cnic;
hospital.makeAppointment(patientName, doctorName);
}
else if (choice == 5) {
cout << "Give Feedback\n";
string patientName, feedback;
hospital.giveFeedback(patientName, feedback);
}
else if (choice == 6) {
hospital.checkAppointments();
}
else if (choice == 7) {
hospital.checkFeedbacks();
}
else if (choice == 8) {
hospital.saveData();
cout << "Exiting...\n";
}
else {
cout << "Invalid choice. Please try again.\n";
}
} while (choice != 8);
}
int main() {
Hospital hospital;
hospital.loadData();
hospital.addUser(&doctor1);
hospital.addUser(&doctor2);
hospital.addUser(&doctor3);
mainMenu(hospital);
return 0;
}
Outputs