Employee Class. 3 files

Ok guys I need some assistance :)
---

I am very much stuck on this Employee class, it's for school.

Constructor should have 3 parameters.
Provide a set / get function for each data member.

Basically I think user enters their salary, if its a negative #, it sets to 0. Then I have to give a 10 percent raise. set again? then get?

Im so lost!

Heres my header file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string> 
using namespace std;

class Employee
{
public:
	Employee ( string );     
	void setFirstName( string );
	string getFirstName();     
	void setLastName ( string );
	string getLastName();
	void setsalary ( int );
	int getsalary ();
private:
	string firstName;
	string lastName;
	int salary;
}; 

Well, you have the basic class set up...read this and you should be able to finish it:

http://www.cplusplus.com/doc/tutorial/classes/
I'm stuck on my implementation file. I got this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include "Employee.h" 

void Employee::setsalary( int salary )
{
	if ( salary < 0 )
	{
		monthlySalary = 0;
		cout << "monthly salary must be greater than 0." << endl;
		cout << "monthly salary is now 0." << endl;
	}
	else {
		monthlySalary = salary;
	
		} 

}
Can an expert help me with the rest of this .cpp file?

Is what I have so far correct?
The employee class has no member called monthlySalary - it is called salary
See line 18 of the header file.

personally I think :
1. The salary should be double rather than an int.
2. you might want to avoid 0 as a salary

because you don't want to end up doing integer division, and you certainly don't want to divide by 0
It is Generally recommended not to use using namespace xxx directive in header files.
Do it the same way as you have done in the cpp file - or write it out fully like std::cout
the task also says:
Constructor should have 3 parameters.

I think they want a constructor with parameters for firstname, lastname and salary.

Your current constructor has only one parameter.
Would my constructor be:
void Employee::setsalary( int salary, string FirstName, string LastName)
?


Also, would it be salary = salary;
?

Do I add 10% after setting the salary?

would it be cout << "monthly salary is now (salary*.1)" << endl;
Topic archived. No new replies allowed.