HELP WITH A _EmployeeClass_Program

I have been working on this employee class program that takes the first name, last, name, dependents, gender, and annual salary. for an eemployee1 and employee2. The instructor only wants this 1 .cpp file. I can't get it to compile. I don't really understand what I'm missing.Any help would be greatly appreciated this is my last resort.

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
// Program Header
// Program Name: Employee Class Program
// Programmer: Alicia Shorts
// CIS247 Week 2 iLab
// Program Description: Object Oriented program with a class names Employee

#include<iostream>
#include<string>
#include<stdlib.h>
#include<iomanip>

using namespace std;

class Employee
{


public:
	Employee();
	Employee(string firstName, string lastName, char gender, int dependents, double salary);

	double calculatePay(double);
	displayEmployee(void);
	string getFirstName(string firstName);
	string setFirstName(string);
	string getLastName(string);
	string setLastName( string);
	char getGender(char);
	char setGender(  char);
	int getDependents(int);
	int setDependents( int);
	double getAnnualSalary(double);
	double setAnnualSalary(  double);

	Employee::Employee(void)
{
	string firstName= "not given" ; 
	string lastName = "not given";
	char gender = 'U';
	int dependents = 0;
	double annualSalary = 20000;


}
Employee::~Employee(void)
{
}

void setGender(char gen)
{
	switch(gen)
	{
	case'f': case 'F': case 'm':case 'M': gender = gen; break;
	default: cout << " Gender unknown" << endl; break;
		default = Default_Gender;

	}
}


	Employee:: Employee(string firstName, string lastName, char gender, int dependents, double salary)
{

	this ->firstName = firstName;
	this ->lastName = lastName;
	this ->gender = gender;
	this ->dependents = dependents;
	this ->annualSalary = salary;


	string getFirstName()
	{
		return firstName;
	}

	void setFirstName(string name)
	{
		firstName = name;
	}


	string getLastName()
	{
		return lastName;
	}

	void setLastName(string name)
	{
		lastName= name;
	}

	char getGender()
	{
		return gender;
	}

	void setGender(char gen)
	{
		gender = gen;
	}

	int getDependents()
	{
		return dependents;
	}
	void setDependents(int dep)
	{
		dependents= dep;
	}
	double getAnnualSalary()
	{
		return annualSalary;
	}

	void setAnnualSalary(double salary)
	{
		annualSalary = salary;
	}

	double calculatePay()
	{
		annualSalary = annualSalary / 52;
		return annualSalary;
	}
	}

private:
	string firstName;
	string lastName;
	char gender;
	int dependents;
	double annualSalary;






};



string GetInput(string);
void setGender(char gen);
string DisplayDivider(string);
int main()
{

	Employee employee1;
	
	employee1.setFirstName(GetInput("First Name"));
	name = GetInput("First Name");
	employee1.setLastName(GetInput("Last Name"));
	name = GetInput("Last Name");
	employee1.setGender(GetInput(char gen));
	gender = gen;
	employee1.setDependents(GetInput(int dep));
	dependents = dep;
	employee1.setAnnualSalary(GetInput(double salary));
	double annualSalary = salary;

	employee2.setFirstName(GetInput("First Name"));
	name = GetInput("First Name");
	employee2.setLastName(GetInput("Last Name"));
	name = GetInput("Last Name");
	employee2.setGender(GetInput(char gen));
	gender = gen;
	employee2.setDependents(GetInput(int dep));
	dependents = dep;
	employee2.setAnnualSalary(GetInput(double salary));
	double annualSalary = salary;


	DisplayDivider("First Name");
	DispalyDivider("Last Name");
	DisplayDivider(char gen);
	DisplayDivider(int dependents);
	DisplayDivider(double annualSalary);







	return 0;
	system("pause");







}



	
	void displayEmployee()
	{
		cout << "Employee Information \n";
		cout << " ____________________________________________________________________________________________________ \n";
		cout << "Name: \t\t" << firstName << " " << lastName << "\n";
		cout << " Gender: \t\t" << gender << "\n";
		cout << "Dependents: \t" << dependents << "\n";
		cout << "Annual Salary: \t" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
		cout << "Weekly Salary: \t" << setprecision(2) << showpoint << fixed << calculatePay();


	}

	string DisplayDivider( string outputTitle)
	{
		cout << "*********************************" << outputTitle<< "***************************************" << endl;
		return outputTitle;
	}

	string GetInput(string)
	{
		string myString;
		cout << " Please enter your" << inputType;
		getline(cin,myString);
		return myString;
	}
Well, copy-pasting this into CodeBlocks and looking at the error report... there's a lot of things wrong with this. Let me work through it and see what I can do, first...

Well, for one, line 23 doesn't have an actual type.
Last edited on
All your function definitions are inside the class declaration. :( Try defining your functions outside of the class, like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <string>
#include <iostream>
class Person   //class declaration
{
public:
    std::string getName();
    void setName(std::string newName);
private:
    std::string _name;
};  //End of class declaration

// function definitions
std::string Person::getName() { return _name; }
void Person::setName(std::string newName) { _name = newName; }

// main
int main()
{
    Person p;
    p.setName("Alicia");
    std::cout << p.getName();
    return 0;
}

Last edited on
This code could still use some work but you get the idea

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
// Program Header
// Program Name: Employee Class Program
// Programmer:
// CIS247 Week 2 iLab
// Program Description: Object Oriented program with a class names Employee

#include<iostream>
#include<string>
#include<stdlib.h>
#include<iomanip>

using namespace std;

class Employee
{	private:
	string firstName;
	string lastName;
	char gender;
	int dependents;
	double annualSalary;
public:
	Employee();
	~Employee();
	Employee(string firstName, string lastName, char gender, int dependents, double salary);
	double calculatePay();
	void displayEmployee();
	void setFirstName();
	void setLastName();
	void setGender();
	void setDependents();
	void setAnnualSalary();
};

	Employee::Employee()
{
	string firstName= "not given" ; 
	string lastName = "not given";
	char gender = 'U';
	int dependents = 0;
	double annualSalary = 20000;


}
Employee::~Employee()
{
}

	Employee::Employee(string firstName, string lastName, char gender, int dependents, double salary)
{

	firstName = firstName;
	lastName = lastName;
	gender = gender;
	dependents = dependents;
	annualSalary = salary;
}

	void Employee::setFirstName()
	{
		cout << "PLease enter your first Name: ";
		getline(cin,firstName);
		cout << endl;

	}

	void Employee::setLastName()
	{
		cout << "PLease enter your lastname: ";
		getline(cin, lastName);
		cout << endl;
	}

	void Employee::setGender()
	{
		cout << "PLease enter your gender: ";
		cin >> gender;
		cout << endl;
	}

	void Employee::setDependents()
	{
		cout << "Please enter your dependents: ";
		cin >> dependents;
		cin.ignore();
	}

	void Employee::setAnnualSalary()
	{
		cout << "Please entery your annual sallery: ";
		cin >> annualSalary;
		cin.ignore();
	}

	double Employee::calculatePay()
	{
		annualSalary = double (annualSalary / 52);
		return annualSalary;
	}

		void Employee::displayEmployee()
	{
		cout << " __________________________________________________________________________ \n";
		cout << "Employee Information \n";
		cout << "Name: \t\t" << firstName << " " << lastName << "\n";
		cout << " Gender: \t\t" << gender << "\n";
		cout << "Dependents: \t" << dependents << "\n";
		cout << "Annual Salary: \t" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
		cout << "Weekly Salary: \t" << setprecision(2) << showpoint << fixed << calculatePay() << endl;

}

int main()
{
	string name;
	Employee employee1, employee2;
	employee1.setFirstName();
	employee1.setLastName();
	employee1.setGender();
	employee1.setDependents();
	employee1.setAnnualSalary();
	employee2.setFirstName();
	employee2.setLastName();
	employee2.setGender();
	employee2.setDependents();
	employee2.setAnnualSalary();
	employee1.displayEmployee();
	employee2.displayEmployee();

	cin.ignore();
	return 0;
	
}
Last edited on
Thanks everyone, I still have some issues. My instructor told me that it has to be in the layout I have. If the methods are in the class or outside I still get an error both ways.

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
#include<iostream>
#include<string>
#include<stdlib.h>
#include<iomanip>

using namespace std;

class Employee
{

private:
	string firstName;
	string lastName;
	char gender;
	int dependents;
	double annualSalary;




public:
	Employee();
	Employee(string firstName, string lastName, char gender, int dependents, double salary);

	double calculatePay(double);
	void displayEmployee(void);
	string getFirstName(string firstName);
	string setFirstName(string);
	string getLastName(string);
	string setLastName( string);
	char getGender(char);
	char setGender(  char);
	int getDependents(int);
	int setDependents( int);
	double getAnnualSalary();
	double setAnnualSalary(  double);

	Employee::Employee(void)
{
	string firstName= "not given" ; 
	string lastName = "not given";
	char gender = 'U';
	int dependents = 0;
	double annualSalary = 20000;


}
Employee::~Employee(void)
{
}

void setGender(char gen)
{
	switch(gen)
	{
	case'f': case 'F': case 'm':case 'M': gender = gen; break;
	default: cout << " Gender unknown" << endl; break;
		default = Default_Gender;

	}
}


	Employee:: Employee(string firstName, string lastName, char gender, int dependents, double salary)
	{
	this ->firstName = firstName;
	this ->lastName = lastName;
	this ->gender = gender;
	this ->dependents = dependents;
	this ->annualSalary = salary;


	string Employee::getFirstName()
	{
		cout << " Please enter first name:" << endl;
		getline(cin,firstName);
		return firstName;
	}

	void Employee::setFirstName(string name)
	{
		firstName = name;
	}


	string Employee::getLastName()
	{
		cout << "Please enter last name:" << endl;
		getline(cin, lastName);
		
		return lastName;
	}

	void Employee::setLastName(string name)
	{
		lastName= name;
	}

	char Employee::getGender()
	{
		cout << " Please enter gender:" << endl;
		getline(cin, gender);
		return gender;
	}

	void Employee::setGender(char gen)
	{
		gender = gen;
	}

	int Employee::getDependents()
	{
		cout << " Please enter the amount of dependents:" << endl;
		getline(cin,dependents);
		return dependents;
	}
	void Employee::setDependents(int dep)
	{
		dependents= dep;
	}
	double Employee::getAnnualSalary()
	{
		cout << " Please enter the employee's annual salary:" << endl;
		getline(cin, annualSalary);
		return annualSalary;
	}

	void Employee::setAnnualSalary(double salary)
	{
		annualSalary = salary;
	}

	double Employee::calculatePay()
	{
		annualSalary = annualSalary / 52;
		return annualSalary;
	}


	}





};



int main()
{
	string GetInput(string);
void setGender(char gen);
string DisplayDivider(string);
DisplayApplicationInformation();


	Employee employee1;
	
	employee1.setFirstName(GetInput("First Name"));
	name = GetInput("First Name");
	employee1.setLastName(GetInput("Last Name"));
	name = GetInput("Last Name");
	employee1.setGender(GetInput(char gen));
	gender = gen;
	employee1.setDependents(GetInput(int dep));
	dependents = dep;
	employee1.setAnnualSalary(GetInput(double salary));
	double annualSalary = salary;

	employee2.setFirstName(GetInput("First Name"));
	name = GetInput("First Name");
	employee2.setLastName(GetInput("Last Name"));
	name = GetInput("Last Name");
	employee2.setGender(GetInput(char gen));
	gender = gen;
	employee2.setDependents(GetInput(int dep));
	dependents = dep;
	employee2.setAnnualSalary(GetInput(double salary));
	double annualSalary = salary;

	
	cin.ignore();





	return 0;
	system("pause");





}

void DisplayApplicationInformation();
{
	cout << " Welcome to the Employee Class Program!"<< endl;
	cout << " CIS 247 Week 2 Lab" << endl;
	cout << " Name: Alicia Shorts." << endl;
	cout << " This program accepts employee information and calculates annual salary." << endl;



}
		void displayEmployee()
	{
		cout << "Employee Information \n";
		cout << " ____________________________________________________________________________________________________ \n";
		cout << "Name: \t\t" << firstName << " " << lastName << "\n";
		cout << " Gender: \t\t" << gender << "\n";
		cout << "Dependents: \t" << dependents << "\n";
		cout << "Annual Salary: \t" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
		cout << "Weekly Salary: \t" << setprecision(2) << showpoint << fixed << calculatePay();


	}

	string DisplayDivider( string outputTitle)
	{
		cout << "*********************************" << outputTitle<< "***************************************" << endl;
		return outputTitle;
	}

	string GetInput(string)
	{
		string myString;
		cout << " Please enter your" << inputType;
		getline(cin,myString);
		return myString;
	}
Last edited on
If the methods are in the class or outside I still get an error both ways.


The implementation code should be outside the class - even better in it's own .cpp file.

The functions you have in the main.cpp file could also be part of the class.

If you still have errors then post them in full - we can go from there.

Line 198 - remove the semicolon, so that it becomes a function definition and not a re-declaration.

line 154 - 155 - always put a return type for function declarations.

As I said these function should be part of the class.

Hope all goes well.
Topic archived. No new replies allowed.