int main(int argc, char** argv) { //declare variables string name; //employee name int empNum; //employee number string hireDate; //hire date of the employee int shift; //the shift of the employee (shift 1 or shift 2) float rate; //employee rate of pay bool v=true;//validation for shift ProductionWorker emp; //input information cout<<"What is the name of the employee? "<<endl; getline(cin,name); emp.setName(name); cout<<"What is the employee's id number? "<<endl; cin>>empNum; emp.setNum(empNum); cout<<"What was the hire date of the employee? (mm/dd/yy) "<<endl; cin>>hireDate; emp.setHireD(hireDate); cout<<"What is the employee's shift? Enter 1 for shift 1, 2 for shift 2"<<endl; cin>>shift; while(v){ try{ //call set function emp.setShift(shift); v=false; }catch(ProductionWorker::EmpClass){ cout<<"Invalid Entry. Shift must be 1 or 2"<<endl; cin>>shift; } } cout<<"What is the employee's rate of pay? "<<endl; cin>>rate; emp.setRate(rate); cout<<"***********************************"<<endl; cout<<"Production Worker Information "<<endl; cout<<"Name: "<<emp.getName()<<endl; cout<<"Employee Id: "<<emp.getNum()<<endl; cout<<"Hire Date: "<<emp.getHirdD()<<endl; cout<<"Shift: "<<emp.getShift()<<endl; cout<<"Hourly Pay Rate: $"<<emp.getRate()<<endl; cout<<"***********************************"<<endl; return 0; }
void problem1(){ cout<<"In Gaddis_8thEd_Chap15_Prob1"<<endl<<endl; cout<<"Employee and ProductionWorker Classes"<<endl; cout<<"This problem demonstrates implementation of an exception"<<endl; cout<<"As well as derived classes (inheritance)"<<endl; //declare variables string name; //employee name string empNum; //employee number string hireDate; //hire date of the employee int shift; //the shift of the employee (shift 1 or shift 2) float rate; //employee rate of pay bool v=true;//validation for shift ProductionWorker emp; //employee information held here //input information cout<<"\nInput the following employee information"<<endl; //this part not working cout<<"What is the name of the employee? "<<endl; cin.ignore(); getline(cin,name); emp.setName(name); cin.ignore(); do{ cout<<"What is the employee's id number? Enter a four digit number"<<endl; cin>>empNum; if(empNum.length()!=4){ cout<<"Invalid entry enter again."<<endl; } }while(empNum.length()!=4); emp.setNum(empNum); do{ cout<<"What was the hire date of the employee? (mm/dd/yy) "<<endl; cin>>hireDate; if(hireDate.length()!=8){ cout<<"Invalid entry enter again."<<endl; } }while(hireDate.length()!=8); emp.setHireD(hireDate); cout<<"What is the employee's shift? Enter 1 for shift 1, 2 for shift 2"<<endl; cin>>shift; while(v){ try{ //call set function emp.setShift(shift); v=false; }catch(ProductionWorker::EmpClass){ cout<<"Invalid Entry. Shift must be 1 or 2"<<endl; cin>>shift; } } cout<<"What is the employee's rate of pay? "<<endl; cin>>rate; emp.setRate(rate); cout<<"***********************************"<<endl; cout<<"Production Worker Information "<<endl; cout<<"Name: "<<emp.getName()<<endl; cout<<"Employee Id: "<<emp.getNum()<<endl; cout<<"Hire Date: "<<emp.getHirdD()<<endl; cout<<"Shift: "<<emp.getShift()<<endl; cout<<"Hourly Pay Rate: $"<<emp.getRate()<<endl; cout<<"***********************************"<<endl; }