I am trying to modify this program so that it stores the employee's name in a c-string and can handle up to 100 employees (so it would mostly be a partially filled array), but I cannot get it to work. It works with two files that it is suppose to read input from. Then it prints output to an output file.
Employee Info File (first file read, M/F should be ignored):
5 Christine Kim 30.00 2 1 F
15 Ray Allrich 10.25 0 0 M
16 Adrian Bailey 12.50 0 0 F
17 Juan Gonzales 30.00 1 1 M
18 Morris Kramer 8.95 0 0 M
22 Cindy Burke 15.00 1 0 F
24 Esther Bianco 10.25 0 0 F
25 Jim Moore 27.50 3 1 M
32 Paula Cameron 14.50 0 0 F
36 Melvin Ducan 10.25 0 0 M
37 Nina Kamran 30.00 1 1 F
38 Julie Brown 35.00 0 1 F
40 Imelda Buentello 14.50 0 0 F
42 J. P. Morgan 12.50 0 0 M
43 Maria Diaz 15.00 0 0 F
Timecard File with ID number and hours worked (second file read):
17 20.0
37 31.0
5 40.0
42 39.5
24 15.0
22 40.0
15 42.0
18 40.0
25 45.0
32 25.0
40 47.5
36 -40.0
16 40.0
38 35.0
43 40.0
33 30.0
#include
#include
#include
#include
using namespace std;
class Employee
{
private:
int id;
string name;
double hourlyPay;
int numDeps;
int type;
public:
Employee( int initId=0, string initName="",
double initHourlyPay=0.0,
int initNumDeps=0, int initType=0 );
bool set(int newId, string newName, double newHourlyPay,
int newNumDeps, int newType);
int getID(){ return id; }
string getName() { return name; }
double getHourlyPay() { return hourlyPay; }
int getNumDeps() { return numDeps; }
int getType() { return type; }
};
Employee::Employee( int initId, string initName,
double initHourlyPay,
int initNumDeps, int initType )
{
bool status = set( initId, initName, initHourlyPay,
initNumDeps, initType );
if ( !status )
{
id = 0;
name = "";
hourlyPay = 0.0;
numDeps = 0;
type = 0;
}
}
bool Employee::set( int newId, string newName, double newHourlyPay,
int newNumDeps, int newType )
{
bool status = false;
if ( newId > 0 && newHourlyPay > 0 && newNumDeps >= 0 &&
newType >= 0 && newType <= 1 )
{
status = true;
id = newId;
name = newName;
hourlyPay = newHourlyPay;
numDeps = newNumDeps;
type = newType;
}
return status;
}
int main()
{
const int TOTAL_EMPS = 6,
INSURANCE = 20;
const float TAX_RATE = .15;
int insurance;
float hoursWorked,
grossPay,
tax,
netPay;
int id;
string name;
double hourlyPay;
int numDeps;
int type;
float totalGross = 0.0,
totalNet = 0.0;
int transactions = 0;
Employee employee[6];
ifstream inFile("sample9.txt");
for (int i = 0; i < TOTAL_EMPS; i++)
{
inFile >> id;
inFile.ignore();
getline(inFile, name, '#');
inFile >> hourlyPay >> numDeps >> type;
employee[i].set(id, name, hourlyPay, numDeps, type);
}
inFile.close();
ifstream inFile2("trans9.txt");
ofstream outFile("payroll2.txt");
// Write report
outFile << fixed << setprecision(2)
<< setw(2) << "ID" << " "
<< setw(20) << left << "Employee Name"
<< setw(10) << right << "Gross Pay"
<< setw(10) << "Tax"
<< setw(12) << "Insurance"
<< setw(10) << "Net Pay" << endl;
outFile << "----------------------------------------------"
<< "-------------------" << endl;
for (int i = 0; i < TOTAL_EMPS; i++)
{
inFile2 >> id;
inFile2 >> hoursWorked;
if (!employee[i].getID())
cout << "Entry #" << i+1 << " in employee master file "
<< "-- invalid employee data!\n";
else if (hoursWorked < 0.0)
cout << "Entry #" << i+1 << " employee #"
<< id << " in transaction file -- invalid hours worked!\n";
else
{
if (hoursWorked <= 40 || employee[i].getType())
grossPay = hoursWorked * employee[i].getHourlyPay();
else
grossPay = (40 * employee[i].getHourlyPay()) +
((hoursWorked - 40) * employee[i].getHourlyPay() * 1.5);
tax = grossPay * TAX_RATE;
insurance = employee[i].getNumDeps() * INSURANCE;
netPay = grossPay - tax - insurance;
outFile << fixed << setprecision(2)
<< setw(2) << id << " "
<< setw(20) << left << employee[i].getName()
<< setw(10) << right << grossPay
<< setw(10) << tax
<< setw(12) << insurance
<< setw(10) << netPay << endl;
totalGross += grossPay;
totalNet += netPay;
transactions++;
}
}
inFile2.close();
outFile << endl
<< setw(23) << "Total gross pay: "
<< setw(10) << totalGross
<< setw(22) << "Total net pay: "
<< setw(10) << totalNet << endl;
outFile.close();
cout << "Total transactions processed: " << transactions << endl;
return 0;
}
If you have any doubts, please give me comment...
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
class Employee {
private:
int id;
char name[100];
double hourlyPay;
int numDeps;
int type;
public:
Employee(int initId = 0, char *initName='\0', double initHourlyPay = 0.0, int initNumDeps = 0, int initType = 0);
bool set(int newId, char *newName, double newHourlyPay, int newNumDeps, int newType);
int getID() { return id; }
char *getName() { return name; }
double getHourlyPay() { return hourlyPay; }
int getNumDeps() { return numDeps; }
int getType() { return type; }
};
Employee::Employee(int initId, char *initName, double initHourlyPay, int initNumDeps, int initType)
{
bool status = set(initId, initName, initHourlyPay, initNumDeps, initType);
if (!status)
{
id = 0;
name[0] = '\0';
hourlyPay = 0.0;
numDeps = 0;
type = 0;
}
}
bool Employee::set(int newId, char *newName, double newHourlyPay, int newNumDeps, int newType)
{
bool status = false;
if (newId > 0 && newHourlyPay > 0 && newNumDeps >= 0 &&
newType >= 0 && newType <= 1)
{
status = true;
id = newId;
strcpy(name, newName);
hourlyPay = newHourlyPay;
numDeps = newNumDeps;
type = newType;
}
return status;
}
int main()
{
const int TOTAL_EMPS = 100,
INSURANCE = 20;
const float TAX_RATE = .15;
int insurance;
float hoursWorked,
grossPay,
tax,
netPay;
int id;
char name[100];
double hourlyPay;
int numDeps;
int type;
char gender;
float totalGross = 0.0,
totalNet = 0.0;
int transactions = 0;
Employee employee[TOTAL_EMPS];
ifstream inFile("sample9.txt");
char fname[50], lname[50];
int n=0;
while(inFile>>id)
{
inFile >>fname>>lname;
inFile >> hourlyPay >> numDeps >> type>>gender;
strcpy(name, fname);
strcat(name, " ");
strcat(name, lname);
employee[n].set(id, name, hourlyPay, numDeps, type);
n++;
}
inFile.close();
ifstream inFile2("trans9.txt");
ofstream outFile("payroll2.txt");
// Write report
outFile << fixed << setprecision(2)
<< setw(2) << "ID"
<< " "
<< setw(20) << left << "Employee Name"
<< setw(10) << right << "Gross Pay"
<< setw(10) << "Tax"
<< setw(12) << "Insurance"
<< setw(10) << "Net Pay" << endl;
outFile << "----------------------------------------------"
<< "-------------------" << endl;
int i;
while(!inFile2.eof())
{
inFile2 >> id;
inFile2 >> hoursWorked;
for(i=0; i<n; i++){
if(id==employee[i].getID())
break;
}
if (i==n)
cout << "Entry #" << i + 1 << " in employee master file "
<< "-- invalid employee data!\n";
else if (hoursWorked < 0.0)
cout << "Entry #" << i + 1 << " employee #"
<< id << " in transaction file -- invalid hours worked!\n";
else
{
if (hoursWorked <= 40 || employee[i].getType())
grossPay = hoursWorked * employee[i].getHourlyPay();
else
grossPay = (40 * employee[i].getHourlyPay()) +
((hoursWorked - 40) * employee[i].getHourlyPay() * 1.5);
tax = grossPay * TAX_RATE;
insurance = employee[i].getNumDeps() * INSURANCE;
netPay = grossPay - tax - insurance;
outFile << fixed << setprecision(2)
<< setw(2) << id << " "
<< setw(20) << left << employee[i].getName()
<< setw(10) << right << grossPay
<< setw(10) << tax
<< setw(12) << insurance
<< setw(10) << netPay << endl;
totalGross += grossPay;
totalNet += netPay;
transactions++;
}
}
inFile2.close();
outFile << endl
<< setw(23) << "Total gross pay: "
<< setw(10) << totalGross
<< setw(22) << "Total net pay: "
<< setw(10) << totalNet << endl;
outFile.close();
cout << "Total transactions processed: " << transactions << endl;
return 0;
}

I am trying to modify this program so that it stores the employee's name in a...
Expand the payroll program to combine two sorting techniques
(Selection and Exchange sorts) for better efficiency in sorting the
employee’s net pay.
//I need to use an EXSEL sort in order to
combine the selection and Exchange sorts for my program. I
currently have a selection sort in there. Please help me with
replacing this with the EXSEL sort.
//My input files:
//My current code with the sel sort. Please help me replace this
with an EXSEL sort.
#include <fstream>...
i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...
Hello, I am trying to get this Array to show the summary of NETPAY but have been failing. What is wrong? #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ]; char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int sum; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID, FNAME, LNAME, HRS...
I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...
C++. I need to alter this code below to the current specifications. Console Progressing Complete!!! Specifications Included is an input file. Included is a function to aide, if needed Use the functions, enum, and namespace defined in Assignment 6. You will need to use a loop to read each student’s data You will need to load every homework grade into an array Calculate the homework average The homework average can be calculated while the array is loaded Move the printing...
I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...
Right now, program pushes all data to screen in three loops need to prompt user for three text files, and need to push data from each loop into those three text files. #include #include #include #include #include #include #include #include using namespace std; double random(double minprice, double maxprice); string printRandomString(int n); bool coinToss(); int clicks(); int runme(); int createfiles(); struct things{ //things(); int id; string name; string category; double price; bool two_day_shipping; int...
Hi, I am trying to convert a string vector to a double vector in c++ , but for some reason I am getting this error message. Hope you can help! Thanks error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘double atof(const char*)’ double salary = atof(info[x].stringsalary); my code is... void display(vector<Employee_Data>& info){ double total = 0; cout << "id" <<setw(25) <<"first name" <<setw(25) <<"last name" <<setw(25) <<"gender" <<setw(25) <<"department" <<setw(25) <<"salary" << endl ; for(int...
This is C++. The task is to convert the program to make use of fucntions, but I am am struggling to figure out how to do so. #include <iostream> #include <iomanip> using namespace std; main(){ char empid[ 100 ][ 12 ]; char fname[ 100 ][ 14 ], lastname[ 100 ][ 15 ]; int hw[ 100 ]; double gp[ 100 ], np[ 100 ], hr[ 100 ], taxrate[100], taxamt[ 100 ]; int counter = 0; int i; cout<<"ENTER EMP ID,...