here is my code
This is just the start of the program, there is more to come. I am testing what I have so far and it compiles successfully, but when once prompted for the employee name, I enter the name, and then the program crashes.Code:// paycenter.cpp // Program to calculate overtime pay for employees #include <iostream> //for stream I/O #include <cstring> //for strlen() and strcpy() using std::cout; using std::cin; using std::endl; class Cemployee { public: char* m_name; double m_hours; float m_wage; Cemployee(char* str = "employee name", double hv = 1, float wv = 1): m_hours(hv),m_wage(wv),m_name(str) { m_name = new char[ strlen(str) + 1]; strcpy_s(m_name, strlen(str) + 1, str); } ~Cemployee(void) { delete[] m_name; } double gethours(void) { return m_hours; } float getwage(void) { return m_wage; } char* getname(void) { return m_name; } }; int main() { char* name; double hours; float wage; cout << "Welcome to the Employee Pay Center" << endl << endl; cout << "Enter the employee name = "; cin >> name; cout << endl << "Enter the hours worked = "; cin >> hours; cout << endl << "Enter his or her hourly wage = "; cin >> wage; Cemployee emp1; emp1.m_wage = wage; emp1.m_hours = hours; emp1.m_name = name; cout << endl << endl << endl; cout << "name " << emp1.getname(); cout << endl << "wage " << emp1.getwage(); cout << endl << "hours " << emp1.gethours() << endl; system("pause"); return 0; }
Please, I am new to C++, I do not need advanced fixed for the code, I just need to understand why it is crashing.