1. Print the following heading at the top of the output page: Miser Corporation Payroll

2. Read an unknown number of employee data records as shown below. Each group of data will contain an employee's name, hours worked, rate of page and age. A typical group of data will be:

Duck, Donald
45 3.25 51

Print the data as it is read in, together with appropriate messages (e.g., the name is... the rate of pay is... etc.).

3. For each employee, compute and print the employee's base pay, which includes overtime (paid at one and a half times the normal rate) for each hour over 40. For example, if an employee earning \$20.00 per hour works for 48 hours, then she will be paid for 40 hours at her normal rate plus 8 extra hours at \$30.00 (one and a half times \$20.00).

4. For each employee compute the tax paid by the employee, according to this formula: If the employee is 55 years old (or order), then the employee pays tax at a rate of 50% of the base pay; if the employee is below 55, then the tax is 10% of the base pay. Print the tax and the net pay after taxes.

5. Repeat this process until you have read the last employee. You must decide how to detect the end of the data (you should explain your method in a comment).

6. Print the name and age of the oldest employee. Do the same for the youngest employee.

7. Print the name and taxes of the employee who paid the most in taxes.

8. Print an alphabetically sorted list of all the company's employees.

9. Print a list of the employees sorted by net pay.

10. After all your results have been printed, print a message saying that the payroll program is complete.

How do I go about doing this/getting organized? I have a very vague starting point drafted here:

``````#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

class employees {
public:
string name;
int hours;
float rate;
int age;
float basepay;
float tax;
float netpay;
};

int main() {

cout << "\t\t\tMiser Corporation Payroll\n" << endl;

ifstream datafile; // Declare input file
datafile.open("datafile.txt", ios::in); // Open input file

// Check for error opening input file
if (datafile.fail())
{
cout << "Error opening file; program halted" << endl;
exit(1);
}

employees info [];

while (datafile){
getline(datafile,line);
//Here I plan on reading in the groups of data as instructed to above... but I'm lost as to how I do that.
}

//...

datafile.close(); // Close input file
cout << "The payroll program is complete.";
return 0; // Close main program function
}``````

The operations after reading in the data I should be able to sufficiently figure out on my own... It's that whole major first part (steps 2-5) that's got me all confused. Help please!

Okay, trying to switch to struct instead of class for the records... using an example from the textbook but not in an identical context, so I'm getting errors on the datafile.read lines that say "no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::read(char*)'". So... I mean I gotta say I'm not familiar with using reinterpret_cast or whatever anyway, but it seems pretty crucial. I tried switching the name variable in the struct to type char (from string), but that didn't help either. How can I remedy this? because I think I should be onto something here. Thanks.

``````#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

struct records {
public:
char name;
int hours;
float rate;
int age;
float basepay;
float tax;
float netpay;
};

int main() {

cout << "\t\t\tMiser Corporation Payroll\n" << endl;

ifstream datafile; // Declare input file
datafile.open("datafile.txt", ios::in); // Open input file

// Check for error opening input file
if (datafile.fail())
{
cout << "Error opening file; program halted." << endl;
return 0;
}

records employee;

while (!datafile.eof()){
cout << "Name:\t" << employee.name << endl;
cout << "Hours worked:\t" << employee.hours << endl;
cout << "Rate of pay:\t" << employee.rate << endl;
cout << "Age:\t" << employee.age << endl;
cout << endl;