Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.
Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.
Can anyone give me a hand with this?
Thanks.
Benefit.h
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
static const double Min_Life = 0;
static const double Max_Life = 1000000;
static const int Min_Vacation = 0;
static const int Max_Vacation = 365;
class Benefit
{
private:
string HealthInsurance;
double LifeInsurance;
int Vacation;
public:
Benefit();
Benefit(string health, double life, int vac);
void displayBenefits();
string getHealthInsurance();
void setHealthInsurance(string health);
double getLifeInsurance();
void setLifeInsurance(double life);
int getVacation();
void setVacation(int vac);
};
Employee.h
Code:
#include "Benefit.h"
const int Max_Depend = 10;
const int Min_Depend = 0;
const double Max_Salary = 250000;
const double Min_Salary = 20000;
const char Default_Gender = 'U';
class Employee
{
protected:
string FirstName, LastName;
char Gender;
int Dependent;
double AnnualSalary;
Benefit benefit;
private:
static int numEmployees;
public:
Employee();
Employee(string fName, string lName, char gen, int depend, double salary, Benefit ben);
double calculatePay();
void displayEmployee();
string getFirstName();
void setFirstName(string fName);
string getLastName();
void setLastName(string lName);
char getGender();
void setGender(char gen);
int getDependent();
void setDependent(int depend);
void setDependent(string depend);
double getAnnualSalary();
void setAnnualSalary(double salary);
void setAnnualSalary(string salary);
static int getnumEmployees();
Benefit getBenefit();
void setBenefit(Benefit ben);
};
EmployeeMain.cpp
Code:
#include "Hourly.h"
#include "Salaried.h"
void DisplayApplicationInformation();
void DisplayDivider(string);
string GetInput(string);
void TerminateApplication();
int Employee::numEmployees = 0;
int main()
{
DisplayApplicationInformation();
string input = "";
DisplayDivider(" EMPLOYEE #1 ");
cout << endl;
Benefit benefit1("Atena", 250000, 45);
Employee emp1("John","Jones",'M', 3, 100000, benefit1);
emp1.Employee::displayEmployee();
DisplayDivider("Number of Employees");
cout << "Number of employees: " << Employee::getnumEmployees() << endl;
cout << endl;
DisplayDivider(" EMPLOYEE #2 ");
cout << endl;
Benefit benefit2("Blue Cross", 250000, 90);
Salaried emp2("Mary", "Smith", 'F', 4, 50000, benefit2, 2);
emp2.Salaried::displayEmployee();
DisplayDivider("Number of Employees");
cout << "Number of employees: " << Employee::getnumEmployees() << endl;
cout << endl;
DisplayDivider(" EMPLOYEE #3 ");
cout << endl;
Benefit benefit3("Cigna", 500000, 60);
Hourly emp3("Tom", "Jones", 'M', 5, 25, 40, benefit3, "FT");
emp3.Hourly::displayEmployee();
DisplayDivider("Number of Employees");
cout << "Number of employees: " << Employee::getnumEmployees() << endl;
cout << endl;
TerminateApplication();
system("pause");
return 0;
}
void DisplayApplicationInformation()
{
cout << endl;
cout << "Welcome to the Employee Class Program" << endl;
cout << "CIS247C, Week5 Lab" << endl;
cout << "Developer: John Worley" << endl;
cout << endl;
}
void DisplayDivider(string outputTitle)
{
cout << setw(12) << outputTitle << setw(12) << endl;
cout << "-----------------------" << endl;
}
string GetInput(string input) //general input function; takes input as string
{
cout << "Enter " << input << ": "; // no endl, in order to allow input on same line
getline(cin, input);
return input;
}
void TerminateApplication() // terminate program message
{
cout << "Thank you for using the Employee class program" << endl;
cout << "Program terminating" << endl;
cout << "Good-Bye" << endl;
cout << endl;
}