Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a program that calculates pay for either an hourly paid worker or a sal

ID: 3757830 • Letter: 1

Question

1. 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: An important thing to note: We will be using nested structures. So actually there is another structure called PersonalInfo. FirstName, LastName and Title are members of that structure. You will be nesting the structures to achieve this scheme.

2. We will be using enumerations. For salaried employees, you have an enum type called BonusAvailability. Three values of this type are: “NO_BONUS”, “AVG_BONUS” and “HIGH_BONUS”.

3. The program should ask the user the number of employees that the user wishes to enter the information of. So if I say 10, I should be allowed to enter information about 10 employees. This means: The program should loop till I stop it.

4. Next step, you should ask the user about number of hourly/salaried workers to handle the information appropriately. So the flow should be like: How many employees you wish to define? 10. How many hourly workers are there? 4… After this you should be determine the information about salaried workers. Be careful though! Make some error checking. I should not be able to say 10 employees, 11 of them are hourly workers!

Hourly Paid Salaried Worker

First Name (P.Info) First Name (P.Info)

Last Name (P.Info) Last Name (P.Info)

Title (P.Info) Title (P.Info)

HoursWorked Salary

HourlyRate Bonus

BonusAvailability

5. At this step you should be able to enter information of the workers. One thing to note: BonusAvailability for salaried workers should be taken care of. If the user enters 0 for the bonus amount you should assign NO_BONUS, if the bonus is below $5000 you should assign AVG_BONUS and if the bonus is above $5000 you should assign HIGH_BONUS to this member (It should be determined automatically. You should not be entering NO_BONUS by yourself).

6. After all the entries are done or the user decides to exit the application (Yes! Ask the user if he/she wishes to continue entering information after each successful entry) a summary should be displayed. The format should be: First Name, Last Name and Total Salary in a single line for each employee (Total Salary is HoursWorked x HourlyRate for hourly workers and Salary for salaried workers).

7. After the first summary titled “List of Employees”, you should be generating another summary about salaried workers and the bonus they are getting. You should sort them depending on the bonus they are getting. The titles are “Employees with High Bonus”, “Employees with Average Bonus” and “Employees with No Bonus”. After each title in the console list the employees one by one with their first names and last names.

8. You should do input validation. Do not accept negative numbers (The salary cannot be negative) and do not accept values greater than 80 for HoursWorked.

I have this.

//This program
#include <iostream>
#include <string>
using namespace std;

struct PersonalInfo
{
string first, //employees first name
last, //employees last name
title; //employees title, Mr., Ms., Mrs.
};

struct HourlyPaid
{
PersonalInfo name; //Nested Structure
double hoursWorked;

union PaySource //Nested Union
{
int hourlyRate; //hours worked
double salary, //amount of sales
bonus; //amount of bonus
};
};

struct SalariedWorker
{
PersonalInfo name; //Nested Structure
union PaySource //Nested union
{
int hourlyRate; //hours worked
double salary, //amount of sales
bonus; //amount of bonus
};
};

enum bonusAvailability {NO_BONUS, AVG_BONUS, HIGH_BONUS};

int hourInfo();
int salaryInfo();

int main()
{
int numEmp, //Number of employees
hourWork, //Number of hourly workers
salWork, //Number of salaried workers
keepOn; //Continue to enter information

HourlyPaid employee;
SalariedWorker worker;

cout << "How many employees do you wish to enter information for? ";
cin >> numEmp;

cout << "How many are hourly workers? ";
cin >> hourWork;

//Validate entry
if (hourWork > numEmp)
{
cout << "The amount of hourly workers excedes the number of employees "
<< "Program ending. "
<< endl;
}
else
{
salWork = numEmp - hourWork;
}

do
{
for (int count = 0; count <= hourWork; count++)
{
cout << "For Hourly Workers: ";
cout << "Enter employee's first name: ";
getline(cin, employee.name.first);
cout << "Last name: ";
getline(cin, employee.name.last);
cout << "Title (Ms., Mr., Mrs.): ";
getline(cin, employee.name.title);
cout << "Enter hours worked: ";
cin >> employee.hoursWorked;
cout << "Enter hourly pay rate: ";
cin >> employee.HourlyPaid.PaySource.hourlyRate;
cout << "Would you like to continue to next employee? 1 = yes, 2 = no ";
cin >> keepOn;
}
}
while (keepOn == 1);
}

Explanation / Answer

This should work for you. If you have any problems, just ping me. I'll find a solution for you....
#include <iostream>
#include <string>
#define SIZE 10
using namespace std;
enum bonusAvailability {NO_BONUS, AVG_BONUS, HIGH_BONUS};
struct PersonalInfo
{
string first, //employees first name
last, //employees last name
title; //employees title, Mr., Ms., Mrs.
};
struct HourlyPaid
{
PersonalInfo name; //Nested Structure
double hoursWorked;
int hourlyRate; //hours worked
};
struct SalariedWorker
{
PersonalInfo name; //Nested Structure //hours worked
double salary, //amount of sales
bonus; //amount of bonus
bonusAvailability bonusCategory;
};

int hourInfo();
int salaryInfo();
int main()
{
int numEmp, //Number of employees
hourWork, //Number of hourly workers
salWork, //Number of salaried workers
keepOn, //Continue to enter information
count1,
count2;
HourlyPaid employee[SIZE];
SalariedWorker worker[SIZE];
cout << "How many employees do you wish to enter information for? ";
cin >> numEmp;
cout << "How many are hourly workers? ";
cin >> hourWork;
//Validate entry
if (hourWork > numEmp)
{
cout << "The amount of hourly workers excedes the number of employees "
<< "Program ending. "
<< endl;
exit(0);   
}
else
{
salWork = numEmp - hourWork;
}
keepOn = 1;
cout << "For Hourly Workers: ";
for (int count1 = 0; count1 < hourWork && keepOn == 1; count1++)
{
cout << "Enter employee's first name: ";
cin>>employee[count1].name.first;
cout << "Last name: ";
cin>>employee[count1].name.last;
cout << "Title (Ms., Mr., Mrs.): ";
cin>>employee[count1].name.title;
cout << "Enter hours worked: ";
cin >> employee[count1].hoursWorked;
cout << "Enter hourly pay rate: ";
cin >> employee[count1].hourlyRate;
cout << "Would you like to continue to next employee? 1 = yes, 2 = no ";
cin >> keepOn;
}
keepOn = 1;
for (int count2 = 0; count2 < salWork && keepOn == 1; count2++)
{
cout << "Enter employee's first name: ";
cin>>worker[count2].name.first;
cout << "Last name: ";
cin>>worker[count2].name.last;
cout << "Title (Ms., Mr., Mrs.): ";
cin>>worker[count2].name.title;
cout << "Enter the salary: ";
cin >> worker[count2].salary;
cout << "Enter the bonus amount: ";
cin >> worker[count2].bonus;
if(worker[count2].bonus == 0)
worker[count2].bonusCategory = NO_BONUS;
else if(worker[count2].bonus <= 5000)
worker[count2].bonusCategory = AVG_BONUS;
else
worker[count2].bonusCategory = HIGH_BONUS;
cout << "Would you like to continue to next employee? 1 = yes, 2 = no ";
cin >> keepOn;
}
  
cout<<"Hourly Employees Summary: "<<endl;
for(int i = 0; i < count1; i++)
cout<<employee[i].name.first<<" "<<employee[i].name.last<<" "<<employee[i].hoursWorked * employee[i].hourlyRate<<endl;
cout<<endl;
cout<<"Salaried Workers Summary: "<<endl;
for(int i = 0; i < count2; i++)
cout<<worker[i].name.first<<" "<<worker[i].name.last<<" "<<worker[i].salary+worker[i].bonus<<endl;

cout<<"Salaried Workers Categorized by bonus:"<<endl;
cout<<"Employees with Highest Bonus: "<<endl;
for(int i = 0; i < count2; i++)
if(worker[i].bonusCategory == HIGH_BONUS)
cout<<worker[i].name.first<<" "<<worker[i].name.last<<endl;
cout<<"Employees with Average Bonus: "<<endl;
for(int i = 0; i < count2; i++)
if(worker[i].bonusCategory == AVG_BONUS)
cout<<worker[i].name.first<<" "<<worker[i].name.last<<endl;
cout<<"Employees with No Bonus: "<<endl;
for(int i = 0; i < count2; i++)
if(worker[i].bonusCategory == NO_BONUS)
cout<<worker[i].name.first<<" "<<worker[i].name.last<<endl;

}