It's me again

Hi everyone, my assignment for this week has me stumped once again. I have several questions and problems with my code that I could really use some help with. Not looking for the answers, an explanation using my code or code in general would be great so I can learn where I am going wrong.

The main issue I'm having is being able to use my Benefits class correctly. With it being protected I can't access it the way I have it yet. Another is how to properly inherit the employee class variables to the other classes.

This program is supposed to create at least one Employee, Hourly, and Salaried employee.

For each object created, display the number of employees created.

For each object created, write statements to exercise each of the public methods listed in the Class diagram.

For each object created, invoke the object's displayEmployee() method to display the employee's information.

As you can see, I made seperate .h and .cpp files for all the classes, thought it would make it easier, not sure if I accomplished that.

Any suggestions? Thanks in advance.

Main CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include "Hourly.h"
#include "Salaried.h"
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------------------------------
// Main Function
int main()
{
	// Call DisplayApplicationInformation and DisplayDivider Proceedures
	DislayApplicationInformation();
	DisplayDivider("Employee 1");

	// Construct Employee1 Object and Benefit Object
	Employee employee1;  
	char gender;
	string tempString;
	Benefit benefit;
	double lifeInsurance;
	int vacation;

	// Getting Employee1 Data
	employee1.setFirstName(GetInput("First Name "));
	employee1.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee1.setGender(gender);  
	employee1.setDependents(GetInput("Dependents "));
	employee1.setAnnualSalary(GetInput("Annual Salary "));
	
	// Get Employee1 Benefit Data
	//employee1.benefit.setHealthInsurance(GetInput("Health Insurance "));
	tempString = GetInput("Life Insurance");
	lifeInsurance = atof(tempString.c_str());
	//employee1.benefit.setLifeInsurance(lifeInsurance);
	tempString = GetInput("Vacation ");
	vacation = atoi(tempString.c_str());
	//employee1.benefit.setVacation(vacation);

	// Calling DisplayDivider2 and DisplayEmployee Proceedures for Employee 1
	DisplayDivider2("Employee Information"); 
	employee1.displayEmployee(); //Display Employee1 Data
	cout << endl;	

	// Construct Hourly Employee and Benefit1 Objects
	Benefit hourlyBenefit;
	Hourly employee2;
	double wage;
	double hours;
	string category;
	
	// Get Hourly Employee Data
	employee2.setFirstName(GetInput("First Name "));
	employee2.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee2.setGender(gender);  
	employee2.setDependents(GetInput("Dependents "));
	employee2.setCategory(GetInput("Category "));
	tempString = GetInput("Wage "); 
	wage = atoi(tempString.c_str());
	employee2.setWage(wage);
	tempString = GetInput("Hours: "); 
	hours = atoi(tempString.c_str());
	employee2.setHours(hours);

	// Get Hourly Employee Benefit Data
	//employee2.hourlyBenefit.setHealthInsurance(GetInput("Health Insurance "));
	tempString = GetInput("Life Insurance");
	lifeInsurance = atof(tempString.c_str());
	//employee2.hourlyBenefit.setLifeInsurance(lifeInsurance);
	tempString = GetInput("Vacation ");
	vacation = atoi(tempString.c_str());
	//employee2.hourlyBenefit.setVacation(vacation);

	// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 2
	DisplayDivider("Employee 2");
	DisplayDivider2("Employee Information");
	employee2.displayEmployee(); // 

	// Construct Salaried Employee and Benefit2 Objects
	Benefit SalariedBenefit;
	Salaried employee3;
	int managementLevel;

	// Get Salaried Employee Data
	employee3.setFirstName(GetInput("First Name "));
	employee3.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee3.setGender(gender);  
	employee3.setDependents(GetInput("Dependents "));
	employee3.setAnnualSalary(GetInput("Annual Salary "));
	tempString = GetInput("Management Level ");
	managementLevel = atoi(tempString.c_str());
	employee3.setManagementLevel(managementLevel);
	
	// Get Salaried Employee Benefit Data
	//employee3.salariedBenefit.setHealthInsurance(GetInput("Health Insurance "));
	tempString = GetInput("Life Insurance");
	lifeInsurance = atof(tempString.c_str());
	//employee3.salariedBenefit.setLifeInsurance(lifeInsurance);
	tempString = GetInput("Vacation ");
	vacation = atoi(tempString.c_str());
	//employee3.salariedBenefit.setVacation(vacation);

	// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 3
	DisplayDivider("Employee 3");
	DisplayDivider2("Employee Information");
	employee3.displayEmployee();

	// Call TerminateApplication Proceedure
	TerminateApplication();

	return 0;
}
//----------------------------------------------------------------------------------------------
// DisplayApplicationInformation Procedure
void DislayApplicationInformation()
{
	// Display Program Header
	cout << "Welcome to your first Object Oriented Program\n";
	cout << "Employee Class CIS247C, Week 4 Lab\n";
	cout << "Name: Jim Stevens\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider Prodedure
void DisplayDivider(string outputTitle)
{
	// Display Divider with Output Title
	cout << "************************" << outputTitle <<"************************\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider2 Prodedure
void DisplayDivider2(string outputTitle)
{
	// Display Divider with Output Title
	cout << "\n" << outputTitle << endl;
	cout << "----------------------------------------------------------------\n";
}
//----------------------------------------------------------------------------------------------
// GetInput Function
string GetInput (string inputType)
{ 
	// Declare Function Varaible
	string input;
	// Prompt User for Input
	cout<<"Please enter your "<< inputType <<": ";
	getline(cin, input);
	return input;
}
//----------------------------------------------------------------------------------------------
// TerminateApplication Procedure
void TerminateApplication()
{
	// Display Termination Message
	cout << "\nThank you for using the Employee Class program\n";
}
//---------------------------------------------------------------------------------------------- 


Employee.h File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Preprocessor Directives
#pragma once
#include "Benefit.h"
#include <string>
using namespace std;
//---------------------------------------------------------------------------------------
// Declare Prototypes
void DislayApplicationInformation();
void DisplayDivider(string);
void DisplayDivider2(string);
string GetInput (string);
void TerminateApplication();
//---------------------------------------------------------------------------------------
/* Define iEmployee Class
class iEmployee
{
public:
	virtual double calculatePay()= 0;
};*/
// Define Employee Class
class Employee
{
protected:
	string firstName;
	string lastName;
	char gender;
	int dependents;
	double annualSalary;
	Benefit benefit;

private:
	// Declare Data Members
	static int numEmployees;

public:
	// Constructors and Destructor
	Employee(void);
	Employee(string, string, char, int, double, Benefit);
	~Employee(void);

	// Methods to Access Attributes
	double calculatePay();
	void displayEmployee();

	// Getters and Setters
	string Employee::getFirstName();
	void Employee::setFirstName(string);
	void Employee::setLastName(string);
	string Employee::getLastName();
	char Employee::getGender();
	void Employee::setGender(char);
	int Employee::getDependents();
	void Employee::setDependents(int);
	void Employee::setDependents(string);  
	double Employee::getAnnualSalary();
	void Employee::setAnnualSalary(double);
	void Employee::setAnnualSalary(string);  
	static int getNumEmployees();
};


Employee.CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include <iostream>
#include <iomanip>
//----------------------------------------------------------------------------------------------
// Declare Variables
const double minSalary = 50000;
const double maxSalary = 250000;
const int maxDepenents = 10;
const int minDependents = 0;
const char defaultGender= 'U';
const int numberOfWeeks = 52;
int Employee::numEmployees = 0;
//----------------------------------------------------------------------------------------------
// Default Employee Constructor
Employee::Employee() : firstName("not given"), lastName("not given"), gender('U'), dependents(0), annualSalary(20000.0)
{
	numEmployees++;
}
//----------------------------------------------------------------------------------------------
// Multi-Arg Employee Constructor
Employee::Employee(string first, string last, char gen, int dep, double salary, Benefit ben) :

	firstName(first),
	lastName(last),
	gender(gen),
	dependents(dep),
	annualSalary(salary),
	benefit(ben)
{
	numEmployees++;
}
//----------------------------------------------------------------------------------------------
// Employee Deconstructor
Employee::~Employee()
{
	numEmployees--;
}
//----------------------------------------------------------------------------------------------
// Define CalculatePay Function
double Employee::calculatePay()
{
	return (annualSalary/numberOfWeeks);
}
//----------------------------------------------------------------------------------------------
// DisplayEmployee Function
void Employee::displayEmployee()
{
	cout << "Employee Name:\t\t" << firstName << " " << lastName << "\n";
	cout << "Employee Gender:\t" << gender << "\n";
	cout << "Employee Dependents:\t" << dependents << "\n";
	cout << "Employee Annual Salary:\t$" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
	cout << "Employee Weekly Pay:\t$" << setprecision(2) << showpoint << fixed << calculatePay() << "\n";
	benefit.displayBenefits();
	cout << "--- Number of Employee Objects Created ----\n";
	cout << "Number of employees: " << Employee::getNumEmployees() << "\n"; 
}
//----------------------------------------------------------------------------------------------
// Define GetFirstName and SetFirstName
string Employee::getFirstName()
{
	return firstName;
}
void Employee::setFirstName(string name)
{
	firstName = name;
}

string Employee::getLastName()
{
	return lastName;
}
void Employee::setLastName(string name)
{
	lastName = name;
}
//----------------------------------------------------------------------------------------------
// Define GetGender and SetGender
char Employee::getGender()
{
	return gender;
}

void Employee::setGender(char gen)
{
	switch (gen)
	{
	case 'f':case 'F': case 'M':case 'm':
		gender = gen;
		break;
	default:
		gender = defaultGender;
	}
}
//----------------------------------------------------------------------------------------------
// Define GetDependents and both SetDependents (overloaded)
int Employee::getDependents()
{
	return dependents;
}

void Employee::setDependents(int dep)
{
	if (dep >= minDependents && dep <= maxDepenents)
	{
		dependents = dep;
	}
	else if (dep < minDependents)
	{
		dep = minDependents;
	}
	else
	{
		dependents = maxDepenents;
	}
}

void Employee::setDependents(string dep)
{
	Employee::setDependents(atoi(dep.c_str()));
}
//----------------------------------------------------------------------------------------------
// Define GetAnnualSalary and both SetAnnualSalary (overloaded)
double Employee::getAnnualSalary()
{
	return annualSalary;
}
void Employee::setAnnualSalary(double salary)
{
	if (salary >= minSalary && salary <= maxSalary)
	{
		annualSalary = salary;
	}
	else if (salary < minSalary)
	{
		annualSalary = minSalary;
	}
	else
	{
		annualSalary = maxSalary;
	}
}

void Employee::setAnnualSalary(string sal)
{
	Employee::setAnnualSalary( atof(sal.c_str())); 
}
//----------------------------------------------------------------------------------------------
// Define GetNumEmployees
int Employee::getNumEmployees()
{
	return Employee::numEmployees; 

}
//---------------------------------------------------------------------------------------------- 


Benefit.h File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Preprocessor Directives
#pragma once
#include <string>
using namespace std;
//----------------------------------------------------------------------------------------------
// Define Benefit Class
class Benefit
{
public:
	// Constructors and Destructor
	Benefit();
	Benefit(string, double, int);
	~Benefit();

	// Methods to Access Attributes
	void displayBenefits();

	// Getters and Setters
	string Benefit::getHealthInsurance();
	void Benefit::setHealthInsurance(string);
	double Benefit::getLifeInsurance();
	void Benefit::setLifeInsurance(double);
	int Benefit::getVacation();
	void Benefit::setVacation(int);

private:
	// Declare Data Members
	string healthInsurance;
	double lifeInsurance;
	int vacation;

};



Benefit CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include "Benefit.h"
#include <iostream>
#include <iomanip>
//----------------------------------------------------------------------------------------------
// Default Benefit Constructor
Benefit::Benefit() : healthInsurance("not provided"), lifeInsurance(0.0), vacation(14)
{	
}
//----------------------------------------------------------------------------------------------
// Multi-Arg Benefit Constructor
Benefit::Benefit(string health, double life, int vac) :
	healthInsurance(health),
	lifeInsurance(life),
	vacation(vac)
{
}
//----------------------------------------------------------------------------------------------
// Benefit Deconstructor
Benefit::~Benefit()
{
}
//----------------------------------------------------------------------------------------------
// DisplayBenefits Function  
void Benefit::displayBenefits()
{
	cout << "\nBenefit Information\n";
	cout << "----------------------------------------------------------------\n";
	cout << "Health Insurance: \t" << healthInsurance << "\n";
	cout << "Life Insurance: \t" << setprecision(2) << showpoint << lifeInsurance << "\n";
	cout << "Vacation: \t\t" << vacation << " days\n";
}
//----------------------------------------------------------------------------------------------
// Define GetHealthInsurance and SetHealthInsurance
string Benefit::getHealthInsurance()
{
	return healthInsurance;
}

void Benefit::setHealthInsurance(string newHealthInsurance)
{
	healthInsurance = newHealthInsurance;
}
//----------------------------------------------------------------------------------------------
// Define GetLifeInsurance and SetLifeInsurance
double Benefit::getLifeInsurance()
{
	return lifeInsurance;
}

void Benefit::setLifeInsurance(double newLifeInsurance)
{
	lifeInsurance = newLifeInsurance;
}
//----------------------------------------------------------------------------------------------
// Define GetVacation and SetVacation
int Benefit::getVacation()
{
	return vacation;
}

void Benefit::setVacation(int newVacation)
{
	vacation = newVacation;
}


Salaried.h File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Preprocessor Directives
#pragma once
#include "employee.h"
class Salaried :
	public Employee
{
public:
	Salaried(void);
	~Salaried(void);
private:
	int minManagementLevel;
	int maxManagementLevel;
	double bonusPercent;
	int managementLevel;
public:
	Salaried(string firstName, string lastName, char gender, int dependent, double salary, Benefit benefit, int managementLevel);
	Salaried(double salary, int managementLevel);
	double calculatePay(void);
	void displayEmployee(void);

	//Getters and Setters
	int Salaried::getManagementLevel();
	void Salaried::setManagementLevel(int);
};


Salaried CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "stdafx.h"
#include "Salaried.h"

#include <iostream>

	

Salaried::Salaried()
{	
	const int minManagementLevel = 0;
	const int maxManagementLevel = 3;
	const double bonusPercent = 0.10;
	managementLevel = 0;
}


Salaried::~Salaried(void)
{
}


Salaried::Salaried(string firstName, string lastName, char gender, int dependent, double salary, Benefit benefit, int managementLevel)
{
}


Salaried::Salaried(double salary, int managementLevel)
{
}


double Salaried::calculatePay(void)
{
	return Employee::calculatePay()*(1+(managementLevel*bonusPercent));
}


void Salaried::displayEmployee(void)
{
  Employee::displayEmployee();
  cout<<"Salaried Employee\n";
  cout<<"Management Level:\t\t" << managementLevel << "\n";
}

//----------------------------------------------------------------------------------------------
int Salaried::getManagementLevel()
{
	return managementLevel;
}


void Salaried::setManagementLevel(int managementLevel)
{
if (managementLevel >= minManagementLevel && managementLevel <= maxManagementLevel)
	{
		managementLevel = managementLevel;
	}
	else
	{
		cout << "Invalid Input" << "\n";
	}
}
//---------------------------------------------------------------------------------------------- 


Hourly.h File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include "employee.h"
class Hourly :
	public Employee
{
public:
	Hourly(void);
	~Hourly(void);
private:
	double minWage;
	double maxWage;
	double minHours;
	double maxHours;
	double wage;
	double hours;
	string category;
public:
	Hourly(double wage, double hours, string category);
	Hourly(string firstName, string lastName, char gender, int dependents, double wage, double hours, Benefit benefit, string category);
	double calculatePay(void);
	void displayEmployee(void);
	double Hourly::getWage();
	void Hourly::setWage(double);
	double Hourly::getHours();
	void Hourly::setHours(double);
	string Hourly::getCategory();
	void Hourly::setCategory(string);
	void Hourly::setAnnualSalary(double);
};


Hourly CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "stdafx.h"
#include "Hourly.h"
#include <iostream>

using namespace std;

Hourly::Hourly(void)
{
	const double minWage = 10.0;
	const double maxWage = 75.0;
	const double minHours = 0.0;
	const double maxHours = 50.0;
	wage = 0.0;
	hours = 0.0;
}


Hourly::~Hourly(void)
{
}


Hourly::Hourly(double wage, double hours, string category)
{
}


Hourly::Hourly(string firstName, string lastName, char gender, int dependents, double wage, double hours, Benefit benefit, string category)
{
}

double Hourly::calculatePay(void)
{
	return (wage * hours);
}

void Hourly::displayEmployee(void)
{
	Hourly::setAnnualSalary(annualSalary);
	Employee::displayEmployee();
	cout<<"Hourly Employee\n";
	cout<<"Category:\t\t" << category << "\n";
	cout<<"Wage:\t\t\t" << showpoint << fixed << wage  << "\n";
	cout<<"Hours:\t\t\t" << showpoint << fixed << hours << "\n";
}

	double Hourly::getWage()
	{
		return wage;
	}
	void Hourly::setWage(double wage)
	{
		if(wage >= minWage && wage <+ maxWage)
	{
		this->wage = wage;
	}
	else if(wage < minWage)
	{
		this->wage = minWage;
	}
	else
	{
		this->wage = maxWage;
	}
	}
	double Hourly::getHours()
	{
		return hours;
	}
	void Hourly::setHours(double hours)
	{
		if (hours > minHours && hours < maxHours)
	{
		this->hours = hours;
	}
	else if (hours <= minHours)
	{
		this->hours = minHours;
	}
	else
	{
		this->hours = maxHours;
	}
	}

	string Hourly::getCategory()
	{
		return category;
	}
	void Hourly::setCategory(string category)
	{
	if (category.compare("temporary")==0)
	{
		this->category = category;
	}
	else if (category.compare("part time")==0)
	{
		this->category = category;
	}
	else if (category.compare("full time")==0)
	{
		this->category = category;
	}
	else
	{
		this->category = "Unknown";
	}
	}

	void Hourly::setAnnualSalary(double salary)
	{
		salary = calculatePay() * 50;
		this->annualSalary = salary; 
	}



OK, got the benefits working. Now I am having trouble with:

For each object created, write statements to exercise each of the public methods listed in the Class diagram.

For each object created, invoke the object's displayEmployee() method to display the employee's information.

After further reading, the hourly employee does not get the wages/hours/category input in, amd suppposed to use the Hourly::Hourly(double wage, double hours, string category) constructor. Same with the salaried employee, supposed to use the Salaried::Salaried(double salary, int managementLevel). Here are the files that have been changed from what is listed above.

Main CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include "Hourly.h"
#include "Salaried.h"
#include <iostream>
#include <string>
using namespace std;
//----------------------------------------------------------------------------------------------
// Main Function
int main()
{
	// Call DisplayApplicationInformation and DisplayDivider Proceedures
	DislayApplicationInformation();
	DisplayDivider("Employee 1");

	// Construct Employee1 Object and Benefit Object
	Employee employee1;  
	char gender;
	string tempString;
	Benefit benefit;
	//double lifeInsurance;
	//int vacation;

	// Getting Employee1 Data
	employee1.setFirstName(GetInput("First Name "));
	employee1.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee1.setGender(gender);  
	employee1.setDependents(GetInput("Dependents "));
	employee1.setAnnualSalary(GetInput("Annual Salary "));
	employee1.setBenefit(benefit);
	
	// Calling DisplayDivider2 and DisplayEmployee Proceedures for Employee 1
	DisplayDivider2("Employee Information"); 
	employee1.displayEmployee(); //Display Employee1 Data
	cout << endl;	

	// Construct Hourly Employee and Benefit1 Objects
	Benefit hourlyBenefit;
	Hourly employee2;
	
	// Get Hourly Employee Data
	employee2.setFirstName(GetInput("First Name "));
	employee2.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee2.setGender(gender);  
	employee2.setDependents(GetInput("Dependents "));
	employee2.setBenefit(benefit);
	

	// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 2
	DisplayDivider("Employee 2");
	DisplayDivider2("Employee Information");
	employee2.displayEmployee();

	// Construct Salaried Employee and Benefit2 Objects
	Benefit SalariedBenefit;
	Salaried employee3;
	int managementLevel;

	// Get Salaried Employee Data
	employee3.setFirstName(GetInput("First Name "));
	employee3.setLastName(GetInput("Last Name "));
	tempString = GetInput("Gender ");
	gender = tempString.at(0);
	employee3.setGender(gender);  
	employee3.setDependents(GetInput("Dependents "));
	employee3.setAnnualSalary(GetInput("Annual Salary "));
	tempString = GetInput("Management Level ");
	managementLevel = atoi(tempString.c_str());
	employee3.setManagementLevel(managementLevel);
	employee3.setBenefit(benefit);
	

	// Calling DisplayDivider, DisplayDivider2 and DisplayEmployee Proceedures for Employee 3
	DisplayDivider("Employee 3");
	DisplayDivider2("Employee Information");
	employee3.displayEmployee();

	// Call TerminateApplication Proceedure
	TerminateApplication();

	return 0;
}
//----------------------------------------------------------------------------------------------
// DisplayApplicationInformation Procedure
void DislayApplicationInformation()
{
	// Display Program Header
	cout << "Welcome to your first Object Oriented Program\n";
	cout << "Employee Class CIS247C, Week 4 Lab\n";
	cout << "Name: Jim Stevens\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider Prodedure
void DisplayDivider(string outputTitle)
{
	// Display Divider with Output Title
	cout << "************************" << outputTitle <<"************************\n";
}
//----------------------------------------------------------------------------------------------
// DisplayDivider2 Prodedure
void DisplayDivider2(string outputTitle)
{
	// Display Divider with Output Title
	cout << "\n" << outputTitle << endl;
	cout << "----------------------------------------------------------------\n";
}
//----------------------------------------------------------------------------------------------
// GetInput Function
string GetInput (string inputType)
{ 
	// Declare Function Varaible
	string input;
	// Prompt User for Input
	cout<<"Please enter your "<< inputType <<": ";
	getline(cin, input);
	return input;
}
//----------------------------------------------------------------------------------------------
// TerminateApplication Procedure
void TerminateApplication()
{
	// Display Termination Message
	cout << "\nThank you for using the Employee Class program\n";
}
//---------------------------------------------------------------------------------------------- 



Employee CPP File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Preprocessor Directives
#include "stdafx.h"
#include "Employee.h"
#include <iostream>
#include <iomanip>
//----------------------------------------------------------------------------------------------
// Declare Variables
const double minSalary = 50000;
const double maxSalary = 250000;
const int maxDepenents = 10;
const int minDependents = 0;
const char defaultGender= 'U';
const int numberOfWeeks = 52;
int Employee::numEmployees = 0;
//----------------------------------------------------------------------------------------------
// Default Employee Constructor
Employee::Employee() : firstName("not given"), lastName("not given"), gender('U'), dependents(0), annualSalary(20000.0)
{
	numEmployees++;
}
//----------------------------------------------------------------------------------------------
// Multi-Arg Employee Constructor
Employee::Employee(string first, string last, char gen, int dep, double salary, Benefit ben) :

	firstName(first),
	lastName(last),
	gender(gen),
	dependents(dep),
	annualSalary(salary),
	benefit(ben)
{
	numEmployees++;
}
//----------------------------------------------------------------------------------------------
// Employee Deconstructor
Employee::~Employee()
{
	numEmployees--;
}
//----------------------------------------------------------------------------------------------
// Define CalculatePay Function
double Employee::calculatePay()
{
	return (annualSalary/numberOfWeeks);
}
//----------------------------------------------------------------------------------------------
// DisplayEmployee Function
void Employee::displayEmployee()
{
	cout << "Employee Name:\t\t" << firstName << " " << lastName << "\n";
	cout << "Employee Gender:\t" << gender << "\n";
	cout << "Employee Dependents:\t" << dependents << "\n";
	cout << "Employee Annual Salary:\t$" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
	cout << "Employee Weekly Pay:\t$" << setprecision(2) << showpoint << fixed << calculatePay() << "\n";
	benefit.displayBenefits();
	cout << "--- Number of Employee Objects Created ----\n";
	cout << "Number of employees: " << Employee::getNumEmployees() << "\n"; 
}
//----------------------------------------------------------------------------------------------
// Define GetFirstName and SetFirstName
string Employee::getFirstName()
{
	return firstName;
}
void Employee::setFirstName(string name)
{
	firstName = name;
}

string Employee::getLastName()
{
	return lastName;
}
void Employee::setLastName(string name)
{
	lastName = name;
}
//----------------------------------------------------------------------------------------------
// Define GetGender and SetGender
char Employee::getGender()
{
	return gender;
}

void Employee::setGender(char gen)
{
	switch (gen)
	{
	case 'f':case 'F': case 'M':case 'm':
		gender = gen;
		break;
	default:
		gender = defaultGender;
	}
}
//----------------------------------------------------------------------------------------------
// Define GetDependents and both SetDependents (overloaded)
int Employee::getDependents()
{
	return dependents;
}

void Employee::setDependents(int dep)
{
	if (dep >= minDependents && dep <= maxDepenents)
	{
		dependents = dep;
	}
	else if (dep < minDependents)
	{
		dep = minDependents;
	}
	else
	{
		dependents = maxDepenents;
	}
}

void Employee::setDependents(string dep)
{
	Employee::setDependents(atoi(dep.c_str()));
}
//----------------------------------------------------------------------------------------------
// Define GetAnnualSalary and both SetAnnualSalary (overloaded)
double Employee::getAnnualSalary()
{
	return annualSalary;
}
void Employee::setAnnualSalary(double salary)
{
	if (salary >= minSalary && salary <= maxSalary)
	{
		annualSalary = salary;
	}
	else if (salary < minSalary)
	{
		annualSalary = minSalary;
	}
	else
	{
		annualSalary = maxSalary;
	}
}

void Employee::setAnnualSalary(string sal)
{
	Employee::setAnnualSalary( atof(sal.c_str())); 
}
//----------------------------------------------------------------------------------------------
// Define GetBenefit and SetBenefit
Benefit Employee::getBenefit()
{
	return benefit;
}

void Employee::setBenefit(Benefit)
{
	string tempString;
	double lifeInsurance;
	int vacation;
	benefit.setHealthInsurance(GetInput("Health Insurance "));
	tempString = GetInput("Life Insurance");
	lifeInsurance = atof(tempString.c_str());
	benefit.setLifeInsurance(lifeInsurance);
	tempString = GetInput("Vacation ");
	vacation = atoi(tempString.c_str());
	benefit.setVacation(vacation);
}


// Define GetNumEmployees
int Employee::getNumEmployees()
{
	return Employee::numEmployees; 

}
//---------------------------------------------------------------------------------------------- 
Topic archived. No new replies allowed.