Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <array>
- using namespace std;
- void dataEntryMess();
- void messLine();
- string employType(int c);
- string hoursworked();
- enum class paycode
- { TEAM=1, SALES=2, PEICE=3, HOURLY=4, QUIT=-1};
- class employee {
- private:
- protected:
- int type;
- double hrsworked;
- double payrate;
- double overtime;
- double sales;
- int items;
- public:
- employee(double t,double hw,
- double pr,double ot,double s,int i){
- hrsworked=hw;
- payrate=pr;
- overtime=ot;
- sales=s;
- items=i;
- } // end constructor
- employee(){
- type=0;
- hrsworked=0.0;
- payrate=0.0;
- overtime=0.0;
- sales=0.0;
- items=0;
- } // end constructor
- void setType(int t){type=t;}
- void setHoursWorked(double hw){hrsworked=hw;}
- void setPayRate(double pr){payrate=pr;}
- void setOvertime(double ot){overtime=ot;}
- void setSales(double s){sales=s;}
- int getType(){return type;}
- double getHoursWorked(){return hrsworked;}
- double getPayRate(){return payrate;}
- double getOverTime(){return overtime;}
- double getSales(){return sales;}
- }; // end class
- class TeamLeader : public employee
- {
- public:
- TeamLeader(double pr){
- payrate=pr;
- }
- double getPayRate(){return payrate;}
- };
- class Sales : public employee
- {
- private:
- const double sales_worker = 500.00;
- const double gross_sales = 6.5;
- public:
- Sales(double s){
- sales=s;
- }
- double getPayRate(){
- return (sales_worker+(sales*gross_sales));
- }
- };
- class Peice : public employee
- {
- protected:
- const double peice_work = 0.96;
- public:
- Peice(int p){
- items=p;
- }
- double getPayRate(){
- return (peice_work*items);
- }
- };
- class Hourly : public employee
- {
- const double over_time = 1.5;
- const int full_time = 40;
- public:
- Hourly(double w,double h){
- payrate=w;
- hrsworked=h;
- }
- double getHoursWorked(){return hrsworked;}
- double getPayRate(){
- double ot=(hrsworked-full_time);
- return (ot>0)?
- ((ot*(over_time*payrate))+
- (full_time*payrate)):
- (hrsworked*payrate);
- }
- };
- int main(){
- char run='y';
- int t=0,s=0,p=0,h=0;
- int c;
- double pr,hrs;
- vector <TeamLeader> tl;
- vector <Sales> sl;
- vector <Peice> pe;
- vector <Hourly> hry;
- do
- {
- dataEntryMess();
- cin>>c;
- switch(static_cast<paycode>(c)){
- case paycode::TEAM:
- cout<< employType(c);
- cin>>pr;
- tl.push_back(TeamLeader(pr));
- cout<<"Fortnight pay is: $"
- <<tl.at(t++).getPayRate()<<endl<<endl;
- break;
- case paycode::SALES:
- cout<< employType(c);
- cin>>pr;
- sl.push_back(Sales(pr));
- cout<<"Fortnight pay is: $"
- <<sl.at(s++).getPayRate()<<endl<<endl;
- break;
- case paycode::PEICE:
- cout<< employType(c);
- int i;
- cin>>i;
- pe.push_back(Peice(i));
- cout<<"Fortnight pay is : $"
- <<pe.at(p++).getPayRate()<<endl<<endl;
- break;
- case paycode::HOURLY:
- cout<< employType(c);
- cin>>pr;
- cout<< hoursworked()<<endl;
- double hrw;
- cin>>hrw;
- hry.push_back(Hourly(pr,hrw));
- cout<<"Fortnight pay is : $"
- <<hry.at(h++).getPayRate()<<endl<<endl;
- break;
- case paycode::QUIT:
- run='n';
- break;
- default:
- cerr<<"bad input"<<endl;
- c=0;
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- break;
- }// end switch
- }while(run == 'y');
- double total;
- for(auto it:tl)
- total+=it.getPayRate();
- for(auto it:sl)
- total+=it.getPayRate();
- for(auto it:pe)
- total+=it.getPayRate();
- for(auto it:hry)
- total+=it.getPayRate();
- cout<<endl<<"Total amount paid out : $"<<total<<endl;
- return 0;
- }
- // Functions
- void dataEntryMess(){
- messLine();
- cout<<"Enter code for employee's number code [-1 to end]: \n";
- }
- void messLine(){
- for(int i=0;i<30;i++)
- cout<<"*";
- cout<<"\n";
- }
- string employType(int c){
- array<string, 5> type ={" ",
- "Team leader's",
- "Sales employee's",
- "Peice worker's",
- "Hourly worker's"};
- switch(static_cast<paycode>(c)){
- case paycode::TEAM:
- return "Enter "+ type.at(c) +" pay rate : ";
- case paycode::SALES:
- return "Enter "+type.at(c)+" gross weekly sales: ";
- case paycode::PEICE:
- return "Enter "+type.at(c)+" amount of peices sold: ";
- case paycode::HOURLY:
- return "Enter "+type.at(c)+" pay rate: ";
- case paycode::QUIT:
- // its here to complete the enum elements
- break;
- } //end switch
- return "oops something went wrong!";// for control path
- }
- string hoursworked(){
- return "Enter the numbers of hours worked: ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement