int main(int argc, char** argv) { ProductionWorker test; test.setName("Bill"); test.setNumber(1234); test.setDate("12/1/2015"); test.setShift(2); test.setRate(12.56); cout << test.getDate(); return 0; }
int main() { ProductionWorker pwork; pwork.setName("Ryan"); pwork.setNumber(23456); pwork.setDate("12/1/2015"); pwork.setShift(2); pwork.setRate(12.56); cout << pwork.getName() << " " << pwork.getNumber() << " " << pwork.getDate() << endl; ShiftSupervisor super; super.setSalary(100000); super.setBonus(2500); cout << super.getSalary() + super.getBonus() << endl; return 0; }
int main(int args, const char* argv[]) { string name = "Homer Simpson"; size_t number = 342345; time_t hire_date = time(NULL); uint8_t shift = 2; double hourly_pay_rate = 7.50f; ProductionWorker pw = ProductionWorker(name, number, hire_date, shift, hourly_pay_rate); assert(pw.get_name() == name); assert(pw.get_number() == number); assert(pw.get_hire_date() == hire_date); assert(pw.get_shift() == shift); assert(pw.get_hourly_pay_rate() == hourly_pay_rate); return 0; }
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; }