Sunday, 8 April 2018

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,” i.e., 1.5 times their hourly wage, for overtime hours worked), commission workers (who receive $250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce—each pieceworker in this company works on only one type of item). 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 paycode 1, hourly workers have code 2, commission workers have code 3 and piece- workers have code 4. Use a switch to compute each employee’s pay based on that employee’s paycode. Within the switch, prompt the user (i.e., the payroll clerk) to enter the appropriate facts your program needs to calculate each employee’s pay based on that employee’s paycode.

#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main ()
{
int paycode,weklysalary,hourlysalary,totalhours,grossweklysales,pieces,piecewage;
double pay;
cout<<"Enter paycode (1 to 4):"<<endl;
cout<<"press 1 for manager weelky salary"<<endl;
cout<<"press 2 for hourly worker salary"<<endl;
cout<<"press 3 for comission worker salary"<<endl;
cout<<"press 4 for piece worker salary"<<endl;
cin>>paycode;
switch (paycode)
{
case 1:
{
cout<<"Manager selected." << endl;
cout<<"Enter weekly salary: ";
cin>>weklysalary;
cout<<endl;
pay=weklysalary;
cout<<"The manager's pay is  " << pay;
cout<<endl;
    }
break;
case 2:
{
cout<<"Hourly worker selected." << endl;
cout<<"Enter the hourly salary: ";
cin>>hourlysalary;
cout<<endl;
    cout<<"Enter the total hours worked: " << endl;
cin>>totalhours;
if ( totalhours <= 40)
pay = hourlysalary * totalhours;
else
pay = (40.0 * hourlysalary) + (totalhours - 40) * (hourlysalary * 1.5);
cout<<endl;
    cout<<"Worker's pay is  " << pay;
    cout<<endl;

    }
break;
case 3:
{
cout<<"Commission worker selected." << endl;
cout<<"Enter gross weekly sales: ";
cin>>grossweklysales;
cout<<endl;
    pay = (grossweklysales *.57) + 250;
cout<<" Commission worker's pay is  " << pay;
    }
break;
case 4:
{
cout<<"Pieceworker selected." << endl;
    cout<<"Enter number of pieces: ";
cin>>pieces;
cout<<"Enter wage per piece: ";
cin>>piecewage;
pay = pieces * piecewage;
    cout<<"Pieceworker's pay is  " << pay;
    }
    break;
default:
cout<<"invalid number";
}
return 0;
}

No comments:

Post a Comment