Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C++ ProgrammingAssignment APPLICATION to automate adding and deleting e

ID: 3545761 • Letter: C

Question

Create a C++ ProgrammingAssignment APPLICATION to automate adding and deleting employees in a hospital.


The set of classes define these employees of a hospital: hospital employee, doctor, nurse, administrator, surgeon, receptionist, and janitor. Please use the inheritance in creating these classes. You can use arrays to store objects of the same class, you can assume MAX_SIZE = 10.


These employees are initially read and added from the Programming Assignment Data.txt and are also saved in same file when your ProgrammingAssignment APPLICATION terminates.


Your ProgrammingAssignment APPLICATION must prompt the user to read in the data file.


Your ProgrammingAssignment APPLICATION must allow the user to delete a hospital employee, doctor, nurse, administrator, surgeon, receptionist, and janitor given the role and the name from the data file.



Your ProgrammingAssignment APPLICATION must allow the user to print the hospital employees in the format given below.



Your ProgrammingAssignment APPLICATION must allow the user to save the hospital employees before it exists.


A sample input file Programming Assignment Data.txt follows:


h Vito 123

d Michael 234 Heart

s Vincent 345 Brain Y

n Sonny 456 6

a Luca 567 Business

r Tom 678 Talking Y

j Anthony 789 Maintenance N

d Nicos 891 Bone

n Vicky 911 7


The h stands for hospital employee role, Vito for name (only one string), and 123 is its hospital employee number.


The d stands for doctor, Michael for name, 234 for number, and Heart for specialty.


The s stands for surgeon, Vincent for name, 345 for number, Brain for specialty, and Y for operating.


The n stands for nurse, Sonny for name, 456 for number, and 6 for numpatients.


The a stands for administrator, Luca for name, 567 for number, and Business for department.


The r stands for receptionist, Tom for name, 678 for number, Talking for department, and Y for answering.


The j stands for janitor, Anthony for name, 789 for number, Maintenance for department, and Y for sweeping.





The output of the ProgrammingAssignment APPLICATION is of the following form:


The Hospital has the following employees:


Hospital Employees: 1

Name: Vito Employee Number: 123


Doctors: 2

Name: Michael Employee Number: 234 Specialty: Heart

Name: Nicos Employee Number: 891 Specialty: Bone


Surgeons: 1

Name: Vincent Employee Number: 345 Specialty: Brain Can Operate: Y


Nurses: 2

Name: Sonny Employee Number: 456 Number of Patients: 6

Name: Vicky Employee Number: 911 Number of Patients: 7


Administrators: 1

Name: Luca Employee Number: 567 Department: Business


Receptionists: 1

Name: Tom Employee Number: 678 Department: Talking Answering: Y


Janitors: 1

Name: Anthony Employee Number: 789 Department: Maintenance Sweeping: N


Total number of Employees: 9


Create a ProgrammingAssignmen.cpp that contains the main method.

You cannot use any DATA STRUCTURES STL classes! Use arrays.

One class per .h &.cpp file (you will lose 15 points if not)!

Must use Inheritance (you will lose 20 points if not)!

Explanation / Answer

Answer:

Program code to copy:

//ProgrammingAssignment.cpp

#include "stdafx.h"

#include "Administrator.h"

#include "Doctor.h"

#include "HospitalEmployee.h"

#include "Janitor.h"

#include "Nurse.h"

#include "Receptionist.h"

#include "Surgeon.h"

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

const int MAX = 10;

void printData();

void deleteEmployee(char roll);

void saveData(ofstream &outfile);

HospitalEmployee hospEmp[MAX];

Doctor doc[MAX];

Administrator admin[MAX];

Janitor jani[MAX];

Nurse nurse[MAX];

Receptionist recep[MAX];

Surgeon surg[MAX];

int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0;

int main()

{

     string line;

     int total = 0;

     string name, speciality, depart;

     char ans, sweep, operate, roll;

     int numPatient, empNum, choice;

     ifstream inFile("Data.txt");

     ofstream outFile;

     if(inFile)

     {

          while(!inFile.eof())

          {

              inFile>>roll;

              switch(roll)

              {

              case 'h':

                   inFile>>name;

                   inFile>>empNum;                  

                   hospEmp[c1].setName(name);

                   hospEmp[c1].setNumber(empNum);

                   c1++;

                   break;

              case 'd':

                   inFile>>name;

                   inFile>>empNum;

                   inFile>>speciality;

                   doc[c2].setName(name);

                   doc[c2].setNumber(empNum);

                   doc[c2].setSpecialist(speciality);

                   c2++;

                   break;

              case 's':

                   inFile>>name;

                   inFile>>empNum;        

                   inFile>>speciality;

                   inFile>>operate;

                   surg[c3].setName(name);

                   surg[c3].setNumber(empNum);

                   surg[c3].setSpecialist(speciality);

                   surg[c3].setOperateStatus(operate);

                   c3++;

                   break;

              case 'n':

                   inFile>>name;

                   inFile>>empNum;   

                   inFile>>numPatient;

                   nurse[c4].setName(name);

                   nurse[c4].setNumber(empNum);

                   nurse[c4].setNumberofPatients(numPatient);

                   c4++;

                   break;

              case 'a':

                   inFile>>name;

                   inFile>>empNum;

                   inFile>>depart;

                   admin[c5].setName(name);

                   admin[c5].setNumber(empNum);

                   admin[c5].setDepartment(depart);

                   c5++;

                   break;

              case 'r':

                   inFile>>name;

                   inFile>>empNum;

                   inFile>>depart;

                   inFile>>ans;

                   recep[c6].setName(name);

                   recep[c6].setNumber(empNum);

                   recep[c6].setDepartment(depart);

                   recep[c6].setAnswering(ans);

                   c6++;

                   break;

              case 'j':

                   inFile>>name;

                   inFile>>empNum;

                   inFile>>depart;

                   inFile>>sweep;

                   jani[c7].setName(name);

                   jani[c7].setNumber(empNum);

                   jani[c7].setDepartment(depart);

                   jani[c7].setSweeping(sweep);

                   c7++;

                   break;

              }

          }

     }

     else

     {

          cout<<"Sorry! Unable to find or open the file: Data.txt"<<endl;

     }

     inFile.close();

     outFile.open("Data.txt");

     do

     {

          cout<<endl;

          cout<<"Menu for hospital data:"<<endl<<endl;

          cout<<"1: To print the list of employees"<<endl;

          cout<<"2: To delete particular employee"<<endl;

          cout<<"3: To exit application"<<endl;

          cout<<"Enter your choice: ";

          cin>>choice;

          cout<<endl;

          switch(choice)

          {

          case 1:

              printData();

              break;

          case 2:

              cout<<"h - Hospital Employee"<<endl;

              cout<<"d - Doctor"<<endl;

              cout<<"s - Surgeon"<<endl;

              cout<<"n - Nurse"<<endl;

              cout<<"a - Admin"<<endl;

              cout<<"r - Receptionist"<<endl;

              cout<<"j - Janitor"<<endl;

              cout<<"Enter the roll: ";

              cin>>roll;

              deleteEmployee(roll);

              break;

          case 3:           

              saveData(outFile);

              outFile.close();

              system("pause");

              return 0;

              break;

          default:

              cout<<"Enter the choice properly. "<<endl;          

          }

     }while(true);

     system("pause");

     return 0;

}

void printData()

{

     cout<<"The Hospital has the following employees "<<endl<<endl;

     cout<<"Hospital Employees: "<<c1<<endl;

     for(int i =0;i<c1;i++)

     {

          hospEmp[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Doctors: "<<c2<<endl;

     for(int i =0;i<c2;i++)

     {

          doc[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Surgeons: "<<c3<<endl;

     for(int i =0;i<c3;i++)

     {

          surg[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Nurses: "<<c4<<endl;

     for(int i =0;i<c4;i++)

     {

          nurse[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Administrators: "<<c5<<endl;

     for(int i =0;i<c5;i++)

     {

          admin[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Receptionist: "<<c6<<endl;

     for(int i =0;i<c6;i++)

     {

          recep[i].print();

          cout<<endl;

     }

     cout<<endl;

     cout<<"Janitors: "<<c7<<endl;

     for(int i =0;i<c7;i++)

     {

          jani[i].print();

          cout<<endl;

     }

     cout<<endl;

}

void deleteEmployee(char roll)

{

     string name;

     int index = 0;

     cout<<"Enter the name: ";

     cin>>name;

     switch(roll)

     {

     case 'h':

          for(int i = 0;i<c1;i++)

          {

              if((hospEmp[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c1-1; i++)

          {

              hospEmp[i]=hospEmp[i+1];                  

          }

          cout<<endl;

          c1--;

          break;

     case 'd':

          for(int i = 0;i<c2;i++)

          {

              if((doc[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c2-1; i++)

          {

              doc[i]=doc[i+1];                 

          }

          cout<<endl;       

          c2--;

          break;

     case 's':

          for(int i = 0;i<c3;i++)

          {

              if((surg[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }        

          for(int i = index; i<c3-1; i++)

          {

              surg[i]=surg[i+1];               

          }

          cout<<endl;       

          c3--;

          break;

     case 'n':

          for(int i = 0;i<c4;i++)

          {

              if((nurse[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c4-1; i++)

          {

              nurse[i]=nurse[i+1];                 

          }

          cout<<endl;       

          c4--;

          break;

     case 'a':

          for(int i = 0;i<c5;i++)

          {

              if((admin[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c5-1; i++)

          {

              admin[i]=admin[i+1];                 

          }

          cout<<endl;       

          c5--;

          break;

     case 'r':

          for(int i = 0;i<c6;i++)

          {

              if((recep[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c6-1; i++)

          {

              recep[i]=recep[i+1];                 

          }

          cout<<endl;       

          c6--;

          break;

     case 'j':

          for(int i = 0;i<c7;i++)

          {

              if((jani[i].getName().compare(name))==0)

              {

                   index = i;

                   break;

              }                 

          }

          for(int i = index; i<c7-1; i++)

          {

              jani[i]=jani[i+1];               

          }

          cout<<endl;       

          c7--;

          break;

     }

}

void saveData(ofstream &outfile)

{

     for(int i =0;i<c1;i++)

     {

          outfile<<'h'<<" ";

          outfile<<hospEmp[i].getName()<<" ";

          outfile<<hospEmp[i].getNumber();

     }   

     outfile<<" ";

    

     for(int i =0;i<c2;i++)

     {        

          outfile<<'d'<<" ";

          outfile<<doc[i].getName()<<" ";

          outfile<<doc[i].getNumber()<<" ";

          outfile<<doc[i].getSpecialist();

     }

     outfile<<" ";

    

     for(int i =0;i<c3;i++)

     {        

          outfile<<'s'<<" ";

          outfile<<surg[i].getName()<<" ";

          outfile<<surg[i].getNumber()<<" ";

          outfile<<surg[i].getOperateStatus();

     }

     outfile<<" ";

         

     for(int i =0;i<c4;i++)

     {        

          outfile<<'n'<<" ";

          outfile<<nurse[i].getName()<<" ";

          outfile<<nurse[i].getNumber()<<" ";

          outfile<<nurse[i].getNumberofPatients();

     }

     outfile<<" ";

     for(int i =0;i<c5;i++)

     {

          outfile<<'a'<<" ";

          outfile<<admin[i].getName()<<" ";

          outfile<<admin[i].getNumber()<<" ";

          outfile<<admin[i].getDepartment();

     }

     outfile<<" ";

         

     for(int i =0;i<c6;i++)

     {

          outfile<<'r'<<" ";

          outfile<<recep[i].getName()<<" ";

          outfile<<recep[i].getNumber()<<" ";

          outfile<<recep[i].getDepartment()<<" ";

          outfile<<recep[i].getAnswering();

     }

     outfile<<" ";

         

     for(int i =0;i<c7;i++)

     {

          outfile<<'j'<<" ";

          outfile<<jani[i].getName()<<" ";

          outfile<<jani[i].getNumber()<<" ";

          outfile<<jani[i].getDepartment()<<" ";

          outfile<<jani[i].getSweeping();

     }

     outfile<<" ";

}

//HospitalEmployee.hpp

#ifndef HospitalEmployee_H

#define HospitalEmployee_H

#include "stdafx.h"

#include <iostream>

#include <string>

using namespace std;

class HospitalEmployee

{

private:

     string name;

     int number;

public:

     HospitalEmployee();

     HospitalEmployee(string name, int number);

     void setName(string name);

     void setNumber(int number);

     string getName();

     int getNumber();

     virtual void print();

};

#endif

//HospitalEmployee.cpp

#include "stdafx.h"

#include "HospitalEmployee.h"

#include <iostream>

#include <string>

using namespace std;

HospitalEmployee::HospitalEmployee()

{

     name = "";

     number = 0;

}

HospitalEmployee::HospitalEmployee(string name, int number)

{

     this->name = name;

     this->number = number;

}

void HospitalEmployee::setName(string name)

{

     this->name = name;

}

void HospitalEmployee::setNumber(int number)

{

     this->number = number;

}

string HospitalEmployee::getName()

{

     return this->name;

}

int HospitalEmployee::getNumber()

{

     return this->number;

}

void HospitalEmployee::print()

{

     cout<<"Name: "<<this->name;

     cout<<" Employee Number: "<<this->number;

}

//Doctor.hpp

#include "HospitalEmployee.h"

#ifndef Doctor_H

#define Doctor_H

class Doctor: public HospitalEmployee

{

private:

     string speicalist;

public:

     Doctor();

     Doctor(string name, int number, string specialist);

     void setSpecialist(string specialist);

     string getSpecialist();

     void print();

};

#endif

//Doctor.cpp

#include "stdafx.h"

#include "HospitalEmployee.h"

#include "Doctor.h"

Doctor::Doctor():HospitalEmployee()

{

     this->speicalist = "";

}

Doctor::Doctor(string name, int number, string specialist):HospitalEmployee(name, number)

{

     this->speicalist = specialist;

}

void Doctor::setSpecialist(string specialist)

{

     this->speicalist = specialist;

}

string Doctor::getSpecialist()

{

     return this->speicalist;

}

void Doctor::print()

{

     HospitalEmployee::print();

     cout<<" Specialty: "<<this->speicalist;

}

//Surgeon.hpp

#ifndef Surgeon_H

#define Surgeon_H

#include "HospitalEmployee.h"

#include "Doctor.h"

class Surgeon: public Doctor

{

private:

     char operate;

public:

     Surgeon();

     Surgeon(string name, int number, string specialist, char operate);

     void setOperateStatus(char operate);

     char getOperateStatus();

     void print();

};

#endif

//Surgeon.cpp

#include "stdafx.h"

#include "Surgeon.h"

Surgeon::Surgeon():Doctor()

{

     this->operate = ' ';

}

Surgeon::Surgeon(string name, int number, string specialist, char operate):Doctor(name, number, specialist)

{

     this->operate = operate;

}

void Surgeon::setOperateStatus(char operate)

{

     this->operate = operate;

}

char Surgeon::getOperateStatus()

{

     return this->operate;

}

void Surgeon::print()

{

     Doctor::print();

     cout<<" Operate: "<<this->operate;

}

//Nurse.hpp

#include "HospitalEmployee.h"

#ifndef Nurse_H

#define Nurse_H

class Nurse: public HospitalEmployee

{

private:

     int num_of_patients;

public:

     Nurse();

     Nurse(string name, int number, int num_of_patients);

     void setNumberofPatients(int num_of_patients);

     int getNumberofPatients();

     void print();

};

#endif

//Nurse.cpp

#include "stdafx.h"

#include "HospitalEmployee.h"

#include "Nurse.h"

Nurse::Nurse():HospitalEmployee()

{

     this->num_of_patients = 0;

}

Nurse::Nurse(string name, int number, int num_of_patients):HospitalEmployee(name, number)

{

     this->num_of_patients = num_of_patients;

}

void Nurse::setNumberofPatients(int num_of_patients)

{

     this->num_of_patients = num_of_patients;

}

int Nurse::getNumberofPatients()

{

     return this->num_of_patients;

}

void Nurse::print()

{

     HospitalEmployee::print();

     cout<<" Number of Patients: "<<this->num_of_patients;

}

//Administrator.hpp

#ifndef Administrator_H

#define Administrator_H

#include "HospitalEmployee.h"

class Administrator: public HospitalEmployee

{

private:

     string department;

public:

     Administrator();

     Administrator(string name, int number, string department);

     void setDepartment(string department);

     string getDepartment();

     void print();

};

#endif

//Administrator.cpp

#include "stdafx.h"

#include "Administrator.h"

Administrator::Administrator():HospitalEmployee()

{

     this->department = "";

}

Administrator::Administrator(string name, int number, string department):HospitalEmployee(name, number)

{

     this->department = department;

}

void Administrator::setDepartment(string department)

{

     this->department = department;

}

string Administrator::getDepartment()

{

     return this->department;

}

void Administrator::print()

{

     HospitalEmployee::print();

     cout<<" Department: "<<this->department;

}

//Receptionist.hpp

#ifndef Receptionist_H

#define Receptionist_H

#include "HospitalEmployee.h"

#include "Administrator.h"

class Receptionist:public Administrator

{

private:

     char answering;

public:

     Receptionist();

     Receptionist(string name, int number, string department, char answering);

     void setAnswering( char answering);

     char getAnswering();

     void print();

};

#endif

//Receptionist.cpp

#include "stdafx.h"

#include "Receptionist.h"

Receptionist::Receptionist():Administrator()

{

     this->answering = ' ';

}

Receptionist::Receptionist(string name, int number, string department, char answering):Administrator(name, number, department)

{

     this->answering = answering;

}

void Receptionist::setAnswering(char answering)

{

     this->answering = answering;

}

char Receptionist::getAnswering()

{

     return this->answering;

}

void Receptionist::print()

{

     Administrator::print();

     cout<<" Answering: "<<this->answering;

}

//Janitor.hpp

#ifndef Janitor_H

#define Janitor_H

#include "HospitalEmployee.h"

#include "Administrator.h"

class Janitor: public Administrator

{

private:

     char sweeping;

public:

     Janitor();

     Janitor(string name, int number, string department, char sweeping);

     void setSweeping(char sweeping);

     char getSweeping();

     void print();

};

#endif

//Janitor.cpp

#include "stdafx.h"

#include "Janitor.h"

Janitor::Janitor():Administrator()

{

     this->sweeping = ' ';

}

Janitor::Janitor(string name, int number, string department, char answering):Administrator(name, number, department)

{

     this->sweeping = answering;

}

void Janitor::setSweeping(char answering)

{

     this->sweeping = answering;

}

char Janitor::getSweeping()

{

     return this->sweeping;

}

void Janitor::print()

{

     Administrator::print();

     cout<<" Sweeping: "<<this->sweeping;

}

Sample Output:

Menu for hospital data:

1: To print the list of employees

2: To delete particular employee

3: To exit application

Enter your choice: 1

The Hospital has the following employees

Hospital Employees: 1

Name: Vito Employee Number: 123

Doctors: 2

Name: Michael Employee Number: 234 Specialty: Heart

Name: Nicos Employee Number: 891 Specialty: Bone

Surgeons: 1

Name: Vincent Employee Number: 345 Specialty: Brain Operate: Y

Nurses: 2

Name: Sonny Employee Number: 456 Number of Patients: 6

Name: Vicky Employee Number: 911 Number of Patients: 7

Administrators: 1

Name: Luca Employee Number: 567 Department: Business

Receptionist: 1

Name: Tom Employee Number: 678 Department: Talking Answering: Y

Janitors: 1

Name: Anthony Employee Number: 789 Department: Maintenance Sweeping: N

Menu for hospital data.

1: To print the list of employees

2: To delete particular employee

3: To exit application

Enter your choice: 2

h - Hospital Employee

d - Doctor

s - Surgeon

n - Nurse

a - Admin

r - Receptionist

j - Janitor

Enter the roll: d

Enter the name: Michael

Menu for hospital data.

1: To print the list of employees

2: To delete particular employee

3: To exit application

Enter your choice: 1

The Hospital has the following employees

Hospital Employees: 1

Name: Vito Employee Number: 123

Doctors: 1

Name: Nicos Employee Number: 891 Specialty: Bone

Surgeons: 1

Name: Vincent Employee Number: 345 Specialty: Brain Operate: Y

Nurses: 2

Name: Sonny Employee Number: 456 Number of Patients: 6

Name: Vicky Employee Number: 911 Number of Patients: 7

Administrators: 1

Name: Luca Employee Number: 567 Department: Business

Receptionist: 1

Name: Tom Employee Number: 678 Department: Talking Answering: Y

Janitors: 1

Name: Anthony Employee Number: 789 Department: Maintenance Sweeping: N

Menu for hospital data:

1: To print the list of employees

2: To delete particular employee

3: To exit application

Enter your choice: 3

Sample Text file after saving:

h Vito 123
d Nicos 891 Bone
s Vincent 345 Y
n Sonny 456 6n Vicky 911 7
a Luca 567 Business
r Tom 678 Talking Y
j Anthony 789 Maintenance N