I am having trouble writing this code. I am somewhat close I think but I really need some help. Here is the prompt...
Problem Statement
Assume you are reading lines of data that correspond to records of employee's data. For example:
x135.5 14.56 999999999 Kenneth Todd Stevens
On each line, the first character is not used (so read it into a junk variable). The second character indicates which type of employee the individual is:
1. part-time hourly,
2. part-time salary,
3. full-time hourly without overtime,
4. full-time-hourly with double pay overtime
5. full-time salary
Use a if statements (or switch) on this character, and have a case for each type in which you will call the respective calc function to return the employee's weekly pay.
Immediately after each type character (1-5) is how many hours (float) the employee worked that week, then white-space, and then either their annual salary (double) or their hourly rate (double). Each field after the hours-worked is white-space separated. Next are their employee id number (long), first name, middle name, last name.
Write the following separate functions to calculate each employee's pay for the week:
• calcPartTimeHourly(float hours, double hrate)
- never paid for more than 39 hours
• calcPartTimeSalary(float hours, double sal)
• calcFullTimeHourlyWithoutOvertime(float hours, double hrate)
- never paid for over 40 hours
• calcFullTimeHourlyWithOvertime(float hours, double hrate)
- paid double-time for over 40 hours
• calcFullTimeSalary(float hours, double sal)
Each of these must return the calculated pay as a double. The functions must be named exactly this and have exactly these parameter types.
Sample Input
Name of input file: infile.txt
Sample Input File
a222.5 10000.00 329238390 Matthew Charles Mullenweg
g3999 59.99 327237237 Sergey Mikhailovich Brin
x1100.1 200 100000000 Edsger Wybe Dijkstra
p51 9999.99 123456890 Guido van Rossum
c499.9 100.01 777777777 Kenneth Lane Thompson
Sample Output (corresponding to the above input)
The id is 9 characters printed in a 12 character field; the name field is 15 characters, and the next 2 columns are first initial and middle initial. The other fields have just 1 space between them.
Name of input file: empInput.txt
329238390 Mullenweg M C $192.31
327237237 Brin S M $2399.60
100000000 Dijkstra E W $7800.00
123456890 Rossum G v $192.31
777777777 Thompson K L $15981.60
Number of Employees: 5
Number of Hours Worked: 1222.50
Total Payroll: $26565.81
Hint: You can access just the first character of a string with fname[0];
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
|
int main()
{
ifstream infile;
ofstream myOutfile;
char junk;
float hours;
float weekpay;
double annual_salary;
double hrate;
double sal;
long employeeID;
long firstname, middlename, lastname;
double calcPartTimeHourly;
double calcPartTimeSalary;
double calcFullTimeHourlyWithoutOvertime;
double calcFullTimeHourlyWithOvertime;
double calcFullTimeSalary;
char type;
string inputfile;
cout << "Name of input file: " << endl;
infile.open(inputfile);
myOutfile.open(inputfile);
if (! infile) // the ! means myInfile is non 0, indicating it is OK
{
cout << "Error" << endl;
return 1;
}
infile >> junk >> hours >> annual_salary >> employeeID >> firstname >> middlename >> lastname;
cin >> type;
if (type==1)
{
cin >> hours;
cin >> hrate;
calcPartTimeHourly = hours * hrate;
}
else if (type==2)
{
cin >> hours;
cin >> sal;
calcPartTimeSalary = hours * sal;
}
else if (type==3)
{
cin >> hours;
cin >> hrate;
calcFullTimeHourlyWithoutOvertime = hours * hrate;
}
else if (type==4)
{
cin >> hours;
cin >> hrate;
calcFullTimeHourlyWithOvertime = ((hours * hrate) + (40 - hours) * (hrate * 1.5));
}
else if (type==5)
{
cin >> hours;
cin >> sal;
calcFullTimeSalary = (hours * sal);
}
return 0;
}
|