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

J Inc. has a file with employee details. You are asked to write a C++ program to

ID: 3732783 • Letter: J

Question

J Inc. has a file with employee details. You are asked to write a C++ program to read the file and display the results with appropriate formatting. Read from the file a person's name, SSN, and hourly wage, the number of hours worked in a week, and his or her status and store it in appropriate vector of obiects. For the output, you must display the person's name, SSN, wage, hours worked, straight time pay, overtime pay, employee status and net pay. Pay calculations and output display should be carried out using functions. For full-time employees, $10 is deducted from wages for union fees. A person is full-time if the status is F. Time and a half is paid for any time worked over 40 hours in a week. Make sure the output is formatted into rows and columns and includes the appropriate titles and column headings. Additional requirements: 1) Define a class Employee with appropriate member variables and the following member functions: a. Two constructors: /I constructor that takes five parameters Employee(string theName, string theSsn, double theHourlywage, double theHoursWorked, char theStatus); // default constructor Employee(); b. Appropriate accessors and mutators. Make all accessors and mutators inline functions c. calculatePay0 and displayEmployee0 should also be member functions of class Employee. Eor all the member functions.use const modifier whereverappropriate. 2) Define a vector of Employee objects in main0. Handle the file reading properly, and use constructor to set values for each Employee object. Can someone please help using classes and not structures?

Explanation / Answer

#include<iostream>

#include<fstream>

#include<string>

#include<vector>

using namespace std;

class Employee{

string ename,ssn;

double wage,hours,pay;

char status;

public:

Employee(string theName, string theSsn, double theHourlywage, double theHoursWorked, char theStatus)

{

ename=theName;

ssn=theSsn;

wage=theHourlywage;

hours=theHoursWorked;

status=theStatus;

}

Employee(){}

void displayEmployee(){

calculatePay();

cout<<"Employee name: "<<ename<<endl;

cout<<"SSN: "<<ssn<<" ";

cout<<"Wage: "<<wage<<endl;

cout<<"Hours worked: "<<hours<<endl;

cout<<"Pay: "<<pay<<endl;

}

void calculatePay(){

if(hours>40)

pay=hours*1.5*wage;

else

pay=wage*hours;

if(status=='F')

pay=pay-10; // $10 deduction for union fees

}

};

Employee readingfile(ifstream &OutputFile)

{

Employee obj;

OutputFile.read((char*)&obj, sizeof(obj));

return obj;

}

int main()

{

vector<Employee> myvector;

ifstream file_obj;

file_obj.open("Input.txt", ios::in);

while(!EOF){

myvector.push_back(readingfile(file_obj));

}

for(int i=0;i<myvector.size();i++)

{

myvector[i].displayEmployee();  

}

file_obj.close();

}

//To write sample data into file you can use the following code separately

/* ofstream file_obj;

file_obj.open("Input.txt",ios::app);

Employee obj("john","xyz",10,34,'H');

Employee obj1("sean","abc",50,10,'F');

file_obj.write((char*)&obj, sizeof(obj));

file_obj.write((char*)&obj1, sizeof(obj1));

file_obj.close();

*/