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

Three employees in a company are up for a special pay increase. You are given a

ID: 3758916 • Letter: T

Question

Three employees in a company are up for a special pay increase. You are given a file, 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 employee's last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87, and the pay increase is 5%.

Write a program that reads 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: firstName lastName updatedSalary. Format the output of decimal numbers to two decimal places.

Explanation / Answer

#include <iostream>

#include <fstream>

#include <string>

#include <iomanip>

using namespace std;

int main()

{

               

                                                                                                //Declare variables

ifstream inFile;

ofstream outFile;

string firstName, lastName;

double currentPay, upDatedPay, raise;

int counter = 0;

int numberEm;

                                                                                                //Process

inFile.open("Ch3_Ex7Data.txt");

outFile.open("Ch3_Ex7Output.dat");

outFile << fixed << showpoint;

outFile << setprecision(2);

cout << "Please Enter Number of Employees"<<endl;

cin >> numberEm;

                                                                                                //Looop

while (counter < numberEm)

{

inFile >> firstName >> lastName >> currentPay >> raise;

raise = raise / 100;

upDatedPay = currentPay * raise;

outFile << firstName << " " << lastName << " $"<< currentPay + upDatedPay << endl << endl;

counter++;

}

inFile.close() ;

outFile.close() ;

system ("pause");

                return 0;

}

YOU CAN ALSO TRY THIS CODE

#include <stdafx.h> // always include this if using visual studio
#include <iostream> // always include this
#include <string> // include this if working with string type
#include <iomanip> // include this if manipulating precision
#include <fstream> // include this if reading or writing to files
using namespace std;

int main()
{
// Declare Variables
ifstream inData; // input variable for file
ofstream outData; // output variable for file
string lastName = “”;
string firstName = “”;
double salary = 0;
double raisePercentage = 0;
double newSalary = 0;

// Format precision to two decimal places
cout << fixed << setprecision(2);
outData << fixed << setprecision(2);

cout << “This program reads data from a text file which contains employee names “;
cout << “ and salaries. It calculates a pay increase and stores the output in a new file. ”;

inData.open(“Ch3_Ex6Data.txt”); // opens input file
outData.open(“Ch3_Ex6Output.txt”); // creates and/or opens output file

// Process first employee
cout << “Reading data from old file… ”;
inData >> lastName >> firstName >> salary >> raisePercentage;
newSalary = salary * ((1 + raisePercentage) / 100) + salary;
cout << endl << firstName << ” ” << lastName << ” has a new salary of $” << newSalary;
outData << firstName << ” ” << lastName << ” ” << newSalary;

// Process second employee
inData >> lastName >> firstName >> salary >> raisePercentage;
newSalary = salary * ((1 + raisePercentage) / 100) + salary;
cout << endl << firstName << ” ” << lastName << ” has a new salary of $” << newSalary;
outData << firstName << ” ” << lastName << ” ” << newSalary;

// Process third employee
inData >> lastName >> firstName >> salary >> raisePercentage;
newSalary = salary * ((1 + raisePercentage) / 100) + salary;
cout << endl << firstName << ” ” << lastName << ” has a new salary of $” << newSalary;
cout << “ Writing data to new file…” << endl << endl;
outData << firstName << ” ” << lastName << ” ” << newSalary;

inData.close(); // closes input file
outData.close(); // closes output file

return 0;
}

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