If you're trying to set the employee's name, set the name to n, not the other way around.
Employee(string *n,int , int )
{
*n = name; (This should be name = *n;) I believe.
emp_ID = NULL;
emp_GrossSal = NULL;
//emp_Savings = (.1*emp_GrossSal);
}
Что касается установки имени сотрудника, я бы сделал функцию установки, но, как есть, вы также можете заставить получатель возвращать ссылку вместо этого, и тогда это должно работать:
Employee One;
char name;
cout << "\t\tPlease enter the Employee's Information Below\n\n" <<
endl;
cout << "Enter the employees Name: ";
cin >> One.getName(); (*(One.getName()) if using pointer)
One.displayEmp();
Edit:
void Employee::setName(const string& name_)
{
name = name_;
}
Employee One;
char name;
cout << "\t\tPlease enter the Employee's Information Below\n\n" << endl;
cout << "Enter the employees Name: ";
string inputName;
cin >> inputName;
One.setName(inputName);
One.displayEmp();
Edit # 2:
//NOTE: Your issue here is the way your set salary and display functions work
class Employee
{
private:
string name;
int emp_ID;
int emp_GrossSal;
//NOTE: This is never set
double emp_Savings;
public:
double Employee::getSavings()
{
//NOTE: This is never called
return (emp_GrossSal*(1/100));
}
void Employee::setSalary(int s)
{
//NOTE: Only the emp_GrossSal is set, emp_savings isn't
emp_GrossSal = s;
}
void Employee::displayEmp()
{
cout << "Employee Gross Salary: " << emp_GrossSal << endl;
//NOTE: When you print out savings, you use emp_Saving which was never set.
cout << "Employee Savings: " << emp_Savings << endl;
}
У вас есть два решения для этого, либо вам нужно установить экономию, как показано ниже:
void Employee::setSalary(int s)
{
emp_GrossSal = s;
emp_Savings = (s * 0.1);
}
Или вы можете полностью избавиться от переменной emp_Savings, поскольку она нигде не используется, и просто вызвать функцию получения сбережений вместо использования переменной-члена, как показано ниже:
void Employee::displayEmp()
{
cout << "Employee Gross Salary: " << emp_GrossSal << endl;
//NOTE: This function will actually just get the salary divided by 10
//NOTE: You want to keep this a function in case you change percentage in the future
cout << "Employee Savings: " << getSavings() << endl;
}