Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, I need help in a C ++ code, it's about an assignment on Hospital System Management, I have this code and I need to

Hi, I need help in a C ++ code, it's about an assignment on Hospital System Management, I have this code and I need to implement data structres, it would be a great favor to help me as soon as possible, I have to implement bags, linked list, stacks and if possible trees, you can modify the code and do it at your best, and create a class of the rooms of the hospital and add patients to it, it would be very pleasant thank you.

#include #include #include #include

using namespace std; // define maximum number of patients in a queue #define MAXPATIENTS 100 #define MAXDOCTORS 100

int choice = 0, success; // define structure for patient data struct patient { char FirstName[50]; char LastName[50]; char ID[20]; char age[20]; char room[20]; }; struct doctor { char FirstName[50]; char LastName[50]; char ID[20]; char age[20]; char room[20]; };

// define class for queue class queue { public: queue (void); int AddDoctorAtEnd(doctor d); int AddPatientAtEnd (patient p); int AddPatientAtBeginning (patient p); patient GetNextPatient (void); doctor GetNextDoctor(); int RemoveDeadPatient (patient * p); void OutputList (void); char DepartmentName[50]; private: int NumberOfPatients; int NumberOfDoctors; patient List[MAXPATIENTS]; doctor List2[MAXDOCTORS]; };

// declare member functions for queue

queue::queue () { // constructor NumberOfPatients = 0; NumberOfDoctors=0; }

int queue::AddPatientAtEnd (patient p) { // adds a normal patient to the end of the queue. // returns 1 if successful, 0 if queue is full. if (NumberOfPatients >= MAXPATIENTS) { // queue is full return 0; } // put in new patient else List[NumberOfPatients] = p; NumberOfPatients++; return 1; }

int queue::AddDoctorAtEnd (doctor d) { // adds a normal doctor to the end of the queue. // returns 1 if successful, 0 if queue is full. if (NumberOfDoctors >= MAXDOCTORS) { // queue is full return 0; } // put in new patient else List2[NumberOfDoctors] = d; NumberOfDoctors++; return 1; }

int queue::AddPatientAtBeginning (patient p) { // adds a critically ill patient to the beginning of the queue. // returns 1 if successful, 0 if queue is full. int i; if (NumberOfPatients >= MAXPATIENTS) { // queue is full return 0; }

// move all patients one position back in queue for (i = NumberOfPatients-1; i >= 0; i--) { List[i+1] = List[i]; } // put in new patient List[0] = p; NumberOfPatients++; return 1; }

patient queue::GetNextPatient (void) { // gets the patient that is first in the queue. // returns patient with no ID if queue is empty

int i; patient p; if (NumberOfPatients == 0) { // queue is empty strcpy(p.ID,""); return p;} // get first patient p = List[0]; // move all remaining patients one position forward in queue NumberOfPatients--; for (i=0; i

int i; doctor d; if (NumberOfDoctors == 0) { // queue is empty strcpy(d.ID,""); return d;} // get first patient d = List2[0]; // move all remaining patients one position forward in queue NumberOfDoctors--; for (i=0; i

int queue::RemoveDeadPatient (patient * p) { // removes a patient from queue. // returns 1 if successful, 0 if patient not found int i, j, found = 0; // search for patient for (i=0; iID) == 0) { // patient found in queue *p = List[i]; found = 1; // move all following patients one position forward in queue NumberOfPatients--; for (j=i; j

void queue::OutputList (void) { // lists entire queue on screen int i; if(NumberOfPatients == 0) {

cout<<"Queue is empty"<

} else {

for (i=0; i

doctor InputDoctor (void) { // this function asks user for patient data. doctor d; cout << " Please enter data for new Doctor First name:"; cin.getline(d.FirstName, sizeof(d.FirstName)); cout << "Last name:"; cin.getline(d.LastName, sizeof(d.LastName)); cout << "ID:"; cin.getline(d.ID, sizeof(d.ID)); cout<< "Age:"; cin.getline(d.age, sizeof(d.age)); cout<<"Room.no:"; cin.getline(d.room, sizeof(d.room)); // check if data valid if (d.FirstName[0]==0 || d.LastName[0]==0 || d.ID[0]==0) { // rejected strcpy(d.ID,""); cout << "Error: Data not valid. Operation cancelled."<

patient InputPatient (void) { // this function asks user for patient data. patient p; cout << " Please enter data for new patient First name:"; cin.getline(p.FirstName, sizeof(p.FirstName)); cout << "Last name:"; cin.getline(p.LastName, sizeof(p.LastName)); cout << "ID:"; cin.getline(p.ID, sizeof(p.ID)); cout<< "Age:"; cin.getline(p.age, sizeof(p.age)); cout<<"Room.no"; cin.getline(p.room, sizeof(p.room));

// check if data valid if (p.FirstName[0]==0 || p.LastName[0]==0 || p.ID[0]==0) { // rejected strcpy(p.ID,""); cout << "Error: Data not valid. Operation cancelled."<

void OutputPatient (patient * p) { // this function outputs patient data to the screen if (p == NULL || p->ID[0]==0) { cout << "No patient"<FirstName; cout << " Last name:" << p->LastName; cout << " ID:" << p->ID; cout <<" Age:" <age; cout <<" Room N.:"<room; } void OutputDoctor (doctor * d) { // this function outputs patient data to the screen if (d == NULL || d->ID[0]==0) { cout << "No doctor"<FirstName; cout << " Last name:" << d->LastName; cout << " ID:" << d->ID; cout << " Age:"<< d->age; cout <<" Room N.:"<< d->room; }

int ReadNumber() { // this function reads an integer number from the keyboard. // it is used because input with cin >> doesn't work properly! char buffer[20]; cin.getline(buffer, sizeof(buffer)); return atoi(buffer); }

void DepartmentMenu (queue * q) { // this function defines the user interface with menu for one //int department; int choice = 0, success; patient p; doctor d; while (choice != 7) { // clear screen system("cls"); // print menu cout << "Welcome to department: " << q->DepartmentName; cout << "Please enter your choice: "; cout << "1: Add normal patient "; cout << "2: Add a Doctor "; cout << "3: Add critically patient "; cout << "4: Take out patient for operation "; cout << "5: Remove dead patient from queue "; cout << "6: List queue Patients "; cout << "7: Change department or exit "; // get user choice choice = ReadNumber(); // do indicated action switch (choice) { case 1: // Add normal patient p = InputPatient(); if (p.ID[0]) { success = q->AddPatientAtEnd(p); system("cls"); if (success) { cout << "Patient added:";

} else { // error cout << "Error: The queue is full. Cannot add patient:"<

case 2: // Add doctor d = InputDoctor(); if (d.ID[0]) { success = q->AddDoctorAtEnd(d); system("cls"); if (success) { cout << "Doctor added:";

} else { // error cout << "Error: The queue is full. Cannot add patient:"<

case 3: // Add critically ill patient p = InputPatient(); if (p.ID[0]) { success = q->AddPatientAtBeginning(p); system("cls"); if (success) { cout << "Patient added:"; } else { // error cout << "Error: The queue is full. Cannot add patient:"<

OutputPatient(&p); cout << "Press any key"; getch(); } break;

case 4: // Take out patient for operation p = q->GetNextPatient(); system("cls"); if (p.ID[0]) { cout << "Patient to operate:"; OutputPatient(&p);} else { cout << "There is no patient to operate."<

case 5: // Remove dead patient from queue p = InputPatient(); if (p.ID[0]) { success = q->RemoveDeadPatient(&p); system("cls"); if (success) { cout << "Patient removed:"; } else { // error cout << "Error: Cannot find patient:"; } OutputPatient(&p); cout << "Press any key"; getch(); } break;

case 6: // List queue system("cls"); q->OutputList(); cout << "Press any key"; getch(); break; } } }

// main function defining queues and main menu int main () { system("color f4"); int i, MenuChoice = 0; // define three queues queue departments[4]; // set department names strcpy (departments[0].DepartmentName, "Heart clinic "); strcpy (departments[1].DepartmentName, "Lung clinic "); strcpy (departments[2].DepartmentName, "Plastic surgery "); strcpy (departments[3].DepartmentName, "Neurosurgery clinic ");

while (MenuChoice != 5) { // clear screen system("cls"); // print menu cout << " ****************Welcome to Hospital System Management***************** "; cout << " Please enter your choice: "; for (i = 0; i < 4; i++) { // write menu item for department i cout << "" << (i+1) << ": " << departments[i].DepartmentName; } cout << "5: Exit "; // get user choice MenuChoice = ReadNumber(); // is it a department name? if (MenuChoice >= 1 && MenuChoice <= 4) { // call submenu for department // (using pointer arithmetics here:) DepartmentMenu (departments + (MenuChoice-1)); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

understand possible effects of ethnicity;

Answered: 1 week ago