c++ Format of clock.txt The first line of the file will contain a single positiv
ID: 665665 • Letter: C
Question
c++
Format of clock.txt
The first line of the file will contain a single positive integer, n, in between 1 and 20, inclusive, which represents the number of employees at the company. These employees will be numbered 0 through n – 1. The next n lines of the file will each contain a single positive real number representing the hourly pay rate for the corresponding employee. (Namely, the first line in this set contains the pay rate for employee 0, the second line contains the pay rate for employee 1, etc.). The next line will contain an integer w indicating how many weeks of data will follow. The rest of the file will contain w sets of data. Each set of data represents the data for that particular week. The first line of each set of data will contain a single positive integer k, representing the number of employee records for the week. (Note: a single employee record denotes one instance of an
employee clocking in and clocking out.) The following k lines will contain one employee record each. Each employee record will have the following format:
Emp# HrIn MinIn HrOut MinOut
Sample Input - clock.txt
2
5.50
10.00
3
2
1 10 30 13 30
0 7 0 16 30
4
0 9 0 14 30
1 7 0 23 0 - 16
1 9 0 22 0 - 13
1 7 20 23 20- 16
3
0 10 0 15 0
1 8 0 12 0
0 9 30 11 30
into an output text file.
Explanation / Answer
#include <ctime.h>
#include <iostream.>
#include <fstream.h>
using namespace std;
int RetrievePay(int,int,int,int);
int RetrieveExperienceYears(int);
int main()
{
ofstream StaffClockFile;
StaffClockFile.open ("clock.txt");
StaffClockFile << "Writing staff clock in and out data hourly rate results to file. ";
int StaffID, NumbOfHrsCllockedIn, SignedUpYear, RegularFullTimeStaff;
cout << "Staff ID: ";
cin >> StaffID;
cout << "Hours ClockedIn: ";
cin >> NumbOfHrsCllockedIn;
cout << "Year SignedUp: ";
cin >> SignedUpYear;
cout << "RegularFullTimeStaff Situation (0 for no, 1 for yes): ";
cin >> RegularFullTimeStaff;
double pay = RetrievePay(StaffID, NumbOfHrsCllockedIn, SignedUpYear, RegularFullTimeStaff);
double taxes = pay * 0.15;
cout << endl << "Empolyee ID: " << StaffID << endl << " Full time?: ";
if (RegularFullTimeStaff == 0)
cout << "No";
else
cout << "Yes";
cout << endl << " Hours ClockedIn: " << NumbOfHrsCllockedIn << endl << " Wages (after tax) for the month: $"
<< pay - taxes << endl << " Amount withheld for tax: $" << taxes;
// write results to the output file
StaffClockFile << endl << " Hours ClockedIn: " << NumbOfHrsCllockedIn << endl << " Wages (after tax) for the month: $"
StaffClockFile << pay - taxes << endl << " Amount withheld for tax: $" << taxes;
StaffClockFile.close();
return 0;
}
int RetrievePay(int StaffID, int NumbOfHrsCllockedIn, int SignedUpYear, int RegularFullTimeStaff) {
double RatePerHour = 14;
//Get the hourly wage
int wage = 14;
if( wage>=50 && wage < 100){
wage += 1.25;
}else if( wage < 160){
wage += 2.0;
}else{
wage += 3.0;
}
double BasePay = RatePerHour * NumbOfHrsCllockedIn;
int yearsOfService = RetrieveExperienceYears(SignedUpYear);
//Check if any additional benefits/bonusses are to be paid
if (RegularFullTimeStaff == 1)
{
BasePay += (35 *yearsOfService);
BasePay += 300;
}
else {
if (yearsOfService > 5)
BasePay += (35 * yearsOfService);
}
return BasePay;
}
int RetrieveExperienceYears(int SignedUpYear) {
time_t curTime = time(NULL);
int elapsed = curTime / (365 * 24 * 60 * 60);
return 1970 + elapsed - SignedUpYear;
}
//********************************************************
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.