Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Three Employess in a company are up for a special Pay increase. uou are given a

ID: 3542266 • Letter: T

Question

Three Employess in a company are up for a special Pay increase. uou are given a file say Ch3_Ex7data.txt with the following data

Miller andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1

Each input line consists of an employees last name first name and current salary and a percent pay increase. For example in the first input line the last name of the employee miller the first name is andrew and the current salary is 65789.87 and the pay increase is 5%. Write a program that read data from the specified file and stores the output in the file Ch3_Ex7output.dat. For each employee the data must be output in the following form First name, Last name and updated salary. Format the output of the decimal numbers to two decimal places

Explanation / Answer

To read from a file in C++, you would need the following:
#include <fstream> // library containing input and output functions to read to or from a file
ifstream read; // use ifstream to read from a file
ofstream write; // use ofstream to write to a file

From your information you provided, you can create variables to temporarily store the data:
string fName = stores the first name
string lName = stores the last name
double salary = stores the salary
double perInc = percent increase

read.open("Chapter2_Ex18Data.txt");
write.open("Ch2_Ex18Output.dat");

To read from the file you would do something like this:
while ( !read.eof() )
{
read >> lName >> fName >> salary >> perInc; // captures the entire line of each value and stores it in appropriate variable

// here get the percInc and divide by 100 to get the actually percent (i.e. 5/100 = .05 which is 5%)
// multiply the percInc after / 100 to the salary for the increase. then add that to the original price to the new salary (updatedSalary)

// after you did that, send it to the second file
write << fName <<" " << lName <<" " << percInc;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote