PLease write a better code which is rather advance form using #include<queue> && #include<list>
#include<iostream>
#include<conio.h>
#include <iomanip.h>
using namespace std;
const int size=20;
// Patient Class
class Patient
{
int age;
char name[30],phy;
public:
Patient()
{
age=0;
strcpy(name,"");
phy=NULL;
}
void SetName(char* P_name)
{
strcpy(name,P_name);
}
void SetAge(int P_age)
{
age=P_age;
}
void SetPhyscian(char P1)
{
phy=P1;
}
char* GetName()
{
return name;
}
int GetAge()
{
return age;
}
char GetPhyscian()
{
return phy;
}
};
// Patient Queue Class
class PatientQueue
{
int front;
int rear;
int noElements;
Patient array[size];
int total_patients;
public:
PatientQueue()
{
rear=0;
front=0;
noElements=0;
total_patients=0;
}
void Add_Patient(Patient p)
{
if(!isFull())
{
rear = (rear + 1) % size;
array[rear] = p;
noElements = noElements + 1;
total_patients++;
}
else
cout<<endl<<endl<<"Your physician's maximum patient limit has reached . No more patients can be treated now"<<endl<<endl;
}
void dequeue()
{
if(isEmpty())
cout<<endl<<"Patient Queue is Empty"<<endl<<endl;
else
{
cout <<left<<setw(20)<< "Name" <<setw(20)<< "Age"<<setw(20)<<"Physician Name";
cout<<endl<<"============================================================================="<<endl <<endl;
for (int i=0; i<total_patients; i++)
{
front = (front + 1) % size;
cout <<left <<setw(20)<<array[front].GetName() <<setw(20)<< array[front].GetAge()<<setw(20)<<array[front].GetPhyscian()<<endl;
noElements = noElements - 1;
}
cout<<endl<<endl<<"==========================================================================="<<endl <<endl;
}
}
void Display_Patient_Phy1()
{
dequeue();
}
void Display_Patient_Phy2()
{
dequeue();
}
bool isFull()
{
return noElements == size;
}
bool isEmpty()
{
return noElements == 0;
}
int Total_Patients()
{
return total_patients;
}
};
// Main() Function
int main()
{
int age,choice,total;
char ch,name[25];
PatientQueue Q[2];
while(choice!=5)
{
cout<<"*******************Menu*************************"<<endl<<endl;
cout<<"1: Register a new patient"<<endl<<endl;
cout<<"2: Display List of Patients treated by Physician A"<<endl<<endl;
cout<<"3: Display List of Patients treated by Physician B"<<endl<<endl;
cout<<"4: Display Total number of patients served"<<endl<<endl;
cout<<"5. Exit"<<endl<<endl;
cout<<"*************************************************"<<endl<<endl;
cout<<"Enter your choice"<<endl<<endl;
cin>>choice;
switch(choice)
{
case 1:
while(ch!= 'n' &&ch!= 'N')
{
cout<<endl;
cout<<"Enter Patient Name: ";
cin>>name;
cout<<endl<<endl;
cout<<"Enter Patient Age: ";
cin>>age;
Patient p;
p.SetName(name);
p.SetAge(age);
if(age<50)
{
p.SetPhyscian('A');
Q[0].Add_Patient(p);
}
else
{
p.SetPhyscian('B');
Q[1].Add_Patient(p);
}
cout<<endl<<"Do you want to enter another patient (y/n)? "<<endl<<endl;
cin>>ch;
cout<<endl;
}
break;
case 2:
system("cls");
Q[0].Display_Patient_Phy1();
break;
case 3:
system("cls");
Q[1].Display_Patient_Phy2();
break;
case 4:
total= Q[0].Total_Patients()+ Q[1].Total_Patients();
if(total==0)
cout<<endl<<endl<<"No Patient Served"<<endl<<endl;
else
cout<<endl<<endl<<"Total Patients serveded are: "<<total<<endl<<endl;
break;
case 5:
cout<<endl<<endl<<"Thanks for using this program"<<endl<<endl;
break;
default:
cout<<endl<<endl<<"Use only options 1-5 "<<endl;
}
}
system("pause");
return 0;
}