Employee/boss program

I am having an issue with this program and am unable to figure it out. Any help from the experts would be great. Thanks in advance.

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
#include <iostream>
#include <string>

using namespace std;

int main()
class Employee
{
public:
Employee();
string salary;
string boss;
Employee (string employee_Lname, string employee_Fname, int initial_salary)
            {
Employee boss("Jones, Juliet", 45000.00);
 
	        Lname = employee_Lname;
	        Fname = employee_Fname;
	        salary = initial_salary;
            };
 void set_salary(double new_salary);
 double get_salary();
 void set_name(string new_Lname,string new_Fname);
 string get_name();  
 private:
 string Lname;  
 string Fname;
 double salary;
};

void Employee::set_salary(double new_salary)
{
	salary = new_salary;
}

void Employee::set_name (string new_Lname, string new_Fname);
{
 Lname = new_Lname;
 Fname = new_Fname;
}
double Employee::get_salary() const
{
	return salary;
}

string Employee::get_name() const
{
string space = " ";
return Fname +space+ Lname;

         cout << "Name: " << boss.get_name() << "\n";
	 cout <<"Salary: " << boss.get_salary() << "\n";

	 return 0;
 }
Last edited on
Could you elaborate on what the problem is? I can see right away that nothing will happen because your main function isn't defined.

You are creating an object in your constructor? The line of code Employee boss("jones","juliet", 45000); needs to be in your main function:
1
2
3
4
int main(void)
{
Employee boss("jones","juliet", 45000);
}
Last edited on
Just so all the experts know, I am new to C++ programming and am not asking for solutions to my problems/programs just looking for a little nudge in the right direction is all. My boss is getting married, she decides to change her name. It has to be written so that I can type in the new name for her. I also have to set the set_name member function for the Employee class. Per my text, I need to make a new object of type Employee with the new name and same salary, then assign the new object boss. I also need to leave the last three lines of code where they are per text book instructions.

1
2
3
4
5
6
int main()
{
Employee boss("Jones, Juliet, 45000.00); 

cout << "Name: " << boss.get_name() << "\n";
cout << "Salary: " << boss.get_salary() << "\n"; 
Last edited on
I found out where I went wrong with this now just need to figure out this error I get when I run it in compiler. I am using VS2010. Thanks for all the assistance in advance.


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

#include <iostream>
#include <string>

using namespace std;
class Employee
{
public:
/**
Constructs an employee with empty name and no salary, 
   */
Employee(); // empty for now but every insatance will have values
/**
Constructs an employee with a given name and salary,
      @paramemployee_name the emplyee name
	  @paramintital_salary the initial salary
   */
Employee(string employee_Lname, string employee_Fname, int initial_salary)
          {
			 Lname = employee_Lname;
			 Fname = employee_Fname;
			 salary=initial_salary;
             };

void set_salary(double new_salary);
/**
Gets the salary of this employee
     @return the current salary
  */
double get_salary() const;
/** 
Gets the name of this employee,
      @return the employee name
   */
void set_name(string new_Lname, string new_Fname);

string get_name() const;  // I gave the object a first and last name separate

private:
string Lname;
string Fname;
double salary;
};
void Employee::set_salary(double new_salary)
{
salary = new_salary;
}
void Employee::set_name(string new_Lname, string new_Fname)
{
Lname = new_Lname;
Fname = new_Fname;
}

double Employee::get_salary() const
        {
			   return salary;
}


string Employee::get_name() const

{
	string space = " ";
	return Fname +space+ Lname;
}
int main()

{
Employee boss("Jones, Juliet", 45000.00);


     cout << "Name: " << boss.get_name() << "\n";
    cout <<"Salary: " << boss.get_salary() << "\n";

	 return 0;
 }




 error C2661: 'Employee::Employee' : no overloaded function takes 2 arguments

1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
//Employee boss("Jones, Juliet", 45000.00); Fix this line to
Employee boss("Jones", "Juliet", 45000.00);

     cout << "Name: " << boss.get_name() << "\n";
    cout <<"Salary: " << boss.get_salary() << "\n";

	 return 0;
 }



note on usage of ""'s.. Original code gave accidentally just 2 arguments to constructor
Last edited on
I fixed that with arguments constructor. Now I am having an issue trying to declare the new name and salary. I get the easy stuff that I have done thus far but this is giving me a headache lol!! I feel like cursing like QBert when he gets hit by his enemies!! I know I have to do something with the new name and salary but have drawn a blank even after going through classes I tutorial and am getting even more confused.
Here is what I have tried to get this going:

1
2
3
4
string Fname, Lname; boss.get_name(); "\n"; 
string salary; boss.get_salary(); "\n";
cin >> Fname, Lname; 
cin >> salary; 


1
2
3
4
5
6
int new_Fname, new_Lname;
int new_salary;
string new_Fname, new_Lname;
string new_salary;
cin >> new_Fname, new_Lname;
cin >> new_salary;
string Fname, Lname; boss.get_name(); "\n";

THINK!
what happens in this row? First you create 2 variables Fname and Lname. THEN you call get_name function which return only one string to... well nothing.

In the end you get name you needed is stored in one string:
1
2
string das_bos;
das_bos=boss.get_name()


and: wth "\n" part is doing?
Last edited on
Let me see if I figured this out!! Here is the changed code:

1
2
3
4
5
6

string get_name;
get_name=boss.get_name();
string get_salary;
get_salary=boss.get_salary();
Last edited on
part of what???

remember that functions(=methods) are only things(ish) that can interact your creation
Topic archived. No new replies allowed.