Hi, I need help in a C ++ code, it\'s about an assignment on Hospital System Man
ID: 3874292 • Letter: H
Question
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 queues, 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<iostream>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
struct doctor1
{
int id;
char name[10],age[10],exp[10],city[10],special[10];
};
struct patient1
{
int id1;
char name[10],age[10],city[10],dis[10],room[10],charg[10],bill[10];
};
using namespace std;
class doctor;
class patient;
class hospital
{
public:
int counter=0;
};
class doctor:public hospital
{
public:
int docid=0;
struct doctor1 arr[10];
void add_doc_info()
{
int i,en;
cout<<"How Many Entries you want to add :";
cin>>en;
for(i=1;i<=en;i++)
{
cout<<"Enter Doctor's ID :";
cin>>arr[docid].id;
cout<<"Enter Doctor's Name :";
cin>>arr[docid].name;
cout<<"Enter Doctor's Age :";
cin>>arr[docid].age;
cout<<"Enter Doctor's Specialization :";
cin>>arr[docid].special;
cout<<"Enter Doctor's Experience :";
cin>>arr[docid].exp;
cout<<"Enter Doctor's city :";
cin>>arr[docid].city;
docid++;
counter++;
cout<<" ";
cout<<"You filled all Entries of "<<i<<" doctor successfully"<<" ";
cout<<"enter value for "<<" "<<i+1<<" "<<"doctor"<<" ";
}
}
void Display()
{
system("cls");
int n,i;
cout<<" Enter the doctor's ID to display Record :";
cin>>n;
if(n==0)
{
cout<<" OOPS!!!! "<<" ";
cout<<"Note:- No Record To Display Please Go Back And Enter Some Entries...... "<<" ";
}
else
{
int status=0;
for(i=0;i<docid;i++)
{
if(arr[i].id==n)
{
status=1;
break;
}
}
if(status)
{
cout<<" ";
cout<<"1.Doctor's ID :"<<arr[i].id<<" ";
cout<<"2.Doctor's Name :"<<arr[i].name<<" ";
cout<<"3.Doctor's Age :"<<arr[i].age<<" ";
cout<<"4.Doctor's Specialization :"<<arr[i].special<<" ";
cout<<"5.Doctor's Experience :"<<arr[i].exp<<" ";
cout<<"6.Doctor's city :"<<arr[i].city<<" ";
cout<<" Press Any KEY To choose another Option.... ";
}
else
{
cout<<" No such ID in database "<<endl;
cout<<" Press Any KEY To choose another Option.... ";
}
}
getch();
}
void doctor_detail()
{
int i;
if(docid==0)
{
cout<<" OOPS!!!! "<<" ";
cout<<"Note:- No Record To Display Please Go Back And Enter Some Entries...... "<<" ";
}
else{
cout<<"********************************************************************************"<<" ";
cout<<" Details Of All The Doctors In The Hospital ";
cout<<"********************************************************************************"<<" ";
cout<<"ID"<<" "<<"specialization"<<" "<<"Age";
cout<<" ";
for(i=0;i<docid;i++)
{
cout<<arr[i].id<<" "<<arr[i].special<<" "<<arr[i].age<<" ";
}
cout<<" Press Any Button To choose another Option.... ";
}
getch();
}
void tot_no_of_doc()
{
system("cls");
int i=counter;
cout<<"Total Doctor's in Hospital : "<<i<<" ";
cout<<" Press Any Button To choose another Option.... ";
getch();
}
};
class patient:public hospital
{
public:
int docid1=0;
struct patient1 arr[10];
void add_pat_info();
void Display();
void patient_report();
void patient_detail();
void tot_no_of_pat();
void gen_pat_report();
};
void patient :: add_pat_info()
{
int i,en;
cout<<"How Many Entries you want to add :";
cin>>en;
for(i=1;i<=en;i++)
{
cout<<" 1. Enter Patient's ID :";
cin>>arr[docid1].id1;
cout<<" 2. Enter patient's Name :";
cin>>arr[docid1].name;
cout<<" 3. Enter patient's Age :";
cin>>arr[docid1].age;
cout<<" 4. Enter patient's Disease :";
cin>>arr[docid1].dis;
cout<<" 5. Enter Patient's Room No. :";
cin>>arr[docid1].room;
cout<<" 6. Enter Patient's Room Charge :";
cin>>arr[docid1].charg;
cout<<" 7. Enter Patient's Medicine charge :";
cin>>arr[docid1].bill;
docid1++;
counter++;
cout<<" ";
cout<<"You filled all Entries of "<<i<<" patient successfully"<<" ";
cout<<"enter value for "<<" "<<i+1<<" "<<"patient"<<" ";
}
}
void patient :: Display()
{
system("cls");
int n,i;
cout<<" Enter the Patient's ID to display info :";
cin>>n;
if(n==0)
{
cout<<" OOPS!!!! "<<" ";
cout<<"Note:- No Record To Display Please Go Back And Enter Some Entries...... "<<" ";
cout<<" Press Any KEY To choose another Option.... ";
}
else
{
int status=0;
for(i=0;i<docid1;i++)
{
if(arr[i].id1==n)
{
status=1;
break;
}
}
if(status==1)
{
cout<<"1.Patient's ID :"<<arr[i].id1<<" ";
cout<<"2.Patient's Name :"<<arr[i].name<<" ";
cout<<"3.Patient's Age :"<<arr[i].age<<" ";
cout<<"4.Patient's Disease :"<<arr[i].dis<<" ";
cout<<"5.Patient's Room No. :"<<arr[i].room<<" ";
cout<<"6.Patient's Room Charge :"<<arr[i].charg<<" ";
cout<<"7.Patient's Medicine charge :"<<arr[i].bill<<" ";
cout<<" Press Any KEY To choose another Option.... ";
}
else{
cout<<" No such ID in database "<<endl;
cout<<" Press Any KEY To choose another Option.... ";
}
}
getch();
}
void patient :: patient_report()
{
system("cls");
int i,n;
cout<<" Enter the Patient's ID to Display Report :";
cin>>n;
int status=0;
for(i=0;i<docid1;i++)
{
if(arr[i].id1==n)
{
status=1;
break;
}
}
if(status)
{
cout<<" *** Patient's Report *** "<<" ";
cout<< "1. Patient's Name "<<arr[i].name<<" ";
cout<< "2. Patient's Age "<<arr[i].age<<" ";
cout<< "3. Patient Disease "<<arr[i].dis<<" ";
cout<<"Press Any Key To Go Back....";
}
else{
cout<<" No such ID in database "<<endl;
cout<<" Press Any KEY To choose another Option.... ";
}
getch();
}
void patient:: patient_detail()
{
int i;
if(docid1==0)
{
cout<<" OOPS!!!! "<<" ";
cout<<"Note:- No Record To Display Please Go Back And Enter Some Entries...... "<<" ";
}
else{
cout<<"********************************************************************************"<<" ";
cout<<" Details Of All The Patient In The Hospital ";
cout<<"********************************************************************************"<<" ";
cout<<"ID"<<" "<<"illness"<<" "<<" "<<"Age";
cout<<" ";
for(i=0;i<docid1;i++)
{
cout<<arr[i].id1<<" "<<arr[i].dis<<" "<<" "<<arr[i].age<<" ";
}
cout<<" Press Any KEY To choose another Option.... ";
}
getch();
}
void patient :: tot_no_of_pat()
{
system("cls");
int i=counter;
cout<<"Total Patients in Hospital : "<<i<<" ";
cout<<" Press Any KEY To choose another Option.... ";
getch();
}
void patient :: gen_pat_report()
{
system("cls");
int i,n;
cout<<" Enter the Patient's ID to Display Bill :";
cin>>n;
int status=0;
for(i=0;i<docid1;i++)
{
if(arr[i].id1==n)
{
status=1;
break;
}
}
if(status)
{
cout<<" *** Patient's Report *** "<<" ";
cout<< "1. Patient's Medicine Charge "<<arr[i].bill<<" ";
cout<< "2. Patient's Room Charge "<<arr[i].charg<<" ";
cout<<"Press Any Key To Go Back....";
}
else{
cout<<" No such ID in database "<<endl;
cout<<" Press Any KEY To choose another Option.... ";
}
getch();
}
int main()
{
system("color F4");
bool repeat= true;
int ch1,ch2,ch3,ch4;
doctor d;
patient p;
menu:
system("cls");
cout<<" ";
cout<<" *** Welcome to the Hospital Management System *** "<<" ";
cout<<" 1. Menu : "<<" ";;
cout<<" 2. Exit : "<<" ";
cout<<"Enter Your Choice :";
cin>>ch1;
cout<<" ";
while (ch1<1||ch1>2){
system("cls");
cout<<"Error, choose available options"<<endl;
cout<<" 1. Menu : "<<" ";;
cout<<" 2. Exit : "<<" ";
cout<<"Enter Your Choice :";
cin>>ch1;
}
if(ch1==1)
{
menu2:
system("cls");
cout<<" ";
cout<<" 1. Enter into Doctor's DataBase "<<endl;
cout<<" 2. Enter into Patient's DataBase "<<endl;
cout<<" 3. Generate Patient's Report "<<endl;
cout<<" 4. Generate Patient's Bill "<<endl;
cout<<" 5. EXIT "<<" ";
cout<<"Please Enter Your choice :"<<" ";
cin>>ch2;
while(repeat==true)
{
system("cls");
switch(ch2)
case 1:
{
cout<<" ";
cout<<" *** Welcome To Doctor's DataBase *** "<<" ";
cout<< " 1. Add New Doctor's Information "<<endl;
cout<< " 2. Display Doctor's Information "<<endl;
cout<< " 3. Detail OF ALL The Doctors In The Hospital "<<endl;
cout<< " 4. Total Number of Doctor's in Hospital "<<endl;
cout<< " 5. EXIT "<<" ";
cout<<"Please Enter your choice :"<<" ";
cin>>ch3;
switch(ch3)
{
case 1:
system("cls");
d.add_doc_info();// las d viene de la clase de doctor que esta declarado en el main
break;
case 2:
d.Display();
cout<<" ";
break;
case 3:
system("cls");
d.doctor_detail();
break;
case 4:
d.tot_no_of_doc();
break;
case 5:
goto menu2;
break;
default:
cout<<"invalid";
}
break;
case 2:
cout<<" ";
cout<<" *** Welcome To Patient's DataBase *** "<<" ";
cout<< "1. Add New Patient's Information "<<endl;
cout<< "2. Display Patient's Information "<<endl;
cout<< "3. Detail OF ALL The Patient In The Hospital "<<endl;
cout<< "4. Total Number of Patient's in Hospital "<<endl;
cout<< "5. EXIT "<<" ";
cout<<"Please Enter your choice :"<<" ";
cin>>ch4;
switch(ch4)
{
case 1:
system("cls");
p.add_pat_info();
break;
case 2:
p.Display();
cout<<" ";
break;
case 3:
system("cls");
p.patient_detail();
break;
case 4:
p.tot_no_of_pat();
break;
case 5:
goto menu2;
break;
default:
cout<<"invalid";
break;
}
break;
case 3:
p.patient_report();
goto menu2;
break;
case 4:
p.gen_pat_report();
goto menu2;
break;
case 5:
goto menu;
break;
}
}
}
else if(ch1==2)
{
return 0;
}
else
{
cout<<"Wrong Input"<<endl;
}
return 0;
}
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
// define maximum number of patients in a queue
#define MAXPATIENTS 100
// define structure for patient data
struct patient
{
char FirstName[50];
char LastName[50];
char ID[20];
};
// define class for queue
class queue
{
public:
queue (void);
int AddPatientAtEnd (patient p);
int AddPatientAtBeginning (patient p);
patient GetNextPatient (void);
int RemoveDeadPatient (patient * p);
void OutputList (void);
char DepartmentName[50];
private:
int NumberOfPatients;
patient List[MAXPATIENTS];
};
// declare member functions for queue
queue::queue ()
{
// constructor
NumberOfPatients = 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::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<NumberOfPatients; i++)
{
List[i] = List[i+1];
}
// return patient
return p;
}
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; i<NumberOfPatients; i++)
{
if (stricmp(List[i].ID, p->ID) == 0)
{
// patient found in queue
*p = List[i]; found = 1;
// move all following patients one position forward in queue
NumberOfPatients--;
for (j=i; j<NumberOfPatients; j++)
{
List[j] = List[j+1];
}
}
}
return found;
}
void queue::OutputList (void)
{
// lists entire queue on screen
int i;
if (NumberOfPatients == 0)
{
cout << "Queue is empty"<<endl;
}
else
{
for (i=0; i<NumberOfPatients; i++)
{
cout << " " << List[i].FirstName<<endl;
cout << " " << List[i].LastName<<endl;
cout << " " << List[i].ID<<endl;
}
}
}
// declare functions used by main:
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 << " Social security number: ";
cin.getline(p.ID, sizeof(p.ID));
// 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."<<endl;
getch();
}
return p;
}
void OutputPatient (patient * p)
{
// this function outputs patient data to the screen
if (p == NULL || p->ID[0]==0)
{
cout << " No patient"<<endl;
return;
}
else
cout << " Patient data:";
cout << " First name: " << p->FirstName<<endl;
cout << " Last name: " << p->LastName<<endl;
cout << " Social security number: " << p->ID<<endl;
}
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 department
int choice = 0, success; patient p;
while (choice != 6)
{
// clear screen
clrscr();
// print menu
cout << " Welcome to department: " << q->DepartmentName<<endl;
cout << " Please enter your choice:"<<endl;
cout << " 1: Add normal patient"<<endl;
cout << " 2: Add critically ill patient"<<endl;
cout << " 3: Take out patient for operation"<<endl;
cout << " 4: Remove dead patient from queue"<<endl;
cout << " 5: List queue"<<endl;
cout << " 6: Change department or exit "<<endl;
// 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);
clrscr();
if (success)
{
cout << " Patient added: "<<endl;
}
else
{
// error
cout << " Error: The queue is full. Cannot add patient:"<<endl;
}
OutputPatient(&p);
cout << " Press any key"<<endl;
getch();
}
break;
case 2: // Add critically ill patient
p = InputPatient();
if (p.ID[0])
{
success = q->AddPatientAtBeginning(p);
clrscr();
if (success)
{
cout << " Patient added: "<<endl;
}
else
{
// error
cout << " Error: The queue is full. Cannot add patient:"<<endl;
}
OutputPatient(&p);
cout << " Press any key"<<endl;
getch();
}
break;
case 3: // Take out patient for operation
p = q->GetNextPatient();
clrscr();
if (p.ID[0])
{
cout << " Patient to operate: "<<endl;
OutputPatient(&p);}
else
{
cout << " There is no patient to operate."<<endl;
}
cout << " Press any key"<<endl;
getch();
break;
case 4: // Remove dead patient from queue
p = InputPatient();
if (p.ID[0])
{
success = q->RemoveDeadPatient(&p);
clrscr();
if (success)
{
cout << " Patient removed: "<<endl;
}
else
{
// error
cout << " Error: Cannot find patient: "<<endl;
}
OutputPatient(&p);
cout << " Press any key"<<endl;
getch();
}
break;
case 5: // List queue
clrscr();
q->OutputList();
cout << " Press any key"<<endl;
getch(); break;
}
}
}
// main function defining queues and main menu
void main ()
{
int i, MenuChoice = 0;
// define three queues
queue departments[3];
// set department names
strcpy (departments[0].DepartmentName, "Heart clinic");
strcpy (departments[1].DepartmentName, "Lung clinic");
strcpy (departments[2].DepartmentName, "Plastic surgery");
while (MenuChoice != 4)
{
// clear screen
clrscr();
// print menu
cout << " Welcome to Software City Hospital"<<endl;
cout << " Please enter your choice: "<<endl;
for (i = 0; i < 3; i++)
{
// write menu item for department i
cout << " " << (i+1) << ": " << departments[i].DepartmentName<<endl;
}
cout << "4: Exit "<<endl;
// get user choice
MenuChoice = ReadNumber();
// is it a department name?
if (MenuChoice >= 1 && MenuChoice <= 3)
{
// call submenu for department
// (using pointer arithmetics here:)
DepartmentMenu (departments + (MenuChoice-1));
}
}
}
Note:- Here i was given an importent hspatal management with different type please cheek It
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.