(Calculating Salaries) A company pays its employees as managers (who receive a fixed week- ly 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—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 code 1, hourly workers have code 2, commission workers have code 3 and piecework- ers have code 4. Use a switch
What will be an ideal response?
```
// Calculate wages for each employee.
#include
#include
using namespace std;
int main()
{
int payCode; // current employee's pay code
int pieces; // current pieceworker's number of pieces
double salary; // current employee's salary
double hours; // current hourly employee's hours
double pay; // current employee's weekly pay
// prompt for first employee input
cout << "Enter paycode (-1 to end): ";
cin >> payCode;
// set floating-point number format
cout << fixed << setprecision( 2 );
// loop until sentinel value read from user
while ( payCode != -1 )
{
// switch to appropriate computation according to pay code
switch ( payCode )
{
case 1: // pay code 1 corresponds to manager
// prompt for weekly salary
cout << "Manager selected.\nEnter weekly salary: ";
cin >> salary;
// manager's pay is weekly salary
cout << "The manager's pay is $" << salary << '\n';
break; // exit switch
case 2: // pay code 2 corresponds to hourly worker
// prompt for hourly salary
cout << "Hourly worker selected.\n"
<< "Enter the hourly salary: ";
cin >> salary;
// prompt for number of hours worked
cout << "Enter the total hours worked: ";
cin >> hours;
// pay fixed for up to 40 hours
// 1.5 for hours over 40
pay = ( hours > 40.0 ? ( hours - 40 ) * 1.5 * salary
+ salary * 40.0 : salary * hours );
// display current employee's pay
cout << "Worker's pay is $" << pay << '\n';
break; // exit switch
case 3: // pay code 3 corresponds to commission worker
// prompt for gross weekly sales
cout << "Commission worker selected.\n"
<< "Enter gross weekly sales: ";
cin >> salary;
// pay $250 plus 5.7% of gross weekly sales
pay = 250.0 + 0.057 * salary;
// display current employee's pay
cout << "Commission worker's pay is $" << pay << '\n';
break; // exit switch
case 4: // pay code 4 corresponds to pieceworker
// prompt for number of pieces
cout << "Pieceworker selected.\n"
<< "Enter number of pieces: ";
cin >> pieces;
// prompt for wage per piece
cout << "Enter wage per piece: ";
cin >> salary;
pay = pieces * salary; // compute pay
// display current employee's pay
cout << "Pieceworker's pay is $" << pay << '\n';
break; // exit switch
default: // default case
cout << "Invalid pay code.\n";
break;
} // end switch
// prompt for next employee input
cout << "\nEnter paycode (-1 to end): ";
cin >> payCode;
} // end while
} // end main
```
You might also like to view...
You can press the ________ key to turn off the Format Painter
A) Alt B) End C) Home D) Esc
Software assurance can be proven, validated, and substantiated only by the process in place and the artifacts produced from each process.
Answer the following statement true (T) or false (F)
The _____ was formed in 1999 to certify interoperability of wireless network products based on IEEE 802.11 specifications.?
A. ?Wi-Fi Alliance B. ?Institute of Electrical and Electronics Engineers (IEEE) C. ?World Wide Web Consortium (W3C) D. ?Wi-MAX
What kind of files are created by Exchange while converting binary data to readable text in order to prevent loss of data??
A. ?.txt B. ?.tmp C. ?.exe D. ?.log