online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> using namespace std; #define MAX_DOCTORS 500 #define MAX_PATIENTS 10000 #define MAX_NURSES 100 class Person { protected: string Name, Gender, Contact_Info; int Age; public: void setName(string n) { Name = n; } void setGender(string g) { Gender = g; } void setContactInfo(string contact) { Contact_Info = contact; } void setAge(int a) { Age = a; } string getName() { return Name; } string getGender() { return Gender; } string getContactInfo() { return Contact_Info; } int getAge() { return Age; } void promptBasicInfo() { string fname, lname; cout << "\nEnter First Name: "; cin >> fname; cout << "Enter Last Name: "; cin >> lname; Name = fname + " " + lname; cout << "Enter Gender: "; cin >> Gender; cout << "Enter Contact Info: "; cin >> Contact_Info; cout << "Enter Age: "; cin >> Age; } void displayBasicInfo() { cout << "\n-----------------------------------------\n"; cout << "Name: " << getName() << "\nGender: " << getGender() << "\nContact Info: " << getContactInfo() << "\nAge: " << getAge(); } }; class Nurse : public Person { private: string NurseId, AssignedDoctorId; public: void setNurseId(string id) { NurseId = id; } void setAssignedDoctorId(string docId) { AssignedDoctorId = docId; } string getNurseId() { return NurseId; } string getAssignedDoctorId() { return AssignedDoctorId; } void promptNurseDetails() { cout << "\n=========== NURSE REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Nurse ID: "; cin >> NurseId; cout << "Enter Assigned Doctor ID: "; cin >> AssignedDoctorId; } void displayDetails() { cout << "\n========== NURSE DETAILS ==========="; displayBasicInfo(); cout << "\nNurse ID: " << getNurseId() << "\nAssigned Doctor ID: " << getAssignedDoctorId() << endl; } }; class Patient : public Person { private: string Diagnosis, Prescription, VisitDate; float TreatmentFee = 0, MedicineCharges = 0; string AssignedDoctorId; string AssignedNurseId; public: void setDiagnosis(string d) { Diagnosis = d; } void setPrescription(string p) { Prescription = p; } void setVisitDate(string v) { VisitDate = v; } void setTreatmentFee(float f) { TreatmentFee = f; } void setMedicineCharges(float m) { MedicineCharges = m; } void setAssignedDoctorId(string id) { AssignedDoctorId = id; } void setAssignedNurseId(string id) { AssignedNurseId = id; } string getDiagnosis() { return Diagnosis; } string getPrescription() { return Prescription; } string getVisitDate() { return VisitDate; } float getTreatmentFee() { return TreatmentFee; } float getMedicineCharges() { return MedicineCharges; } string getAssignedDoctorId() { return AssignedDoctorId; } string getAssignedNurseId() { return AssignedNurseId; } float calculateBill() const { return 500 + TreatmentFee + MedicineCharges; } void promptPatientDetails(string nurseId) { cout << "\n=========== PATIENT REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Date of Visit (YYYY-MM-DD): "; cin >> VisitDate; setAssignedNurseId(nurseId); } void displayDetails() { cout << "\n========== PATIENT DETAILS ==========="; displayBasicInfo(); cout << "\nDiagnosis: " << getDiagnosis() << "\nPrescription: " << getPrescription() << "\nVisit Date: " << getVisitDate() << "\nTreatment Fee: " << getTreatmentFee() << "\nMedicine Charges: " << getMedicineCharges() << "\nTotal Bill: KES " << calculateBill() << "\nAssigned Doctor ID: " << getAssignedDoctorId() << "\nAssigned Nurse ID: " << getAssignedNurseId() << endl; } }; class Doctor : public Person { private: string DoctorId, Specialization; public: void setDoctorId(string id) { DoctorId = id; } void setSpecialization(string s) { Specialization = s; } string getDoctorId() { return DoctorId; } string getSpecialization() { return Specialization; } void promptDoctorDetails() { cout << "\n=========== DOCTOR REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Doctor ID: "; cin >> DoctorId; cout << "Enter Specialization: "; cin >> Specialization; } void displayDetails() { cout << "\n========== DOCTOR DETAILS ==========="; displayBasicInfo(); cout << "\nDoctor ID: " << getDoctorId() << "\nSpecialization: " << getSpecialization() << endl; } void updatePatientDiagnosis(Patient &p, Nurse nurses[], int nurseCount) { cout << "\n=========== UPDATE PATIENT DIAGNOSIS ==========="; string diag, presc; float treatment, meds; cout << "\nEnter Diagnosis: "; cin >> diag; cout << "Enter Prescription: "; cin >> presc; cout << "Enter Treatment Fee: "; cin >> treatment; cout << "Enter Medicine Charges: "; cin >> meds; p.setDiagnosis(diag); p.setPrescription(presc); p.setTreatmentFee(treatment); p.setMedicineCharges(meds); p.setAssignedDoctorId(DoctorId); for (int i = 0; i < nurseCount; ++i) { if (nurses[i].getAssignedDoctorId() == DoctorId) { p.setAssignedNurseId(nurses[i].getNurseId()); break; } } cout << "\n Patient Updated Successfully!" << endl; } }; class Receptionist : public Person { private: string ReceptionistId; public: void setReceptionistId(string id) { ReceptionistId = id; } string getReceptionistId() { return ReceptionistId; } void promptReceptionistDetails() { cout << "\n=========== RECEPTIONIST REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Receptionist ID: "; cin >> ReceptionistId; } void displayDetails() { cout << "\n========== RECEPTIONIST DETAILS ==========="; displayBasicInfo(); cout << "\nReceptionist ID: " << getReceptionistId() << endl; } }; Doctor doctors[MAX_DOCTORS]; Patient patients[MAX_PATIENTS]; Nurse nurses[MAX_NURSES]; int doctorCount = 0, patientCount = 0, nurseCount = 0; int getNextNurseIndex() { if (nurseCount == 0) return -1; return patientCount % nurseCount; } void receptionistMenu() { if (nurseCount == 0) { cout << " No nurses available. Please register at least one nurse before registering patients.\n"; return; } int nurseIndex = getNextNurseIndex(); string nurseId = nurses[nurseIndex].getNurseId(); patients[patientCount].promptPatientDetails(nurseId); patientCount++; } void searchPatientByName() { string searchName; cout << "Enter full patient name to search: "; cin >> searchName; for (int i = 0; i < patientCount; ++i) { if (patients[i].getName() == searchName) { patients[i].displayDetails(); return; } } cout << "No patient found with that name.\n"; } int main() { int choice; do { cout << "\n============= HOSPITAL SYSTEM MENU ============="; cout << "\n1. Register Doctor (Admin)"; cout << "\n2. Register Nurse"; cout << "\n3. Register Patient (Receptionist)"; cout << "\n4. Doctor Login and Update Patient"; cout << "\n5. View All Doctors"; cout << "\n6. View All Nurses"; cout << "\n7. View All Patients"; cout << "\n0. Exit"; cout << "\n===============================================\n"; cout << "Enter your choice: "; cin >> choice; switch (choice) { case 1: if (doctorCount < MAX_DOCTORS) doctors[doctorCount++].promptDoctorDetails(); else cout << "Doctor limit reached!\n"; break; case 2: if (nurseCount < MAX_NURSES) nurses[nurseCount++].promptNurseDetails(); else cout << "Nurse limit reached!\n"; break; case 3: receptionistMenu(); break; case 4: { string docId; cout << "Enter Doctor ID to log in: "; cin >> docId; bool found = false; for (int i = 0; i < doctorCount; i++) { if (doctors[i].getDoctorId() == docId) { found = true; cout << "Doctor Found: " << doctors[i].getName() << endl; if (patientCount == 0) { cout << "No patients registered yet.\n"; break; } for (int j = 0; j < patientCount; j++) { cout << j << ". " << patients[j].getName() << endl; } int index; cout << "Enter Patient Index (0 to " << patientCount - 1 << "): "; cin >> index; if (index >= 0 && index < patientCount) doctors[i].updatePatientDiagnosis(patients[index], nurses, nurseCount); else cout << "Invalid index.\n"; break; } } if (!found) cout << "Doctor not found!\n"; break; } case 5: for (int i = 0; i < doctorCount; i++) doctors[i].displayDetails(); break; case 6: for (int i = 0; i < nurseCount; i++) nurses[i].displayDetails(); break; case 7: for (int i = 0; i < patientCount; i++) patients[i].displayDetails(); break; case 8: searchPatientByName(); break; case 0: cout << "\nThank you for using the Hospital System. Goodbye!\n"; break; default: cout << "Invalid option. Please try again.\n"; } } while (choice != 0); return 0; }
#include <iostream> using namespace std; #define MAX_DOCTORS 500 #define MAX_PATIENTS 10000 #define MAX_NURSES 100 class Person { protected: string Name, Gender, Contact_Info; int Age; public: void setName(string n) { Name = n; } void setGender(string g) { Gender = g; } void setContactInfo(string contact) { Contact_Info = contact; } void setAge(int a) { Age = a; } string getName() { return Name; } string getGender() { return Gender; } string getContactInfo() { return Contact_Info; } int getAge() { return Age; } void promptBasicInfo() { string fname, lname; cout << "\nEnter First Name: "; cin >> fname; cout << "Enter Last Name: "; cin >> lname; Name = fname + " " + lname; cout << "Enter Gender: "; cin >> Gender; cout << "Enter Contact Info: "; cin >> Contact_Info; cout << "Enter Age: "; cin >> Age; } void displayBasicInfo() { cout << "\n-----------------------------------------\n"; cout << "Name: " << getName() << "\nGender: " << getGender() << "\nContact Info: " << getContactInfo() << "\nAge: " << getAge(); } }; class Nurse : public Person { private: string NurseId, AssignedDoctorId; public: void setNurseId(string id) { NurseId = id; } void setAssignedDoctorId(string docId) { AssignedDoctorId = docId; } string getNurseId() { return NurseId; } string getAssignedDoctorId() { return AssignedDoctorId; } void promptNurseDetails() { cout << "\n=========== NURSE REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Nurse ID: "; cin >> NurseId; cout << "Enter Assigned Doctor ID: "; cin >> AssignedDoctorId; } void displayDetails() { cout << "\n========== NURSE DETAILS ==========="; displayBasicInfo(); cout << "\nNurse ID: " << getNurseId() << "\nAssigned Doctor ID: " << getAssignedDoctorId() << endl; } }; class Patient : public Person { private: string Diagnosis, Prescription, VisitDate; float TreatmentFee = 0, MedicineCharges = 0; string AssignedDoctorId; string AssignedNurseId; public: void setDiagnosis(string d) { Diagnosis = d; } void setPrescription(string p) { Prescription = p; } void setVisitDate(string v) { VisitDate = v; } void setTreatmentFee(float f) { TreatmentFee = f; } void setMedicineCharges(float m) { MedicineCharges = m; } void setAssignedDoctorId(string id) { AssignedDoctorId = id; } void setAssignedNurseId(string id) { AssignedNurseId = id; } string getDiagnosis() { return Diagnosis; } string getPrescription() { return Prescription; } string getVisitDate() { return VisitDate; } float getTreatmentFee() { return TreatmentFee; } float getMedicineCharges() { return MedicineCharges; } string getAssignedDoctorId() { return AssignedDoctorId; } string getAssignedNurseId() { return AssignedNurseId; } float calculateBill() const { return 500 + TreatmentFee + MedicineCharges; } void promptPatientDetails(string nurseId) { cout << "\n=========== PATIENT REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Date of Visit (YYYY-MM-DD): "; cin >> VisitDate; setAssignedNurseId(nurseId); } void displayDetails() { cout << "\n========== PATIENT DETAILS ==========="; displayBasicInfo(); cout << "\nDiagnosis: " << getDiagnosis() << "\nPrescription: " << getPrescription() << "\nVisit Date: " << getVisitDate() << "\nTreatment Fee: " << getTreatmentFee() << "\nMedicine Charges: " << getMedicineCharges() << "\nTotal Bill: KES " << calculateBill() << "\nAssigned Doctor ID: " << getAssignedDoctorId() << "\nAssigned Nurse ID: " << getAssignedNurseId() << endl; } }; class Doctor : public Person { private: string DoctorId, Specialization; public: void setDoctorId(string id) { DoctorId = id; } void setSpecialization(string s) { Specialization = s; } string getDoctorId() { return DoctorId; } string getSpecialization() { return Specialization; } void promptDoctorDetails() { cout << "\n=========== DOCTOR REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Doctor ID: "; cin >> DoctorId; cout << "Enter Specialization: "; cin >> Specialization; } void displayDetails() { cout << "\n========== DOCTOR DETAILS ==========="; displayBasicInfo(); cout << "\nDoctor ID: " << getDoctorId() << "\nSpecialization: " << getSpecialization() << endl; } void updatePatientDiagnosis(Patient &p, Nurse nurses[], int nurseCount) { cout << "\n=========== UPDATE PATIENT DIAGNOSIS ==========="; string diag, presc; float treatment, meds; cout << "\nEnter Diagnosis: "; cin >> diag; cout << "Enter Prescription: "; cin >> presc; cout << "Enter Treatment Fee: "; cin >> treatment; cout << "Enter Medicine Charges: "; cin >> meds; p.setDiagnosis(diag); p.setPrescription(presc); p.setTreatmentFee(treatment); p.setMedicineCharges(meds); p.setAssignedDoctorId(DoctorId); for (int i = 0; i < nurseCount; ++i) { if (nurses[i].getAssignedDoctorId() == DoctorId) { p.setAssignedNurseId(nurses[i].getNurseId()); break; } } cout << "\n Patient Updated Successfully!" << endl; } }; class Receptionist : public Person { private: string ReceptionistId; public: void setReceptionistId(string id) { ReceptionistId = id; } string getReceptionistId() { return ReceptionistId; } void promptReceptionistDetails() { cout << "\n=========== RECEPTIONIST REGISTRATION ==========="; promptBasicInfo(); cout << "Enter Receptionist ID: "; cin >> ReceptionistId; } void displayDetails() { cout << "\n========== RECEPTIONIST DETAILS ==========="; displayBasicInfo(); cout << "\nReceptionist ID: " << getReceptionistId() << endl; } }; Doctor doctors[MAX_DOCTORS]; Patient patients[MAX_PATIENTS]; Nurse nurses[MAX_NURSES]; int doctorCount = 0, patientCount = 0, nurseCount = 0; int getNextNurseIndex() { if (nurseCount == 0) return -1; return patientCount % nurseCount; } void receptionistMenu() { if (nurseCount == 0) { cout << " No nurses available. Please register at least one nurse before registering patients.\n"; return; } int nurseIndex = getNextNurseIndex(); string nurseId = nurses[nurseIndex].getNurseId(); patients[patientCount].promptPatientDetails(nurseId); patientCount++; } void searchPatientByName() { string searchName; cout << "Enter full patient name to search: "; cin >> searchName; for (int i = 0; i < patientCount; ++i) { if (patients[i].getName() == searchName) { patients[i].displayDetails(); return; } } cout << "No patient found with that name.\n"; } int main() { int choice; do { cout << "\n============= HOSPITAL SYSTEM MENU ============="; cout << "\n1. Register Doctor (Admin)"; cout << "\n2. Register Nurse"; cout << "\n3. Register Patient (Receptionist)"; cout << "\n4. Doctor Login and Update Patient"; cout << "\n5. View All Doctors"; cout << "\n6. View All Nurses"; cout << "\n7. View All Patients"; cout << "\n0. Exit"; cout << "\n===============================================\n"; cout << "Enter your choice: "; cin >> choice; switch (choice) { case 1: if (doctorCount < MAX_DOCTORS) doctors[doctorCount++].promptDoctorDetails(); else cout << "Doctor limit reached!\n"; break; case 2: if (nurseCount < MAX_NURSES) nurses[nurseCount++].promptNurseDetails(); else cout << "Nurse limit reached!\n"; break; case 3: receptionistMenu(); break; case 4: { string docId; cout << "Enter Doctor ID to log in: "; cin >> docId; bool found = false; for (int i = 0; i < doctorCount; i++) { if (doctors[i].getDoctorId() == docId) { found = true; cout << "Doctor Found: " << doctors[i].getName() << endl; if (patientCount == 0) { cout << "No patients registered yet.\n"; break; } for (int j = 0; j < patientCount; j++) { cout << j << ". " << patients[j].getName() << endl; } int index; cout << "Enter Patient Index (0 to " << patientCount - 1 << "): "; cin >> index; if (index >= 0 && index < patientCount) doctors[i].updatePatientDiagnosis(patients[index], nurses, nurseCount); else cout << "Invalid index.\n"; break; } } if (!found) cout << "Doctor not found!\n"; break; } case 5: for (int i = 0; i < doctorCount; i++) doctors[i].displayDetails(); break; case 6: for (int i = 0; i < nurseCount; i++) nurses[i].displayDetails(); break; case 7: for (int i = 0; i < patientCount; i++) patients[i].displayDetails(); break; case 8: searchPatientByName(); break; case 0: cout << "\nThank you for using the Hospital System. Goodbye!\n"; break; default: cout << "Invalid option. Please try again.\n"; } } while (choice != 0); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue