Question

In: Computer Science

In C++, Write a program that calculates pay for either an hourly paid worker or a...

In C++,

Write a program that calculates pay for either an hourly paid worker or a salaried worker. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are paid their regular salary plus any bonus they may have earned. The program should declare two structures for the following data:


Hourly Paid:
HoursWorked
HourlyRate
Salaried:
Salary
Bonus


The program should also declare a union with two members. Each member should be a structure variable: one for the hourly paid worker and another for the salaried worker. The program should ask the user whether he or she is calculating the pay for an hourly paid worker or a salaried worker. Regardless of which the user selects, the appropriate members of the union will be used to store the data that will be used to calculate
the pay.


Input Validation: Do not accept negative numbers. Do not accept values greater than
80 for HoursWorked.

Solutions

Expert Solution

#include <iostream>
using namespace std;

union Employee
{
struct
{
int hoursWorked;
double hourlyRate;
}hourlyPaid;;

struct
{
double salary;
double bonus;
}salaried;

};
  
int main()
{
union Employee emp;
int employeeType;
int hoursWorked;
double hoursWorked1,hourlyRate1,salary1,bonus1;
cout<<"\nEnter the type of Employee <1-salaried, 2-hourlyPaid>: ";
cin>>employeeType;

if(employeeType == 1)
{
cout<<"\nEnter salary : ";
cin>>salary1;
if(salary1 < 0)
{
cout<<"\nSalary cannot be negative.Enter again";
cin>>salary1;
}
  
emp.salaried.salary = salary1;
cout<<"\nEnter bonus : ";
cin>>bonus1;
if(bonus1 < 0)
{
cout<<"\nbonus cannot be negative.Enter again";
cin>>bonus1;
}
emp.salaried.bonus = bonus1;
cout<<"\nTotal Pay = "<<(emp.salaried.salary + emp.salaried.bonus);
}
else if(employeeType == 2)
{
cout<<"\nEnter HourlyRate : ";
cin>>hourlyRate1;
if(hourlyRate1 < 0)
{
cout<<"\nHourly pay rate cannot be negative.Enter again";
cin>>hourlyRate1;
}
emp.hourlyPaid.hourlyRate= hourlyRate1;
cout<<"\nEnter number of HoursWorked : ";
cin>>hoursWorked1;
if(hoursWorked1 < 0 || hoursWorked1 > 80)
{
cout<<"\nHours Worked cannot be negative or greater than 80.Enter again";
cin>>hoursWorked1;
}
emp.hourlyPaid.hoursWorked = hoursWorked1;
cout<<"\nTotal Pay = "<<(emp.hourlyPaid.hourlyRate * emp.hourlyPaid.hoursWorked);
  
}


   return 0;
}

output:

Enter the type of Employee <1-salaried, 2-hourlyPaid>: 1
Enter salary : 4566.89
Enter bonus : 120.67
Total Pay = 4687.56

Enter the type of Employee <1-salaried, 2-hourlyPaid>: 2
Enter HourlyRate : 124.67
Enter number of HoursWorked : 55
Total Pay = 6856.85


Related Solutions

Write a C++ program that calculates pay for either hourly paid workers or salaried workers.
Write a C++ program that calculates pay for either hourly paid workers or salaried workers. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are payed their regular salary plus any bonus they may have earned. The program should declare two structures for the following data:• Hourly Paid◦ HoursWorked◦ HourlyRate• Salaried◦ Salary◦ BonusThe program should also declare a structure with two members. Each member should be a structure variable: one for the...
Write a program that calculates pay for either hourly paid workers or salaried workers. Hourly paid...
Write a program that calculates pay for either hourly paid workers or salaried workers. Hourly paid workers are paid their hourly pay rate times the number of hours worked. Salaried workers are payed their regular salary plus any bonus they may have earned. The program should declare two structures for the following data: • Hourly Paid ◦HoursWorked ◦ HourlyRate • Salaried ◦ Salary ◦ Bonus The program should also declare a structure with two members. Each member should be a...
Create a C # program that calculates what a worker must be paid if each day...
Create a C # program that calculates what a worker must be paid if each day I work different hours during the week. The price per hour is 80.0.
Write a C program that calculates a worker’s wages from their hours worked and hourly rate....
Write a C program that calculates a worker’s wages from their hours worked and hourly rate. This wage calculator should also account for overtime hours, calculate amount to be witheld from taxes, and calculate the final net income. Required functionality: 1. Ask the user for the number of hours worked and hourly rate in dollars. The program should be able to accept decimal values for both of these (e.g. 3.2 hours, 11.25 dollars/hour) 2. Overtime hours are those worked in...
In C Program #include Create a C program that calculates the gross and net pay given...
In C Program #include Create a C program that calculates the gross and net pay given a user-specified number of hours worked, at minimum wage. The program should compile without any errors or warnings (e.g., syntax errors) The program should not contain logical errors such as subtracting values when you meant to add (e.g., logical errors) The program should not crash when running (e.g., runtime errors) When you run the program, the output should look like this: Hours per Week:...
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $...
Write a C++ program that calculates mileage reimbursement for a salesperson at a rate of $ 0.35 per mile. Your program should interact with the user in this manner: MILEAGE REIMBURSEMENT CALCULATOR Enter beginning odometer reading: 13505.2 Enter ending odometer reading     : 13810.6 You traveled 305.40 miles. At $ 0.35 per mile, your reimbursement is $ 106.89. The values in red color are inputs for the program. The values in blue color are results of expressions.
Write a C program that calculates a student grade in the C Programming Class. Ask the...
Write a C program that calculates a student grade in the C Programming Class. Ask the user to enter the grades for each one of the assignments completed in class: Quiz #1 - 25 points Quiz #2 - 50 points Quiz #3 - 30 points Project #1 - 100 points Project #2 - 100 points Final Test - 100 points The total of the quizzes count for a 30% of the total grade, the total of the projects counts for...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of...
USING C++ PLEASE Write a program named Lab11C that calculates the average of a group of test scores where the lowest score is dropped. It should use the following functions a) void getScores should have 4 double reference parameters (one for each test score) getScores should do the following: - read 4 test scores from the text file Lab11C.txt (Important: declare your ifstream infile and open the file inside this function, not in the main function) - store them in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT