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