Description: A program is needed for a third-party payroll clearinghouse that supports the following:
Calculate employee pay feature
Company total pay feature
The employee and company totals are stored in a text file for each individual company.
1. Create the following “input.txt” file. Each record consists of a first name, last name, employee ID, company name, hours worked, and pay rate per hour.
Maria Brown 10 Intel 42.75 39.0
Jeffrey Jackson 20 Boeing 38.0 32.5
Bernard Smith 30 Douglas 25.0 23.25
Matthew Davenport 40 Raytheon 63.15 47.5
Kimberly Macias 50 Douglas 45.5 40.0
Amber Daniels 60 Raytheon 62.25 44.5
Michael Lee 70 Boeing 32.0 35.5
Patricia Wright 80 Intel 40.0 32.0
Stanley Johnson 90 HealthTech 48.5 43.25
James Miller 100 Raytheon 55.5 45.75
Linda David 110 HealthTech 40.0 36.5
Olivia Walker 120 Intel 61.15 51.5
Thomas Sanders 130 Raytheon 50.25 38.5
Sophia Foster 140 Raytheon 44.15 44.0
Ryan Ward 150 Douglas 68.0 48.25
Karen Hill 160 Intel 49.5 54.0
2. Each record will be saved in an instance of a CLASS called Person. The person class will be declared as follows (HINT: this should go in a file called person.h):
//begin person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class Person
{
private:
string firstName;
string lastName;
int employeeID;
string companyName;
float hoursWorked;
float payRate;
public:
Person();
void setFirstName(string fName);
string getFirstName();
void setLastName(string lName);
string getLastName();
void setEmployeeId(int id);
int getEmployeeId();
void setCompanyName(string coName);
string getCompanyName();
void setPayRate(float rate);
float getPayRate();
void setHoursWorked(float hours);
float getHoursWorked();
float totalPay();
string fullName();
};
#endif // end person.h
3. You will need to make a separate file called person.cpp. The file person.cpp contains proper definitions for all function declarations in the header file. The first line of the file is an include statement:
#include "person.h"
Here is an example of a function definition in person.cpp:
string Person::getFirstName() {
return firstName;
}
Note the <ret type> Classname::funcName() structure here. The “::” is referred to as a scope resolution operator. It lets the compiler know that this code is defining a function for the class Person, and not a bare function that can be used anywhere. It also lets the compiler know that the variables reference in the function can be found within that class. This is required, because they are private otherwise.
4. Make a new file called pay.cpp that includes:
A main() function
The #include "person.cpp" statement
Any other necessary includes and/or helper functions
All the additional details mentioned below
5. A vector called employees used to store the employee data when reading from the file (employees will be of the Person class). Use of the vector class (instead of an array) will ensure that your data space can grow as needed to handle any reasonable number of employees. Use of a vector is required. It should be declared in main().
6. A vector called companyNames that holds the string names of each company (companyNames will be of type string). This information will be needed to complete step 10. Use of a vector is required. It should be declared in main().
7. A function readData to read the data from “input.txt” and store it in the employees vector. NOTE: the vector needs to be passed to the function by reference and the file should be read only once in the program.
8. A function getCompanies that retrieves the company names from employees and adds them to companyNames. NOTE: both vectors need to be passed to this function by reference.
9. A function called printHighestPaid must find and output (cout) the full name, employee ID, company name, and total pay of the person who was paid the highest amount this statement. Call the function from main before exiting the program. NOTE: the employees vector needs to be passed to this function by reference. Example output:
Highest paid: Ryan Ward
Employee ID: 150
Employer: Douglas
Total Pay: $3281.00
10. A function called separateAndSave must write the payroll information to multiple text files - one for each company. Each file should be named after the company (e.g. Boeing.txt) and contain only the employees from that company. Within the file, the data should be formatted by selecting reasonable column widths for output. The float output should be truncated to 2 decimal places. The column widths do not have to match exactly. Simply pick a reasonable number of characters for each (20-30 for names, etc). The output should also have the total pay for each company. NOTE: both vectors need to be passed to this function by reference.
Intel.txt
Maria Brown 10 Intel $1667.25
Patricia Wright 80 Intel $1280.00
Olivia Walker 120 Intel $3149.22
Karen Hill 160 Intel $2673.00
Total $8769.47
Boeing.txt
Jeffrey Jackson 20 Boeing $1235.00
Michael Lee 70 Boeing $1136.00
Total $2371.00
Douglas.txt
Bernard Smith 30 Douglas $581.25
Kimberly Macias 50 Douglas $1820.00
Ryan Ward 150 Douglas $3281.00
Total $5682.25
Raytheon.txt
Matthew Davenport 40 Raytheon $2999.62
Amber Daniels 60 Raytheon $2770.12
James Miller 100 Raytheon $2539.12
Thomas Sanders 130 Raytheon $1934.62
Sophia Foster 140 Raytheon $1942.60
Total $12186.08
HealthTech.txt
Stanley Johnson 90 HealthTech $2097.62
Linda David 110 HealthTech $1460.00
Total $3557.62
Additional Notes:
No global variables are allowed
Do not change function/class/vector/file names or function declaration
You may only call the open file method to read the file one time in the program
pay.cpp
#include "person.h"
#include "person.cpp"
#include <vector>
#include <string>
#include <fstream>
#include "iostream"
#include <iomanip>
using namespace std;
void readData(vector<Person> &Empvect);
void getCompanies(vector<Person>
&Empvect,vector<string> &compVect);
void PrintHighestPaid(vector<Person> &Empvect);
void seperateAndSave(vector<Person>
&Empvect,vector<string> &compVect);
int main()
{
vector<Person> employees;
vector<string> companyNames;
readData(employees);
getCompanies(employees,companyNames);
PrintHighestPaid(employees);
seperateAndSave(employees, companyNames);
}
void readData(vector<Person> &Empvect)
{
Person s;
fstream myfile;
myfile.open("input.txt");
string Fname;
string Lname;
int id;
string compName;
float hours;
float payrate;
if (!myfile.is_open())
{
cout << "File is not found" << endl;
}
else
{
while (!myfile.eof())
{
myfile >> Fname >> Lname >> id >>
compName >> hours >> payrate;
s.setFirstName(Fname); s.setLastName(Lname);
s.setEmployeeId(id);
s.setCompanyName(compName);s.setHoursWorked(hours);
s.setPayRate(payrate);
Empvect.push_back(s);
}
myfile.close();
}
}
void getCompanies(vector<Person>
&Empvect,vector<string> &compVect)
{
for (unsigned int i = 0; i < Empvect.size(); i++)
{
compVect.push_back(Empvect.at(i).getCompanyName());
}
}
void PrintHighestPaid(vector<Person> &Empvect)
{
int counter = 0;
int id;
string coName;
string empName;
float total;
cout << showpoint;
for (unsigned int i = 0; i < Empvect.size(); i++)
{
if (counter < Empvect.at(i).totalPay())
{
counter = Empvect.at(i).totalPay();
id = Empvect.at(i).getEmployeeId();
coName = Empvect.at(i).getCompanyName();
empName = Empvect.at(i).fullName();
total = Empvect.at(i).totalPay();
}
}
cout << "Highest paid: " << empName <<
endl;
cout << "Employee ID: " << id << endl;
cout << "Employer: " << coName << endl;
cout << "Total Pay: $" << total <<endl;
}
void seperateAndSave(vector<Person>
&Empvect,vector<string> &compVect){
string name;
for (unsigned int i = 0; i < compVect.size();i++)
{
float totalpay = 0;
name = compVect.at(i);
ofstream outputfile (name+".txt");
ifstream inputfile;
inputfile.open(name+".txt");
outputfile <<"Company: "<< name <<
".txt"<< endl;
outputfile <<
"___________________________________________________________________"
<< endl;
for (unsigned int i = 0; i < Empvect.size()-1; i++)
{
if (name == Empvect.at(i).getCompanyName())
{
outputfile << showpoint;
outputfile << setw(20)<< left <<
Empvect.at(i).fullName() << setw(20) << right <<
Empvect.at(i).getEmployeeId() << right << setw(20)
<< Empvect.at(i).getCompanyName() << right <<
setw(20) << "$" << Empvect.at(i).totalPay() <<
endl;
totalpay += Empvect.at(i).totalPay();
}
}
outputfile << "\nTotal Pay: $"<< totalpay;
outputfile.close();
}
}
person.cpp
#include "person.h"
#include <string>
Person::Person()
{
}
void Person::setFirstName(string fName)
{
firstName = fName;
}
std::string Person::getFirstName() {
return firstName;
}
void Person::setLastName(string lName)
{
lastName = lName;
}
string Person::getLastName()
{
return lastName;
}
void Person::setEmployeeId(int id)
{
employeeID = id;
}
int Person::getEmployeeId()
{
return employeeID;
}
void Person::setCompanyName(string coName)
{
companyName = coName;
}
std::string Person::getCompanyName()
{
return companyName;
}
void Person::setPayRate(float rate)
{
payRate = rate;
}
float Person::getPayRate()
{
return payRate;
}
void Person::setHoursWorked(float hours)
{
hoursWorked = hours;
}
float Person::getHoursWorked()
{
return hoursWorked;
}
float Person::totalPay()
{
return hoursWorked * payRate;
}
std::string Person::fullName()
{
return firstName + " " +lastName;
}
person.h
//begin person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
using namespace std;
class Person
{
private:
string firstName;
string lastName;
int employeeID;
string companyName;
float hoursWorked;
float payRate;
public:
Person();
void setFirstName(string
fName);
string getFirstName();
void setLastName(string
lName);
string getLastName();
void setEmployeeId(int id);
int getEmployeeId();
void setCompanyName(string
coName);
string getCompanyName();
void setPayRate(float rate);
float getPayRate();
void setHoursWorked(float
hours);
float getHoursWorked();
float totalPay();
string fullName();
};
#endif // end person.h
Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee...
Using struct.c, as a starting point, implement an application that creates a database of employee personal records. Your implementation should follow these guidelines: the definition of the structure PERSON should be provided in an h-file called person.h that you need to create in the src sub-directory, for the content, refer to the lecture notes, typdef should be used for referencing the PERSON structure, an array employees[] should be declared in the main C file (that is struct.c), a new C...
2. In the following program an employee of a company is represented by an object of type employee consisting of a name, employee id, employee salary and the workday starting time. The starting time is a class time 24 object. Implement the class employee. Declaration of Employee and Time Classes /* File : employeetime.h Hlustrates composition of classes */ #ifndef EMPLOYEETIME.H #define EMPLOYEETIME.H #include <iostream> #include <string> using namespace std; class time 24 { private : int hour; int minute...
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...
If the employee is a supervisor calculate her paycheck as her yearly salary / 52 (weekly pay) If the employee is not a supervisor and she worked 40 hours or less calculate her paycheck as her hourly wage * hours worked (regular pay) If the employee is not a supervisor and worked more than 40 hours calculate her paycheck as her (hourly wage * 40 ) + (1 ½ times here hourly wage * her hours worked over 40) (overtime...
4. Create a Business class. This class should store an array of Employee objects. Add a method to add employees to the Business, similar to addFoodItem in the Meal class. Add two more methods for the Business class: getHighestPaid(), which returns the Employee who has been paid the most in total, and getHighestTaxed(), which returns the Employee who has been taxed the most in total. Note: you do not need to handle the case of ties. These are all the...
C++ Program 2 Consider a class Employee with data members: age (an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary: public: Employee; // default constructor: age=0, id=0, and salary=0 void setAge(int x); // let age = x void setId(int x); // let id = x void setSalary(float x); // salary = x int getAge(); // return age int getId; // return id float...
Write a complete C++ program that defines the following class: Class Salesperson { public: Salesperson( ); // constructor ~Salesperson( ); // destructor Salesperson(double q1, double q2, double q3, double q4); // constructor void getsales( ); // Function to get 4 sales figures from user void setsales( int quarter, double sales); // Function to set 1 of 4 quarterly sales // figure. This function will be called // from function getsales ( ) every time a // user enters a sales...
In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...
using c++ output format should look this but use employee id,hours worked and pay rate and the total should be calculated. for example employee id:1234 hours work:29.3 pay rate:16.25 administrative, office and field should be outputted as well too. Using a structure, and creating three structure variables, write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their...