04 Sep C++- Please Solve TODO Sections And Match Sample Output.
C++- Please solve TODO sections and match sample output.
This lab practices reading input from file, performing
a simple calculation with the input values, and writing
the results to another file and echoing the output also
to the screen.
Your program will read the following data values from a file,
located in dataFile.txt in the project folder:
H 38 12.35 Haywood J’Paymee
S 32000.00 Mickey Mouse
H 40 15.11 John Smith, Jr.
The single character at the beginning of the line designates whether the
employee on that line is an hourly employee (H) or salaried (S).
Line formats:
Hourly: H <hours worked> <hourly wage> <full name>
Salaried: S <annual salary> <full name>
The output to the payroll file (Payroll.txt) will be formatted as follows:
469.30 Haywood J’Paymee
615.38 Mickey Mouse
604.40 John Smith, Jr.
The screen output will be formatted as follows:
Name Pay
==============================
Haywood JÆPaymee 469.30
Mickey Mouse 615.38
John Smith, Jr. 604.40
Several file commands have been provided
– The necessary library for file I/O has been included.
– Variables declared for the input and output streams.
– The file streams opened.
– Displaying the output to the screen.
– Closing the files.
You will be responsible for writing several commands to
read from the input file (inputFile = “dataFile.txt”) and
write to the output file (payrollFile = “Payroll.txt”)
Consider the following:
– do not prompt for input when reading data from a file
– do not use cin when reading data from a file
*/
#include<iostream>
#include<iomanip>
#include<fstream> // for file i/o
#include<string> // for string input/output
using namespace std;
int main()
{
char employeeType; // To hold the employee’s type, H for hourly, S for salaried
int hoursWorked; // To hold the number of hours worked for an hourly employee
double hourlyWage; // To hold the hourly wage for an hourly employee
double annualSalary; // To hold the annual salary for a salaried employee
double weeklyPay; // To hold the calculated weekly pay for either type of employee
string fullName; // To hold the employee’s full name
char blank; // Used to read a single character
const int WEEKS_PER_YEAR = 52;
// File stream variables
ifstream inputFile; // input file
ofstream payrollFile; // output file
// Open the input file (datafile.txt) and the output file (Payroll.txt)
inputFile.open(“datafile.txt”);
payrollFile.open(“Payroll.txt”);
// Display output header to the screen
cout << setw(20) << left << “Name” << setw(10) << right << “Pay” << endl;
cout << “==============================” << endl;
// Loop until the entire input file has been read
while (!inputFile.eof())
{
// TODO: Read the employee type from the input file
// (it will be a single character, H or S)
// Test to see if the employee type is H or S
// We will need to process the pay values differently for each employee type
if (employeeType == ‘H’) // Hourly employee
{
// TODO: Read the number of hours worked from the input file
// TODO: Read the hourly wage from the input file
// Calculate the hourly employee’s weekly pay (hours worked x hourly wage)
weeklyPay = hoursWorked * hourlyWage;
}
else
{ // Salaried employee
// TODO: Read the annual salary from the input file
// Calculate the salaried employee’s weekly pay (annual salary / number of weeks in a year)
weeklyPay = annualSalary / WEEKS_PER_YEAR;
}
// Read the full name from the input file
// We can wait until outside the if statement to read the name
// since it is the last item on the line for each type of employee
inputFile.get(blank); // this line required to skip blank space in front of name
// TODO: Read the employee’s full name – you will need to use getline
// TODO: Output the employee’s weekly pay and full name to the payroll file
// Be sure to include a blank space to separate the pay and the name
// Also, make sure the correct number of decimal places appear in the pay
// Output a single line to the console for the current employee
cout << fixed << setprecision(2) << left << setw(20) << fullName << setw(10) << right << weeklyPay << endl;
}
cout << endl;
// Close the input and output files
inputFile.close();
payrollFile.close();
return 0;
}
// NOTE: There should also be output to a file named Payroll.txt
/* Sample Program Screen Output
Name Pay
==============================
Haywood JÆPaymee 469.30
Mickey Mouse 615.38
John Smith, Jr. 604.40
Press any key to continue . . .
*/
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
About Writedemy
We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.
How It Works
To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Are there Discounts?
All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.