Im having difficulty compiling this program. I wrote a .h file that includes the class, constructor, mutator, and accessor functions-- a .cpp implementation file that includes the definitions of the functions, and the main .cpp program that tries to utilitze these functions. I've been trying to debug and have not found a solution. I broke down the problem into a simple task just to see if it will work but i still receive the linker error. The final program will have a derived class and its implementation file but i want to try to work in out in sections. In this example, im just trying to get it to work so im just using a single character for the employee name and just integers for the date ,not trying to get the whole string.Here's what i have as of yet:
employee.h
employee.cpp(implementation file that has the function definitions)Code:#ifndef EMPLOYEE_H #define EMPLOYEE_H class Employee { private: char EmployeeName;// To hold the employee name int EmployeeID;// To hold the employee ID int HireDate;// To hold the employee hire date public: // constructor 1 Employee(); // constructor 2 Employee(char,int,int); //Mutator function void setName(char); void setID(int); void setDate(int); //Accessor function const char GetName() const {return EmployeeName;} int GetID() const {return EmployeeID;} int GetDate() const {return HireDate;} }; #endif
mainprogram.cpp (The main program file)Code:#include "Employee.h" #include<iostream> #include<cstring> using namespace std; // The constructor function definition Employee::Employee() { EmployeeName = '\0'; EmployeeID = 0; HireDate = 0; } Employee::Employee(char n, int i,int d) { strcpy(EmployeeName, n); EmployeeID = i; HireDate = d; } //Mutator Definitions void Employee::setName(char n) { strcpy(EmployeeName,n); } //------------ void Employee::setID(int i) { EmployeeID = i; } //----------- void Employee::setDate(int d) { HireDate = d; }
I've only started learning the basics of c++ since last fall. Its becoming more challenging as i progress and would very much appreciate any assistance from the community. Thank youCode:#include<iostream> #include<cstring> #include "Employee.h" using namespace std; int main() { int i,d; char n; cout<< "enter a letter"; cin >> n; cout << "enter your ID"; cin >> i; cout <<"enter your date"; cin >> d; Employee pay(n,i,d); cout << pay.GetID(); system("pause"); return 0; }



LinkBack URL
About LinkBacks



