C++ Program. Consider the following C++ struct which gathers a company\'s inform
ID: 674745 • Letter: C
Question
C++ Program.
Consider the following C++ struct which gathers a company's information about an employee into one data item:
struct EmployeeInfo{
string lastName;
string firstName;
double salary;
double percentIncrease;
double newSalary;
};
Write a program for a company of no more than ten employees, keeping their data in an array of these structs (one for each employee).
The program is to read a data file (sample attached), containing one line for each employee with
Employee last name
Employee first name
Employee current salary
Employee percentage raise
Once an employee's current salary and percentage raise are known, the program can compute and fill in the employee's "newSalary".
Once this computation is done, report each employee's name (first name *first*, then last) and new salary. Report with exactly two digits to the right of the decimal point, even if not "necessary" (i.e. if my new salary is exactly one hundred dollars, report it as $ 100.00, not $100.)
lab9data.txt:
Explanation / Answer
Comments added
#include <iostream>
#include <cstring>
#include <fstream>
#include <sstream>
using namespace std;
//struct employee info decalred
struct EmployeeInfo{
string lastName;
string firstName;
double salary;
double percentIncrease;
double newSalary;
};
int main( )
{
EmployeeInfo * employee = new EmployeeInfo[10];
int iter = 0;
std::ifstream readfile("lab9data.txt");//reding employee data from file
std::string eachline;
while (std::getline(readfile, eachline))
{
//variables to store temp variables
std::stringstream linestream(eachline);
std::string data;
string lastName;
string firstName;
double salary;
double increment;
//reading values by using delimiter as space between values
std::getline(linestream," ");
linestream >> lastName >> firstName >> salary >> increment;
employee[iter].lastName = lastName;
employee[iter].firstName = firstName;
employee[iter].salary = salary;
employee[iter].percentIncrease = increment;
double newsalry = salary + (salary*increment*0.01);
employee[iter].newSalary = newsalry;
iter++;
}
cout<<" ";
//printing data
for(int i=0;i<iter;i++){
cout<<"firstName: "<<employee[iter].firstName<<" LastName: "<<employee[iter].lastName<<" newsalry: "<<employee[iter].newSalary<<" ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.