/ Published in: C++
Expand |
Embed | Plain Text
/*############################################################################# # CISP 400 ch15.cpp # # # # Class : wed 14:00- # # Assignemnt : Employee and ProductionWorker class # ############################################################################ # Date Edit # ##########################################################################*/ #include <iostream> #include <cstdlib> #include <iomanip> #include <string> #include <cstdio> #include <cstring> #include <vector> using namespace std; class Employee /*: public ProductionWorker*/ { protected: string temp; string temp1; protected: string empName; string empNumber; string hireDate; int nightPer; public: Employee() { nightPer =0; } Employee(string &name,string &number,string &date) /* : ProductionWorker() */ { empName = name; empNumber = number; hireDate = date; } string getDate() const { return hireDate; } string getEmpNum() const { return empNumber; } string getEmpName() const { return empName; } }; class ProductionWorker : public Employee { private: float pay; double workTime; double add; public: int shift; // day for 1 night for 2 double hourlyPayRate; ProductionWorker() : Employee() { add = 0; workTime = 0; pay = 0; shift = 0; hourlyPayRate = 0; } ProductionWorker(int shift,float hourlyPayRate,double workTime,double add) : Employee() { float Pay; Pay = calPay(shift,hourlyPayRate,workTime,add); setValue(Pay,shift,hourlyPayRate,workTime,add); } double calPay(int, double, double,double);//mutator function void setValue(double Pay, int Shift,double hourPay, double workT,double addRate) { pay = Pay; shift = Shift; hourlyPayRate = hourPay; workTime = workT; add = addRate; } double getPay() const // Accessor function { return pay; } int getShift() const { return shift; } }; double ProductionWorker::calPay(int shift,double hourlyPayRate,double workTime,double add) { float payRate =0; if (shift == 1) { payRate = hourlyPayRate * workTime; cout << payRate << endl; return payRate; } else { payRate = (hourlyPayRate*(1+add/100)*workTime); cout << payRate << endl; return payRate; } } void setDate(string &date,int month,int day,int year); int main(){ string name; string number; int month; int day; int year; int sh; double hourPay; double workTime; int add; cout << "Enter a Employee Name : "; getline(cin,name); cout << "Enter a Employee Number : "; getline(cin,number); cout << "Enter a Hire Date (month) : "; cin >> month; while((month < 1) ||(month > 12)) { cout << "Month is Invalid "<< endl; cout << "Could you please enter correct month within 1 to 12"<< endl; cin >> month; } cout << "Enter a Hire Date (day) : "; cin >> day; while((day < 1) ||(day > 31)) { cout << "Month is Invalid "<< endl; cout << "Could you please enter correct day within 1 to 12"<< endl; cin >> day; } cout << "Enter a Hire Date (year) : "; cin >> year; while((year < 1800) ||(year > 2500)) { cout << "Month is Invalid "<< endl; cout << "Could you please enter correct year within 1800 to 2500"<< endl; cin >> year; } // setDate(date,month,day,year); Employee emp(name,number,date); cout << "Enter a shift (day 1 night 2) : "; cin >> sh; while((sh<0) || (sh>2) ) { cout << "Invalid number "<<endl; cout << "Please enter 1 or 2 (1 is Day time, 2 is night time )" <<endl; cin >> sh; } cout << "Enter a work time : "; cin >> workTime; while((workTime<0) || (workTime > 744)) { cout << "work time is invalid"<<endl; cout << "work time is within 774 hours per month" << endl; cout << "work note: 774 hours working is the same amount that one worker works 24 hours/31days"<<endl; cin >> workTime; } cout << "Enter a Basic Hourly Pay Rate: "; cin >> hourPay; while(hourPay < 0) { cout << "Hour Pay is invalid "<< endl; cout << "Hour Pay is more than 0 "<< endl; cin >> hourPay; } cout << "Enter a Night time additional pay rate (%) : "; cin >> add; while(add < 0) { cout << "Additional rate is negative number "<<endl; cout << "please enter more than 0 for additional pay rate at night time workers"<<endl; cin >> add; } ProductionWorker pw(sh,hourPay, workTime,add); system("clear"); /*############################################################################## # need edit here take data from each class and each class need to convert # # data for print out # ############################################################################*/ cout << "******* Result **********" << endl; cout << "Name : "<< emp.getEmpName() << endl; cout << "ID Number : " << emp.getEmpNum() << endl; cout << "Hire Date : " << emp.getDate() << endl; cout << "Shift : " << pw.getShift() << endl; cout << "Payment : " << pw.getPay() << endl; return 0; }
You need to login to post a comment.
