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

Write a program that determines the net income for several employees. The progra

ID: 3750594 • Letter: W

Question

Write a program that determines the net income for several employees. The program should create a structure, Employee, with the following data:

struct Employee

{

string name;

float grossIncome;

float taxes;

};

The program should then create a vector of Employee structs, called Employees. Your program should have functions to: - Read the data from a data file “employeeData.txt” into the vector Employees. - Determine the net income for a given Employee. - Print all personal and income information for every Employee in the vector.

Explanation / Answer

Please find the code below.

CODE

=================

#include <iostream>

#include <fstream>

#include <vector>

using namespace std;

struct Employee

{

string name;

float grossIncome;

float taxes;

};

double getNetPay(vector<Employee> employees, string n) {

for(vector<int>::size_type i = 0; i != employees.size(); i ++) {

if(employees[i].name == n) {

return (employees[i].grossIncome - employees[i].taxes);

}

}

return -1;

}

void print(vector<Employee> employees) {

for(vector<int>::size_type i = 0; i != employees.size(); i ++) {

cout << "Employee " << (i+1) << " details : " << endl;

cout << "Employee name : " << employees[i].name << endl;

cout << "Employee gross income : $" << employees[i].grossIncome << endl;

cout << "Employee taxes : $" << employees[i].taxes << endl;

cout << "Employee net pay : $" << getNetPay(employees, employees[i].name) << endl;

cout << endl;

}

}

int main() {

vector<Employee> employees;

string n;

float gross, tax;

ifstream inFile;

inFile.open("employeeData.txt");

if (!inFile) {

cout << "Unable to open file";

return 0;

}

while (inFile >> n >> gross >> tax) {

employees.push_back({n, gross, tax});

}

inFile.close();

string name;

cout << "Enter the employee name to find net pay : ";

cin >> name;

double pay = getNetPay(employees, name);

if(pay == -1) {

cout << "No such employee found!!!";

} else {

cout << name << "'s net pay : " << pay << endl;

}

cout << "Below are all the employees details : " << endl;

print(employees);

}

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