Hello all,
I have little experience with C++ code, i have this program that i am not sure how to build.
• read the data from the file (via Linux redirection, no prompts)
• for each employee
determine how much the employee has earned
display the employee's ID number, category (using a descriptive word), and total
earned
• The output should be in the form of a table and each column in the table must have a
heading. The data in the ID number and category columns must be left justified. The total
earned values must be right justified, include a $ and 2 digits to the right of the decimal.
Remember to use constants for fixed values.
• The program must keep processing employee information until the end of file is
encountered.
• When all data has been processed, display the total amount earned by all employees as
the last line of the table with a suitable label. The final total must be right justified with
the amounts above it.
• Display messages stating the total number of employees processed and the average
amount paid
the raw file that it might read is.
1005 S 500.00
20 h 41.0 8.00
33 t 10.0 5.0 100.0
2109 H 30.0 10.0
4438 p 5.0 7 12 4 0
189 c 100.0 125.0 0.0 175.0 100.0
3149 P 2.5 7 10 18 4 6 0
Data File
A file contains the data needed to generate the weekly payroll summary. It is made up of several
employee records. Each record begins with the employee's identification number (int) and pay
code (char), see description of employee categories above. Then, depending on what category an
employee is in, the appropriate data will follow. Each data value will be separated by 1 or more
blanks.
• If the employee is salaried, the amount of his/her weekly salary (double) will be provided.
Example: 1005 s 500.00
• If the employee is hourly, the number of hours worked (double) followed by the hourly
pay rate (double) will be provided.
Example: 2017 h 41.0 8.75
• If the employee is on commission, his/her sales (double) made for the 5 days of the work
week will be provided.
Example: 1896 C 100.0 125.0 0.0 157.75 40.0
• If the employee is temporary, his/her hours worked (double) followed by hourly pay rate
(double) followed by the total amount of sales (double) will be provided.
Example: 2531 T 13.5 7.5 250.0
Page 2/4
• If the employee is a pieceworker, the amount paid (double) for an item will be provided,
followed by a series of values (int) representing his/her production for the week. The end
of the production values will be indicated by a 0. Note: all of the integers indicating
number of items produced will be greater than 0 except for the last value (sentinel) which
will be a 0.
Example: 3149 P 2.25 7 10 18 4 6 11 0
In the example above, the total number of items produced should be 56.
expected output should look like.
======================================================
ID# CATEGORY EARNINGS
------------------------------------------
1005 Salaried $ 500.00
20 Hourly $ 332.00
333 Temporary $ 65.00
2109 Pieceworker $ 300.00
4438 Commissioned $ 125.00
189 Salaried $ 500.00
3149 Salaried $ 112.00
TOTAL EARNED $ 1934.50
7 employees processed
Average pay per employees: $276.36
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
int main()
{
int id;
char paycode;
string category;
double earnings;
int employee = 0;
double sum = 0.00;
cout << "==========================================\n\n";
cout << left << setw(12) << "ID #"
<< left << setw(12) << "CATEGORY"
<< right << setw(12) << "EARNINGS"
<< "\n------------------------------------\n";
while (cin >> id >> paycode)
{
paycode = toupper(paycode);
//earnings = 0.0;
//cin.get(paycode);
// logic to find the type of employee.
if (paycode == 'S')
{
category = "Salaried";
cin >> earnings;
}
else if (paycode == 'H')
{
category = "Hourly" ;
double hours = 0;
double rate = 0;
cin >> hours >> rate;
earnings = hours * rate;
}
else if (paycode == 'T')
{
category = "Temporary" ;
double hours = 0;
double rate = 0;
double sales = 0;
cin >> hours >> rate >> sales;
earnings = (hours * rate) + sales;
}
else if (paycode == 'P')
{
category = "Pieceworker" ;
double rate = 0;
int item;
int itemsum;
cin >> rate >> item;
while (item != 0)
{
itemsum= itemsum+itemsum;
cin>>item;
}
earnings = itemsum * rate;
}
else if (paycode == 'C')
{
category = "Commissioned" ;
double sales = 0;
double salestotal =0;
cin >>sales;
for (int f = 1; f <= 5; f++)
{
salestotal = salestotal + salestotal;
}
earnings = salestotal;
}
cout << left << setw(12) << id
<< left << setw(12) << category
<< right << setw(12) << earnings
<< endl;
//cin.ignore(1000, '\n'); // ignore rest of line
employee++;
}
for (int j = 1; j < earnings; j++)
{
sum = sum + earnings;
}
cout <<"TOTAL EARNED " << right << setw(12) <<"$ "<<sum <<endl<<endl;
cout << employee<<" employee processed"<<endl;
cout <<"Average pay per employess; "<< "$ "<< sum / employee <<endl;
return 0;
}
|