Hello all,
I have put together an inventory program and having problems getting it to compile and run. I am at my wits end, with it. I'm not sure what it is that I'm missing. Any help would be greatly appreciated. Thanks in advance.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
#define MAX_EMPLOYEES 3 // we only want 3 in this exercise
//
//CLASS DECLARATION SECTION
//
class EmployeeClass
{
public:
// constructor/destructor
EmployeeClass();
~EmployeeClass();
// employee functions
int AddEmployee();
int DeleteEmployee();
// output functions
int PrintTimesheets();
int PrintSummary();
// member variables
int m_TotalEmployees;
private:
// member variable
struct _Employee
{
char Name[255];
float HoursWorked;
float HourlyWage;
float BasePay;
float OvertimeHours;
float OvertimePay;
float TotalPay;
} Employee[MAX_EMPLOYEES];
struct _Summary
{
float TotalEmployeeSalaries;
float TotalEmployeeHours;
float TotalOvertimeHours;
} Summary;
// calculation functions
int CalcPay(int);
};
// constructor / destructor functions
EmployeeClass::EmployeeClass(void)
{
m_TotalEmployees = 0;
}
EmployeeClass::~EmployeeClass(void)
{
}
int EmployeeClass::AddEmployee()
{
cout << "Enter the employee name = ";
cin >> Employee[m_TotalEmployees].Name;
cout << "Enter hours worked = ";
cin >> Employee[m_TotalEmployees].HoursWorked;
cout << "Enter his or her hourly rate = ";
cin >> Employee[m_TotalEmployees].HourlyWage;
cout << endl;
CalcPay(m_TotalEmployees);
m_TotalEmployees++;
return 0;
}
int EmployeeClass::DeleteEmployee()
{
return 0;
}
int EmployeeClass::CalcPay(int i)
{
if ( Employee[i].HoursWorked == 0 || Employee[i].HoursWorked < 0)
{
Employee[i].BasePay = 0;
Employee[i].OvertimeHours =0;
Employee[i].OvertimePay = 0;
Employee[i].TotalPay = 0;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + Employee[i].HoursWorked;
}
if ( Employee[i].HoursWorked <= 40 && Employee[i].HoursWorked > 0)
{
Employee[i].BasePay = Employee[i].HoursWorked * Employee[i].HourlyWage;
Employee[i].OvertimeHours =0;
Employee[i].OvertimePay = 0;
Employee[i].TotalPay = Employee[i].BasePay;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + Employee[i].HoursWorked;
}
if ( Employee[i].HoursWorked > 40)
{
Employee[i].BasePay = 40 * Employee[i].HourlyWage;
Employee[i].OvertimeHours = Employee[i].HoursWorked - 40;
Employee[i].OvertimePay = Employee[i].OvertimeHours * (Employee[i].HourlyWage * 1.5);
Employee[i].TotalPay = Employee[i].BasePay + Employee[i].OvertimePay;
Summary.TotalEmployeeHours = Summary.TotalEmployeeHours + (Employee[i].HoursWorked - 40);
}
Summary.TotalEmployeeSalaries = Summary.TotalEmployeeSalaries + Employee[i].TotalPay;
return 0;
}
int EmployeeClass::PrintTimesheets()
{
for (int i = 0; i < MAX_EMPLOYEES; i++)
{
cout << "Employee Name ............. = " << Employee[i].Name << endl;
cout << "Base Pay .................. = " << Employee[i].BasePay << endl;
cout << "Hours in Overtime ......... = " ;
if (Employee[i].HoursWorked < 40)
cout << 0 << endl;
else
cout << (Employee[i].HoursWorked - 40) << endl;
cout << "Overtime Pay Amount........ = " << Employee[i].OvertimePay << endl;
cout << "Total Pay ................. = " << Employee[i].TotalPay << endl;
cout << endl;
}
return 0;
}
int EmployeeClass::PrintSummary()
{
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% EMPLOYEE SUMMARY DATA%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%% Total Employee Salaries ..... = " << Summary.TotalEmployeeSalaries << endl;
cout << "%%%% Total Employee Hours ........ = " << Summary.TotalEmployeeHours << endl;
cout << "%%%% Total Overtime Hours......... = " << Summary.TotalOvertimeHours << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" << endl;
cout << endl;
return 0;
}
int main()
{
system("cls");
cout << "\nWelcome to the Employee Pay Center\n\n" ;
// global
EmployeeClass ec;
// add employees
while (ec.m_TotalEmployees < MAX_EMPLOYEES)
{
ec.AddEmployee();
}
// print employee results
ec.PrintTimesheets();
// print summary
ec.PrintSummary();
return 0;
}