Posted by: nepali8 March 28, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
 Namaste!!

Need some help to seperate this file in (.h) and (.cpp) file.

thanks in advance

#ifndef EmployeeClass
#define EmployeeClass
#include <cstring>
 
const int DEFAULT_SIZE = 51;
 
class EmployeeData
{
private:
char *name;
int idnumber;
char *department;
char *position;
 
//private member function
void createName(int size, char *value)
{//Allocate the default amount of memory for name
name = new char [size];
 
//store a value in the memory
strcpy(name, value);}
 
void createDepartment(int size, char *value2)
{
department = new char [size];
strcpy(department, value2);}
 
void createPosition(int size, char *value3)
{
position = new char [size];
strcpy(position, value3);}
 
public:
//Constructor #1
EmployeeData()
{//Store an empty string in the name attribute.
createName(DEFAULT_SIZE, "");
createDepartment(DEFAULT_SIZE, "");
createPosition(DEFAULT_SIZE, "");
 
//initialize idnumber department position
idnumber = 0;}
 
//Constructor #2
EmployeeData(char *nam, char *dep, char *pos)
{//allocate memory and store the description.
createName(strlen(nam), nam);
createDepartment(strlen(dep), dep);
createPosition(strlen(pos), pos);
 
//initialize idnumber department position
idnumber = 0;}
 
//Constructor #3
EmployeeData(char *nam, int id, char *dep, char *pos)
{//Allocate memory and store the description.
createName(strlen(nam), nam);
createDepartment(strlen(dep), dep);
createPosition(strlen(pos), pos);
 
//Assign values to id deparment position
idnumber = id;}
 
//Destructor
~EmployeeData()
{ delete[] name;}
 
//mutator functions
void setName(char *n)
{strcpy(name, n);}
 
void setIdnumber(int id)
{idnumber = id;}
 
void setDepartment(char *d)
{strcpy (department,d);}
 
void setPosition(char *p)
{strcpy (position,p);}
 
//Accessor functions
const char *getName() const
{return name;}
 
int getIdnumber() const
{return idnumber;}
 
char *getDepartment() const
{return department;}
 
char *getPosition() const
{return position;}
};
#endif
Read Full Discussion Thread for this article