Must be C++, please read carefully. Three employees in a company are up for a sp
ID: 668343 • Letter: M
Question
Must be C++, please read carefully.
Three employees in a company are up for a special pay increase. You are given a file, say Employee.txt, with the following data:
Smith John 65789.87 5
Wallace Tom 75892.56 6
West Sara 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 Smith, the first name is John, 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 UpdatedSalary.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>
using namespace std;
int main()
{
ifstream infile("Employee.txt");
string firstname;
string lastname;
float currentPay,percentPay;
ofstream outfile;
outfile.open ("UpdatedSalary.dat");
while(infile >> lastname >> firstname >> currentPay >> percentPay)
{
outfile << firstname << " " << lastname << " " <<currentPay+currentPay*(percentPay/100) << endl;
}
outfile.close();
infile.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.