Problem 06 (8 points) Three employees in a company are up for a special pay incr
ID: 3753645 • Letter: P
Question
Problem 06 (8 points) Three employees in a company are up for a special pay increase. You are given a file. Data.txt. with the following data: Miller Andrew 65789.87 5 Green Shei1a 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 M1.1ler, the first name is Andrew, the current salary is 65789.87, and the pay increase s 5%. Wnte a prograrn that reads data from the specified file and stores the output in the file data must be output in the following form: firatName lastName updatedsalary. Format the output of decimal numbers to two decimal places. Output.dat. For each employee, theExplanation / Answer
Data.txt
Miller Andrew 65789.87 5
Green Sheila 75892 6
Sethi Amit 74900.50 6.1
_____________________
C++ Program :
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
//Creating Employee Structure
struct Employee {
string firstname;
string lastname;
double currsal;
double increasePercent;
} emp;
int main() {
Employee emp[3];
//defines an input stream for the data file
ifstream dataIn;
//Defines an output stream for the data file
ofstream dataOut;
//Declaring variables
string lname,fname;
double csal,incPercent;
double updated_sal;
//Opening the input file
dataIn.open("Data.txt");
/* Getting the values from the input file and
* populate those values into Employee structure
*/
for(int i=0;i<3;i++)
{
//Getting the values from the input txt file
dataIn>>lname>>fname>>csal>>incPercent;
emp[i].lastname=lname;
emp[i].firstname=fname;
emp[i].currsal=csal;
emp[i].increasePercent=incPercent;
}
//Closing the intput file
dataIn.close();
//creating and Opening the output file
dataOut.open("Output.dat");
//Setting the precision
dataOut<<setprecision(2)<<fixed<<showpoint;
//Writing the data to the output file
for(int i=0;i<3;i++)
{
updated_sal=emp[i].currsal+(emp[i].currsal*emp[i].increasePercent);
//Writing the data to the output file
dataOut<<emp[i].firstname<<" "<<emp[i].lastname<<" "<<updated_sal<<endl;
}
//Closing the output file.
dataOut.close();
return 0;
}
______________________
Output file:
Output.dat
Andrew Miller 394739.22
Sheila Green 531244.00
Amit Sethi 531793.55
_____________________Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.