0% found this document useful (0 votes)
47 views8 pages

Hospital Management System

Uploaded by

hifadi1393
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views8 pages

Hospital Management System

Uploaded by

hifadi1393
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Hospital Management System

#include <iostream>
#include <string>
#include <vector>
#include <fstream>

using namespace std;

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) {}

virtual void displayInfo() const = 0;


virtual void saveToFile(ofstream& outFile) const = 0;
};

class Staff : public User {


protected:
string designation;

public:
Staff(const string& name, const string& address, long int cnic, const string& designation)
: User(name, address, cnic), designation(designation) {}

void displayInfo() const override {


cout << "\tName: " << name << endl;
cout << "\tCNIC: " << cnic << endl;
cout << "\tAddress: " << address << endl;
cout << "\tDesignation: " << designation << endl;
}

void saveToFile(ofstream& outFile) const override {


outFile << "Staff" << endl;
outFile << name << endl;
outFile << address << endl;
outFile << cnic << endl;
outFile << designation << endl;
}
};

class AdministrativeStaff : public Staff {


public:
AdministrativeStaff(const string& name, const string& address, long int cnic, const string&
designation)
: Staff(name, address, cnic, designation) {}

void saveToFile(ofstream& outFile) const override {


outFile << "AdministrativeStaff" << endl;
Staff::saveToFile(outFile);
}
};

class Nurse : public Staff {


public:
Nurse(const string& name, const string& address, long int cnic, const string& designation)
: Staff(name, address, cnic, designation) {}

void saveToFile(ofstream& outFile) const override {


outFile << "Nurse" << endl;
Staff::saveToFile(outFile);
}
};

class Technician : public Staff {


public:
Technician(const string& name, const string& address, long int cnic, const string& designation)
: Staff(name, address, cnic, designation) {}

void saveToFile(ofstream& outFile) const override {


outFile << "Technician" << endl;
Staff::saveToFile(outFile);
}
};

class Patient : public User {


protected:
string doctorName;

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;
}

void saveToFile(ofstream& outFile) const override {


outFile << "Patient" << endl;
outFile << name << endl;
outFile << address << endl;
outFile << cnic << endl;
outFile << doctorName << endl;
}
};

class Doctor : public User {


protected:
string specialization;

public:
Doctor(const string& name, const string& address, long int cnic, const string& specialization)
: User(name, address, cnic), specialization(specialization) {}

void displayInfo() const override {


cout << "\tName: " << name << endl;
cout << "\tCNIC: " << cnic << endl;
cout << "\tAddress: " << address << endl;
cout << "\tSpecialization: " << specialization << endl;
}

void saveToFile(ofstream& outFile) const override {


outFile << "Doctor" << endl;
outFile << name << endl;
outFile << address << endl;
outFile << cnic << endl;
outFile << specialization << endl;
}
};

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 makeAppointment(const string& patientName, const string& doctorName) {


string appointment = "Appointment for " + patientName + " with " + doctorName;
appointments.push_back(appointment);
cout << "Appointment made for " << patientName << " with " + doctorName << endl;
}

void giveFeedback(const string& patientName, const string& feedback) {


string patientFeedback = "Feedback from " + patientName + ": " + feedback;
feedbacks.push_back(patientFeedback);
cout << "Feedback received from " << patientName << ": " + feedback << endl;
}

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;
}
}
};

void mainMenu(Hospital& hospital) {


int choice;
string dummy; // Dummy string to clear input buffer

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;

cout << "Enter Name: ";


getline(cin, name);
cout << "Enter Address: ";
getline(cin, address);
cout << "Enter CNIC: ";
cin >> cnic;
getline(cin, dummy); // Clear input buffer
cout << "Enter Designation: ";
getline(cin, designation);

Staff* staff = new Staff(name, address, cnic, designation);


hospital.addUser(staff);
}
else if (choice == 4) {
cout << "Make an Appointment\n";
string patientName, doctorName;

cout << "Enter Patient Name: ";


getline(cin, patientName);
cout << "Enter Doctor Name: ";
getline(cin, doctorName);

hospital.makeAppointment(patientName, doctorName);
}
else if (choice == 5) {
cout << "Give Feedback\n";
string patientName, feedback;

cout << "Enter Patient Name: ";


getline(cin, patientName);
cout << "Enter Feedback: ";
getline(cin, 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();

Doctor doctor1("Dr. Iftikhar Ahmad", "Address1", 1234567890, "Heart Specialist");


Doctor doctor2("Dr. Mazhar Iqbal", "Address2", 9876543210, "Child Specialist");
Doctor doctor3("Dr. Haroon Rasheed", "Address3", 1357924680, "Stomach Specialist");

hospital.addUser(&doctor1);
hospital.addUser(&doctor2);
hospital.addUser(&doctor3);

mainMenu(hospital);

return 0;
}

Outputs

You might also like