Errors for my programming class.

So I keep getting error LNK2005 in my program and there are these requirements for this program that are already coded. I can't get it to work and I have to separate it into different parts.

Create class Salaried that is derived from Employee.
Create class Hourly that is derived from Employee.
Override base class calculatePay() method.
Override displayEmployee() method.

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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
BENEFITS.H

#include <iostream>
#include <string>
using namespace std;
class Benefit {
public:
Benefit();
Benefit(string, double, int);
void displayBenefits();
string getHealthInsurance();
void setHealthInsurance(string);
double getLifeInsurance();
void setLifeInsurance(double);
int getVacation();
void setVacation(int);
private:
string healthInsurance;
double lifeInsurance;
int vacation;
};

EMPLOYEE.H

#include <iostream>
#include <string>
using namespace std;
class Employee {
public:
Employee();
Employee(string, string, char, int, double);
void displayEmployee();
string getFirstName();
void setFirstName(string);
string getLastName();
void setLastName(string);
char getGender();
void setGender(char);
int getDependents();
void setDependents(int);
double getAnnualSalary();
void setAnnualSalary(double);
void setAnnualSalary(string);
static int getNumEmployees();
void setDependents(string);
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
static int numEmployee;
virtual double calculatePay();
};

HOURLY.H

#pragma once
#include "Employee.h"
class Hourly :
	public Employee
{
public:
	Hourly(void);
	 class Hourly : Employee
{
//Constant values for minimum, maximum wage and hours
private const double MIN_WAGE = 10;
private const double MAX_WAGE = 75;
private const double MIN_HOURS = 0;
private const double MAX_HOURS = 50;
private double wage; // wage of employee
private double hours; // hours worked
private string category; // category
//Noargument constructor
public Hourly()
: base()
{
wage = MIN_WAGE;
hours = MIN_HOURS;
category = "Not Given";
}//End of Noargument constructor.
//3-argument constructor
public Hourly(double wage, double hours, string category)
: base()
{
setWage(wage);
setHours(hours);
setCategory(category);
}//End of 3-Argument constructor
//8-argument cinstructor
public Hourly(string first, string last, char gen, int dep, double wage, double hours, Benefit ben, string category)
: base(first, last, gen, dep, wage * 1300, ben)
{
setWage(wage);
setHours(hours);
setCategory(category);
}// End of 8-argument constructor
//Helper functions to set wage, hours and category
public void setWage(double wage)
{
if (wage >= MIN_WAGE && wage <= MAX_WAGE)
this.wage = wage;
else
this.wage = MIN_WAGE;
}//End of setWage
//Sets hours
public void setHours(double hours)
{
if (hours >= MIN_HOURS && hours <= MAX_HOURS)
this.hours = hours;
else
this.hours = MIN_HOURS;
}//End of setHours
//Sets category
public void setCategory(string category)
{
if (category == "temporary" || category == "part time" || category == "full time")
this.category = category;
else
this.category = "temporary";
}//End of setCategory
//Overrides the base class method calculatePay
public override double CalculatePay()
{
return wage * hours;
}//End of CalculatePay method
//Overrides the base class ToString to display data of the object
public override string ToString()
{
return string.Format("Employee Type : {0} First Name : {1} Last Name : {2} Gender : {3} Dependents : {4} Category : {5} Wage : {6:c} Hours : {7} Weekly Pay : {8:c} Annual Salary : {9:c} {10}",
GetType().Name.ToUpper(), FirstName, LastName, (Gender == 'M') ? "Male" : "Female", Dependents, category, wage, hours, CalculatePay(), AnnualSalary, benefit.ToString());
}//End of ToString method
}//End of Hourly class
}//End of namespace
	~Hourly(void);
};

SALARIED.H

const int MIN_MANAGEMENT_LEVEL = 0;
const int MAX_MANAGEMENT_LEVEL = 3;
const double BONUS_PERCENT = .10;
class Salaried :public Employee
{
protected:
	int managementLevel;
public:
	Salaried() :Employee()//initial the common employee attributes
	{
		managementLevel = MIN_MANAGEMENT_LEVEL;
	}
	Salaried(string firstName, string lastName, char gender, int dependents, double salary, Benefit benefits, int manLevel)
		:Employee(firstName, lastName, gender, dependents, salary, benefits)
	{
		setManagementLevel(manLevel);  //use the property to ensure valid data in the managementLevel attribute
	}
	Salaried(double salary, int manLevel) :Employee()
	{
		Employee::setAnnualSalary(salary);  //use the super class property to ensure valid data in the annual salary
		setManagementLevel(manLevel);
	}
	void setManagementLevel(int manLevel)
	{
		if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL)
		{
			managementLevel = manLevel;
		}
		else
		{
			managementLevel = MIN_MANAGEMENT_LEVEL;
		}
	}
	int getManagementLevel()
	{
		return managementLevel;
	}
	double calculatePay()
	{
		return Employee::calculatePay() * (1 + (managementLevel*BONUS_PERCENT));
	}
	void displayEmployee()
	{
		Employee::displayEmployee();
		cout << "Salaried Employee\n";
		cout << "Management level:\t" << managementLevel;

	}

};

EMPLOYEE.CPP

#include <string>
#include <iomanip>
#include "Employee.h"
#include "Benefits.h"
using namespace std;
int Employee::numEmployee=0;
Employee::Employee() {
firstName = "not given";
lastName = "not given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
numEmployee++;
}
Employee::Employee(string first, string last, char gen, int dep,
double salary) {
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
numEmployee++;
}
Benefit::Benefit() {
healthInsurance=" not given";
lifeInsurance=0;
vacation=0;
}
Benefit::Benefit(string hInsurance, double lInsurance, int vacationDays){
healthInsurance=hInsurance;
lifeInsurance=lInsurance;
vacation=vacationDays;
}
string Benefit::getHealthInsurance() {
return healthInsurance;
}
double Benefit::getLifeInsurance() {
return lifeInsurance;
}
int Benefit::getVacation() {
return vacation;
}
void Benefit::setHealthInsurance(string hInsurance){
healthInsurance=hInsurance;
}
void Benefit::setLifeInsurance(double lInsurance) {
lifeInsurance=lInsurance;
}
void Benefit::setVacation(int vacationDays) {
vacation=vacationDays;
}
string Employee::getFirstName() {
return firstName;
}
string Employee::getLastName() {
return lastName;
}
void Employee::setFirstName(string fname) {
firstName = fname;
}
void Employee::setLastName(string lname) {
lastName = lname;
}
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 = 'U';
}
}
void Employee::setDependents(int dep) {
dependents = dep;
}
double Employee::getAnnualSalary() {
return annualSalary;
}
void Employee::setAnnualSalary(double salary) {
annualSalary = salary;
}
double Employee::calculatePay() {
return (annualSalary / 52);
}
int Employee::getNumEmployees()
{
return numEmployee;
}
void Employee::displayEmployee() {
cout << "Employee Information" << endl;
cout
<< "----------------------------------------------------------------------------"
<< endl;
cout << setw(16) << left << "Name:" << firstName << " " << lastName << endl;
cout << setw(16) << "Gender:" << gender << endl;
cout << setw(16) << "Dependents:" << dependents << endl;
cout << setw(16) << fixed << setprecision(2) << "Annual Salary:"
<< annualSalary << endl;
cout << setw(16) << "Weekly Salary:" << calculatePay() << endl;
}
void Benefit::displayBenefits() {
cout<< "Employee Benefits Information"<<endl;
cout
<< "----------------------------------------------------------------------------"
<< endl;
cout << setw(16) << left << "Health Insurance:" << healthInsurance<< endl;
cout << setw(16) << "Life Insurance:" << lifeInsurance << endl;
cout << setw(16) << fixed << setprecision(2) << "Vacation:"
<< vacation << endl;
}
Last edited on
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
EMPLOYEETEST.CPP

#include "Employee.cpp"
#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main() {
cout<< "Welcome to your first Object Oriented Program==Employee ClassCIS247C, Week 1 Lab"<< endl;
cout << "Name: Alejandra Dominguez-Cuevas" << endl;
cout << "************** Employee 1 **************" << endl;
Employee emp;
string first;
string last;
string gen;
string dependents;
string salary;
Benefit ben;
string healthInsurance;
double lifeInsurance;
int vacation;
cout << "Please enter your First name ";
cin >> first;
cout << "Please enter your Last name ";
cin >> last;
cout << "Please enter your Gender ";
cin >> gen;
cout << "Please enter your Dependents ";
cin >> dependents;
cout << "Please enter your Annual Salary ";
cin >> salary;
cout << "Please enter your Health Insurance";
cin >> healthInsurance;
cout << "Please enter your Life Insurance";
cin >> lifeInsurance;
cout << "Please enter your Vacation Days";
cin >> vacation;
emp.setFirstName(first);
emp.setLastName(last);
emp.setDependents(atoi(dependents.c_str()));
emp.setAnnualSalary(atof(salary.c_str()));
ben.setHealthInsurance(healthInsurance);
ben.setLifeInsurance(lifeInsurance);
ben.setVacation(vacation);
if (gen == "Female") {
emp.setGender('F');
} else if (gen == "Male") {
emp.setGender('M');
} else {
emp.setGender('U');
}
emp.displayEmployee();
cout << "************** Employee 2 **************" << endl;
Employee emp2("Mary", "Noia", 'F', 5, 24000.0);
emp2.displayEmployee();
emp2.setFirstName(first);
emp2.setLastName(last);
emp2.setDependents(atoi(dependents.c_str()));
emp2.setAnnualSalary(atof(salary.c_str()));
ben.setHealthInsurance(healthInsurance);
ben.setLifeInsurance(lifeInsurance);
ben.setVacation(vacation);
if (gen == "Female") {
emp2.setGender('F');
} else if (gen == "Male") {
emp2.setGender('M');
} else {
emp2.setGender('U');
}
emp2.displayEmployee();
ben.displayBenefits();
cout << "The end of the CIS247C Week4 iLab" << endl;
system("pause");
return 0;
}
Last edited on
It looks like you may need to add #include guards in your header files.

Also your error messages should be giving you more information, please post the complete error message (all of them).

Please use code tags when posting code.

Error 1:
error LNK2005: "public: __thiscall Benefit::Benefit(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,double,int)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in Employee.obj \\acad.dvuadmin.net\sce\HOMEDIR\d01310439\documents\visual studio 2012\Projects\ConsoleApplication37\ConsoleApplication37\EmployeeTest.obj ConsoleApplication37

Error 2 error LNK2005: "public: __thiscall Benefit::Benefit(void)" ([email protected]@[email protected]) already defined in Employee.obj \\acad.dvuadmin.net\sce\HOMEDIR\d01310439\documents\visual studio 2012\Projects\ConsoleApplication37\ConsoleApplication37\EmployeeTest.obj ConsoleApplication37'

Error 3 error LNK2005: "public: __thiscall Employee::Employee(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char,int,double)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in Employee.obj \\acad.dvuadmin.net\sce\HOMEDIR\d01310439\documents\visual studio 2012\Projects\ConsoleApplication37\ConsoleApplication37\EmployeeTest.obj ConsoleApplication37

this is such a long error I have no idea how to fix it. There is 25 of them.
this is such a long error I have no idea how to fix it.


It looks like you may need to add #include guards in your header files.


Do you understand what an #include guard is?

Since you use Visual Studio you can put #pragma once on top of every include file.
@jib- I thought so! I have no idea how to fix it and the first time I was told to seperate it into different headers and sources and it would fix it and it didn't.

@Thomas- I added them and tried to build it and the error is still there but it did help pull up the other ones that I couldn't fix before!
Last edited on
These are the other errors that I am getting now that i couldnt fix myself but I fixed the host of other ones that came up.



IntelliSense: not a class or struct name Salaried.h 6 24
27 IntelliSense: "Employee" is not a nonstatic data member or base class of class "Salaried" Salaried.h 12 14
28 IntelliSense: identifier "string" is undefined Salaried.h 16 11
29 IntelliSense: identifier "string" is undefined Salaried.h 16 29
30 IntelliSense: identifier "Benefit" is undefined Salaried.h 16 90
31 IntelliSense: "Employee" is not a nonstatic data member or base class of class "Salaried" Salaried.h 17 4
32 IntelliSense: expected a ')' Salaried.h 17 22
33 IntelliSense: "Employee" is not a nonstatic data member or base class of class "Salaried" Salaried.h 21 41
34 IntelliSense: name followed by '::' must be a class or namespace name Salaried.h 23 3
35 IntelliSense: name followed by '::' must be a class or namespace name Salaried.h 43 10
36 IntelliSense: name followed by '::' must be a class or namespace name Salaried.h 47 3
37 IntelliSense: identifier "cout" is undefined Salaried.h 48 3 C


26 IntelliSense: declaration of a member with the same name as its class Hourly.h 8 9
27 IntelliSense: "base" is not a nonstatic data member or base class of class "Hourly::Hourly" Hourly.h 20 3
28 IntelliSense: expected a ':' Hourly.h 27 8
29 IntelliSense: "base" is not a nonstatic data member or base class of class "Hourly::Hourly" Hourly.h 28 3
30 IntelliSense: identifier "Benefits" is undefined Hourly.h 35 89
31 IntelliSense: "base" is not a nonstatic data member or base class of class "Hourly::Hourly" \Hourly.h 36 3
32 IntelliSense: expected a ')' Hourly.h 36 13
33 IntelliSense: expected a ':' Hourly.h 43 8
34 IntelliSense: expression must have class type Hourly.h 46 1
35 IntelliSense: expression must have class type Hourly.h 48 1
36 IntelliSense: expression must have class type Hourly.h 54 1
37 IntelliSense: expression must have class type Hourly.h 56 1
38 IntelliSense: expression must have class type Hourly.h 62 1
39 IntelliSense: expression must have class type Hourly.h 64 1
40 IntelliSense: this declaration has no storage class or type specifier Hourly.h 67 9
41 IntelliSense: expected a ':' Hourly.h 73 8
42 IntelliSense: expected a ';' Hourly.h 73 24
43 IntelliSense: expected an identifier Hourly.h 79 1
44 IntelliSense: expected a ';' Hourly.h 81 2
45 IntelliSense: expected an identifier Hourly.h 81 10
46 IntelliSense: expected a declaration Hourly.h 82 1

Did you see this request in the first reply?

Please use code tags when posting code.


Help us help you. Post your code again, but this time, click the "<>" format button and paste each file between the code and /code tags that appear. That will make it a whole lot easier for us because we will get line numbers that line up with the line numbers in the error logs.

You do know that the last two numbers in the error logs are the line number and character on the line where each error is detected, right? So, why don't you look at some of the simpler errors ("expected a ')'", "expected a ';'") and see if you can figure out why the compiler is expecting those tokens.

When you have cleaned up as many errors as possible, post your code again with code tags, and post the remaining error output.

By the way, Salaried.h must include Employee.h so that it knows what an Employee is. That will clean up a bunch (but not all) of the errors you are seeing.
Also never rely on IntelliNonSense, compile your program and fix all warnings and errors generated by your compiler. IntelliNonSense is not the final arbiter of the correct syntax, that falls to the compiler. The compiler will be correct even when IntelliNonSense gets things wrong.


Last edited on
// employeetest.cpp
Line 1: NEVER include .cpp files. You should be including "employee.h". employee.cpp should be part of your project and will be compiled automatically.

Line 4: Correct header is <cstdlib>

After correcting line 1, employeetest.cpp compiles fine for me.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.pickinpatchfarm.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.




Thank you for the tutorial, I didn't realize there was a better way to make the code show up! And the Intellisense was being crazy! I couldn't get it to run any better but when I tried it on a school computer it was fine.

The last errors have to do with getting Benefits to work properly in the EmployeeTest.cpp. I cant figure out how to get EmployeeTest.cpp to read the Benefits class

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
#include "Employee.h"

#include <iostream>

#include <string>

#include <stdlib.h>

#include <iomanip>

using namespace std;

int main() {

cout<< "Welcome to your first Object Oriented Program==Employee ClassCIS247C, Week 1 Lab"<< endl;

cout << "Name: Alejandra Dominguez-Cuevas" << endl;

cout << "************** Employee 1 **************" << endl;

Employee emp;

string first;

string last;

string gen;

string dependents;

string salary;

Benefits ben;

string healthInsurance;

double lifeInsurance;

int vacation;

cout << "Please enter your First name ";

cin >> first;

cout << "Please enter your Last name ";

cin >> last;

cout << "Please enter your Gender ";

cin >> gen;

cout << "Please enter your Dependents ";

cin >> dependents;

cout << "Please enter your Annual Salary ";

cin >> salary;

cout << "Please enter your Health Insurance";

cin >> healthInsurance;

cout << "Please enter your Life Insurance";

cin >> lifeInsurance;

cout << "Please enter your Vacation Days";

cin >> vacation;

emp.setFirstName(first);

emp.setLastName(last);

emp.setDependents(atoi(dependents.c_str()));

emp.setAnnualSalary(atof(salary.c_str()));

ben.setHealthInsurance(healthInsurance);

ben.setLifeInsurance(lifeInsurance);

ben.setVacation(vacation);

if (gen == "Female") {

emp.setGender('F');

} else if (gen == "Male") {

emp.setGender('M');

} else {

emp.setGender('U');

}

emp.displayEmployee();

cout << "************** Employee 2 **************" << endl;

Employee emp2("Mary", "Noia", 'F', 5, 24000.0);


emp2.displayEmployee();

emp2.setFirstName(first);

emp2.setLastName(last);

emp2.setDependents(atoi(dependents.c_str()));

emp2.setAnnualSalary(atof(salary.c_str()));

ben.setHealthInsurance(healthInsurance);

ben.setLifeInsurance(lifeInsurance);

ben.setVacation(vacation);

if (gen == "Female") {

emp2.setGender('F');

} else if (gen == "Male") {

emp2.setGender('M');

} else {

emp2.setGender('U');

}

emp2.displayEmployee();

ben.displayBenefits();

cout << "The end of the CIS247C Week4 iLab" << endl;

system("pause");

return 0;

}
Last edited on
Thank you for adding code tags. Please get rid of the double spacing. That makes your code hard to read.

Line 1: It's a good idea to put your local headers after library headers. That way the library headers are available to your local header files.

Line 7: As I said before, the correct header is <cstdlib>

Line 33: Benefits type is not defined. I suggest you include "benefits.h" at line 12.

Line 33: The class name is singular, not plural.

Line 33: Shouldn't Benefits be an attribute of an Employee instead of a single local instance in main?

Other than that, I get no errors compiling employee.cpp.



Thank you thank you thank you all!!! I appreciate all of your help for this project! It was so hard to find out what went wrong for this and I finally got it to work! My professor will be so happy about this! Thank you all again!
Registered users can post here. Sign in or register to post.
<rt id="pwjBlLZ"><small id="pwjBlLZ"></small></rt>
<acronym id="pwjBlLZ"></acronym><rt id="pwjBlLZ"></rt>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr><acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
<acronym id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></acronym>
<option id="pwjBlLZ"></option>
<tr id="pwjBlLZ"><optgroup id="pwjBlLZ"></optgroup></tr>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym><acronym id="pwjBlLZ"></acronym>
<acronym id="pwjBlLZ"><small id="pwjBlLZ"></small></acronym>
  • 6512882421 2018-04-19
  • 4659652420 2018-04-19
  • 2967832419 2018-04-19
  • 8339042418 2018-04-19
  • 8147112417 2018-04-19
  • 2774752416 2018-04-19
  • 4316132415 2018-04-19
  • 6265742414 2018-04-19
  • 1875142413 2018-04-19
  • 4146552412 2018-04-19
  • 8205662411 2018-04-19
  • 959982410 2018-04-19
  • 7153742409 2018-04-19
  • 9349932408 2018-04-18
  • 6024052407 2018-04-18
  • 2113432406 2018-04-18
  • 7629172405 2018-04-18
  • 163882404 2018-04-18
  • 3515922403 2018-04-18
  • 5047802402 2018-04-18