This is what i'm trying to do:
Implement a structure Employee. An employee has a name (a char ) and a salary (a double). Write a default constructor, a constructor with two parameters (name and salary), and methods char getName() double getSalary() to return the name and salary. Write a small global function TestEmployee() to test your structure.
And this is what i've done so far:
#include<iostream>
#include<cstring>
using namespace std;
//Implement a structure Employee.
struct Employee
{
private:
//An employee has a name (a char *) and a salary (a double).
char *EmpName;
double EmpSalary;
public:
//default constructor
Employee()
{
this->EmpName = new char[100];
this->EmpSalary = 0.00;
}
//a constructor with two parameters (name and salary),
Employee(char* name_, double salary_)
{
do
{
this->EmpName = name_;
this->EmpSalary = salary_;
}while(salary_<0);
}
//char* getName() to return the name
char* getName()
{
return this->EmpName;
}
//double getSalary() to return the salary.
double getSalary()
{
return this->EmpSalary;
}
};
//Write a small global function TestEmployee() to test your structure.
void TestEmployee()
{
//Employee employee_;
char* empName = new char[100];
double empSalary;
cout<<"Creating a new employee.\nPlease type the name:"<<endl;
cin>>empName;
cout<<"Please specify the salary:"<<endl;
cin>>empSalary;
cout<<"New employee has been created."<<endl;
Employee employee_(empName, empSalary);
cout<<"Name of employee: "<<endl;
cout<<employee_.getName()<<endl;
cout<<"Salary: "<<endl;
cout<<employee_.getSalary()<<endl;
cout<<"Thank you for testing structure Employee."<<endl;
}
int main()
{
TestEmployee();
}
I can't seem to find the error, this program isn't working. This is the output it's giving:
When this is the output it's supposed to have: