Question

In: Computer Science

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

◦ Bonus

The program should also declare a structure 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 pay for an hourly paid worker or a salaried worker. Regardless of what the user selects, the appropriate members of the struct 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 hours worked.


Solutions

Expert Solution

#include
using namespace std;
struct HourlyPaid
{
double hoursWorked;
double hourlyRate;
};

struct Salaried
{
double salary;
double bonus;
};


int main()
{
HourlyPaid hp;
Salaried s;
int choice;
  
cout << "1. Calculate pay for hourly" << endl;
cout << "2. Calculate pay for salaried" << endl;
cout << "Which type are you calculating (1 or 2): ";
cin >> choice;
  
if(choice == 1) //hourly
{
cout << "Enter the no. of hours (0-80): ";
cin >> hp.hoursWorked;
while(hp.hoursWorked < 0 || hp.hoursWorked > 80)
{
cout << "Hours worked should be in range 0-80. Please enter again: ";
cin >> hp.hoursWorked;
}
  
  
cout << "Enter the hourly rate: ";
cin >> hp.hourlyRate;
while(hp.hourlyRate < 0)
{
cout << "Hourly rate can not be negative. Please enter again: " ;
cin >> hp.hourlyRate;
}
  
double pay = hp.hoursWorked * hp.hourlyRate;
cout << "The pay is $" << pay << endl;
}
else if(choice == 2)
{
cout << "Enter the regular salary: ";
cin >> s.salary;
while(s.salary< 0 )
{
cout << "Salary can not be negative. Please enter again: " ;
cin >> s.salary;
}
  
  
cout << "Enter the bonus amount: ";
cin >> s.bonus;
while(s.bonus < 0)
{
cout << "Bonus can not be negative. Please enter again: ";
cin >> s.bonus;
}
  
double pay = s.salary + s.bonus;
cout << "The pay is $" << pay << endl;

  
}
else
cout << "Invalid choice! " << endl;
  
}

output

$./a.out
1. Calculate pay for hourly
2. Calculate pay for salaried
Which type are you calculating (1 or 2): 1
Enter the no. of hours (0-80): 40
Enter the hourly rate: 15
The pay is $600

$./a.out
1. Calculate pay for hourly
2. Calculate pay for salaried
Which type are you calculating (1 or 2): 2
Enter the regular salary: 3000
Enter the bonus amount: 400
The pay is $3400


Related Solutions

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...
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...
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...
C++ Instructions A company hired 10 temporary workers who are paid hourly and you are given...
C++ Instructions A company hired 10 temporary workers who are paid hourly and you are given a data file that contains the last name of the employees, the number of hours each employee worked in a week, and the hourly pay rate of each employee. You are asked to write a program that computes each employee’s weekly pay and the average salary of all employees. The program then outputs the weekly pay of each employee, the average weekly pay, and...
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.
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 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...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT