In: Computer Science
USING C++
A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time- and -a-half “—1.5 times their hourly wage — for overtime hours worked ), commission workers (who receive $250 plus 5.7 percent of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce). Write a program to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have code 1, hourly workers have code 2, commission workers have code 3, and pieceworkers have code 4. The program should prompt the user to enter a pay code and the appropriate facts your program needs to calculate each employee’s pay according to that employee’s pay code. The user enters -1 to end the program.
Sample run:
Payroll Program
1. Managers
2. Hourly workers
3. Commission workers
4. Pieceworkers
Enter pay code (-1 to end): 3
Commission worker selected.
Enter gross weekly sales: 300
Commission worker's pay is $267.10
Enter pay code (-1 to end): 4
Pieceworker selected.
Enter number of pieces: 100
Enter wage per piece: 35.70
Pieceworker's pay is $3570.00
Enter pay code (-1 to end): 1
Manager selected.
Enter weekly salary: 1500
The manager's pay is $1500.00
Enter pay code (-1 to end): 2
Hourly worker selected.
Enter the hourly salary: 25
Enter the total hours worked: 45
Worker's pay is $1187.50
Enter pay code (-1 to end): -1
Have a good day!
Submission Instruction:
• Submit your source file via Canvas by the beginning of the class on March 2, 2018.
• You only need to submit your source code file (.cpp).
Answer:
#include
using namespace std;
int main() /* start of main() function */
{
int choice,pieces; /* variable declaration */
double mgr_sal,hour_sal,hours,pay,week_sales,wage_piece; /* variable declaration */
cout<<" Payroll Program "< cout<<"1.Managers"< cout<<"2.Hourly workers"< cout<<"3.Commission workers"< cout<<"4.Pieceworkers"< cout<<"Enter pay code (-1 to end):"; /*prompts the message
*/ cin>>choice; /* Accepts the integer from the keyboard and
stores in the variable choice */ while(1) /* Infinite loop, will be terminated when user selects
-1 as choice */ { switch(choice) /* takes the value in choice, goes to respective
case */ { case 1:cout<<"Manager seleted."< cout<<"Enter weekly salary:"; /*prompts the message */ cin>>mgr_sal; /* Accepts the value from the keyboard and
stores in mgr_sal */ cout<<"The manager's pay is $"< break; /* Terminated from switch */ case 2:cout<<"Hourly worker selected."< cout<<"Enter the hourly salary:"; /*prompts the message
*/ cin>>hour_sal; /* Accepts the value from the keyboard and
stores in hour_sal */ cout<<"Enter the total hours worked:"; /*prompts the
message */ cin>>hours; /* Accepts the value from the keyboard and
stores in hours */ if(hours<=40&&hours>0) /* if the hours value is in
between 0 and 40 */ pay=hours*hour_sal; /* calculates the pay using this formula
*/ else if(hours>40) /* If the hours value is greater than 40
*/ pay=(hours-40)*(hour_sal*1.5)+(40*hour_sal); /* calculates the
pay using this formula */ cout<<"Worker's pay is $"< break; /* Terminated from switch */ case 3:cout<<"Commission worker selected."< cout<<"Enter gross weekly sales:"; /*prompts the message
*/ cin>>week_sales; /* Accepts the value from the keyboard
and stores in week_sales */ pay=250+((week_sales*5.7)/100); /* calculates pay using this
formula */ cout<<"Commission worker's pay is $"< break; /* Terminated from switch */ case 4:cout<<"piece worker selected."< cout<<"Enter number of pieces:"; /*prompts the message
*/ cin>>pieces; /* Accepts the value from the keyboard and
stores in pieces */ cout<<"Enter wage per piece:"; /*prompts the message
*/ cin>>wage_piece; /* Accepts the value from the keyboard
and stores in wage_piece */ pay=pieces*wage_piece; /* calculates pay using this formula
*/ cout<<"Pieceworker's pay is $"< break; /* Terminated from switch */ case -1:cout<<"Have a good day!"; /*prompts the message
*/ exit(0); /* Exited from the Infinite loop */ default:cout<<"Invalid choice, please enter correct
choice"; /*prompts the message */ } /* End of switch */ cout< cin>>choice; /* Accepts the value from keyboard and stores
in the variable choice */ } /* End of the loop */ return 0; } /* End of main() function */ Output: