SlideShare a Scribd company logo
Having issues with passing my values through different functions after "EmployeeRecord()".
Problem: This database must be capable of maintaining the employee ID, employee name,
department, and annual salary of each sales rep. The first phase of development for this database
will be to create the EmployeeRecord class.
Header File
#pragma once
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
EmployeeRecord(); //The default constructor
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor shall set
the member values passed into the function.
~EmployeeRecord();// The destructor
int getID();// shall return the value stored in the member variable
void setID(int ID);// will set the member variable m_iEmployeeID to the value of its' argument.
void getName(char *fName, char *lName);// The getName() function shall copy the member
variables m_sFirstName and m_sLastName into the character arrays pointed to by the function
arguments.
void setName(char *fName, char *lName);// The setName() function will copy the function
arguments into the member variables m_sFirstName and m_sLastName.
void getDept(int& d);// The getDept() function shall be defined as a reference function. That is,
a call to this function will copy the member variable m_iDeptID into the int variable referenced
by the function argument.
void setDept(int d);// The setDept() function will copy the function argument into the member
variable m_iDeptID.
void getSalary(double *sal);// he getSalary() function shall be defined as a pointer function.
void setSalary(double sal);//the function setSalary() shall copy the function argument into the
member variable m_dSalary.
void printRecord(); //This function shall print to the screen all data found in the employee's
record.
};
Main File
#include
#include "EmployeeRecord.h"
#include
#include
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = '0';
m_sLastName[0] = '0';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
fName=NULL;
lName=NULL;
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
// It was tested in sprint 1
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
/*char *newString = new char[strlen(theString) + 1];
strcpy(newString, theString);
return newString;*/
}
void EmployeeRecord::setName(char *fName, char *lName)
{
/*clearString(); // Clear the current string, if any
theString = new char[strlen(str) + 1]; // Allocate memory for new string
strcpy(theString, str); // Copy string argument into new memory space.*/
}
void EmployeeRecord::getDept(int& d)
{
d = m_iDeptID;
}
void EmployeeRecord::setDept(int d)
{
m_iDeptID = d;
}
void EmployeeRecord::getSalary(double *sal)
{
*sal = m_dSalary;
}
void EmployeeRecord::setSalary(double sal)
{
m_dSalary = sal;
}
void EmployeeRecord::printRecord()
{
cout << "ID: " << m_iEmployeeID << endl;
cout << "Last Name: " << m_sLastName << endl;
cout << "First Name: " << m_sFirstName << endl;
cout << "Dept: " << m_iDeptID << endl;
cout << "Salary: " << m_dSalary << endl;
}
int main(void)
{
int input, employee_id, dept_id, i;
char firstname[32], lastname[32];
double *p_salary;
p_salary = NULL;
double salary;
cout << " What would you like to do?" << endl << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " Enter the Employee's ID: ";
cin >> employee_id;
cout << endl;
cout << " Enter Employee's First Name: ";
cin >> firstname;
cout << " Enter Employee's Last Name: ";
cin >> lastname;
cout << endl;
cout << " Enter Department Number: ";
cin >> dept_id;
cout << endl;
cout << " Enter Employee's Annual Salary: $";
cin >> *p_salary;
EmployeeRecord *Employee1 = new EmployeeRecord(employee_id, firstname, lastname,
dept_id, *p_salary);
Employee1->printRecord();
system ("pause");
return 0;
}
Having issues with passing my values through different functions after "EmployeeRecord()".
Problem: This database must be capable of maintaining the employee ID, employee name,
department, and annual salary of each sales rep. The first phase of development for this
database will be to create the EmployeeRecord class.
Solution
#include
#include
#include
#include
using namespace std;
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
EmployeeRecord(); //The default constructor
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor
shall set the member values passed into the function.
~EmployeeRecord();// The destructor
int getID();// shall return the value stored in the member variable
void setID(int ID);// will set the member variable m_iEmployeeID to the value of its'
argument.
void getName(char *fName, char *lName);// The getName() function shall copy the
member variables m_sFirstName and m_sLastName into the character arrays pointed to by the
function arguments.
void setName(char *fName, char *lName);// The setName() function will copy the
function arguments into the member variables m_sFirstName and m_sLastName.
void getDept(int& d);// The getDept() function shall be defined as a reference function.
That is, a call to this function will copy the member variable m_iDeptID into the int variable
referenced by the function argument.
void setDept(int d);// The setDept() function will copy the function argument into the
member variable m_iDeptID.
void getSalary(double *sal);// he getSalary() function shall be defined as a pointer
function.
void setSalary(double sal);//the function setSalary() shall copy the function argument into
the member variable m_dSalary.
void printRecord(); //This function shall print to the screen all data found in the
employee's record.
};
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = '0';
m_sLastName[0] = '0';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
// Commenting this out as this will lead to fName and lName getting lost before copying it to
the member variables
// fName=NULL;
// lName=NULL;
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
// Copying other member variables
m_iEmployeeID = ID;
m_iDeptID = dept;
m_dSalary = sal;
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
// It was tested in sprint 1
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
//Copying member variables to parameters for name, as required in header file comments
strcpy(fName, m_sFirstName);
strcpy(lName, m_sLastName);
/*char *newString = new char[strlen(theString) + 1];
strcpy(newString, theString);
return newString;*/
}
void EmployeeRecord::setName(char *fName, char *lName)
{
//Copying parameters to member variables, as required in header file comments
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
/*clearString(); // Clear the current string, if any
theString = new char[strlen(str) + 1]; // Allocate memory for new string
strcpy(theString, str); // Copy string argument into new memory space.*/
}
void EmployeeRecord::getDept(int& d)
{
d = m_iDeptID;
}
void EmployeeRecord::setDept(int d)
{
m_iDeptID = d;
}
void EmployeeRecord::getSalary(double *sal)
{
*sal = m_dSalary;
}
void EmployeeRecord::setSalary(double sal)
{
m_dSalary = sal;
}
void EmployeeRecord::printRecord()
{
cout << "ID: " << m_iEmployeeID << endl;
cout << "Last Name: " << m_sLastName << endl;
cout << "First Name: " << m_sFirstName << endl;
cout << "Dept: " << m_iDeptID << endl;
cout << "Salary: " << m_dSalary << endl;
}
int main(void)
{
int input, employee_id, dept_id, i;
char firstname[32], lastname[32];
double *p_salary;
p_salary = NULL;
double salary;
cout << " What would you like to do?" << endl << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " Enter the Employee's ID: ";
cin >> employee_id;
cout << endl;
cout << " Enter Employee's First Name: ";
cin >> firstname;
cout << " Enter Employee's Last Name: ";
cin >> lastname;
cout << endl;
cout << " Enter Department Number: ";
cin >> dept_id;
cout << endl;
cout << " Enter Employee's Annual Salary: $";
cin >> salary;
//Changed input param from *p_salary to salary, as the constructor for Employee class takes a
double input param for salary and not a double pointer
EmployeeRecord *Employee1 = new EmployeeRecord(employee_id, firstname, lastname,
dept_id, salary);
Employee1->printRecord();
//Using setter functions here to change the values in Employee1 object and then printing to
test
Employee1->setID(2);
char* firstName = "Sam";
char* lastName = "Johnson";
Employee1->setName(firstName, lastName);
Employee1->setDept(2);
Employee1->setSalary(4000);
cout << "--------------------------------"<printRecord();
system ("pause");
return 0;
}
NOTE: Please go through the comments thoroughly, I have made some small changes here and
there and added commennts for the same. Also check the main method to see how we are passing
values to the setter functions to change the objects attributes.

More Related Content

Similar to Having issues with passing my values through different functions aft.pdf (20)

PDF
#include iostream #include fstream #include string #incl.pdf
aptexx
 
DOC
Brief Summary Of C++
Haris Lye
 
DOCX
Ass 1
gururaj kulkarni
 
DOCX
Pratik Bakane C++
pratikbakane
 
DOCX
OOP program questions with answers
Quratulain Naqvi
 
DOCX
In this assignment, you will continue working on your application..docx
jaggernaoma
 
RTF
project3
Russell Rawls
 
PDF
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
PDF
I need help to modify my code according to the instructions- Modify th.pdf
pnaran46
 
DOCX
Write a task that will perform some of the functions performed by a s.docx
ajoy21
 
DOCX
Computer science project work
rahulchamp2345
 
DOC
Pads lab manual final
AhalyaR
 
PPT
w10 (1).ppt
amal68766
 
PPTX
CPP Homework Help
C++ Homework Help
 
PDF
Implementation Your program shall contain at least the follo.pdf
ADITIEYEWEAR
 
PDF
in C++ Design a class named Employee The class should keep .pdf
adithyaups
 
TXT
Advance C++notes
Rajiv Gupta
 
DOCX
Cs pritical file
Mitul Patel
 
PDF
Below is my code- I have an error that I still have difficulty figurin.pdf
armanuelraj
 
PDF
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
DerekDixmanChakowela
 
#include iostream #include fstream #include string #incl.pdf
aptexx
 
Brief Summary Of C++
Haris Lye
 
Pratik Bakane C++
pratikbakane
 
OOP program questions with answers
Quratulain Naqvi
 
In this assignment, you will continue working on your application..docx
jaggernaoma
 
project3
Russell Rawls
 
To write a program that implements the following C++ concepts 1. Dat.pdf
SANDEEPARIHANT
 
I need help to modify my code according to the instructions- Modify th.pdf
pnaran46
 
Write a task that will perform some of the functions performed by a s.docx
ajoy21
 
Computer science project work
rahulchamp2345
 
Pads lab manual final
AhalyaR
 
w10 (1).ppt
amal68766
 
CPP Homework Help
C++ Homework Help
 
Implementation Your program shall contain at least the follo.pdf
ADITIEYEWEAR
 
in C++ Design a class named Employee The class should keep .pdf
adithyaups
 
Advance C++notes
Rajiv Gupta
 
Cs pritical file
Mitul Patel
 
Below is my code- I have an error that I still have difficulty figurin.pdf
armanuelraj
 
OOP_EXPLAINED_example_of_cod_and_explainations.pdf
DerekDixmanChakowela
 

More from rajkumarm401 (20)

PDF
Explain the characterstic of web service techonolgy.SolutionT.pdf
rajkumarm401
 
PDF
Executive Summary i. Provide a succinct overview of your strategic p.pdf
rajkumarm401
 
PDF
eee230 Instruction details Answer the following questions in a typed.pdf
rajkumarm401
 
PDF
Essay questionPorter Combining business strategy What is itmeani.pdf
rajkumarm401
 
PDF
During oogenesis, will the genotypes of the first and second polar b.pdf
rajkumarm401
 
PDF
Does personal information available on the Internet make an employee.pdf
rajkumarm401
 
PDF
Determine whether each series is convergent or divergent..pdf
rajkumarm401
 
PDF
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
rajkumarm401
 
PDF
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
rajkumarm401
 
PDF
Click the desktop shortcut icon that you created in this module, and .pdf
rajkumarm401
 
PDF
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
rajkumarm401
 
PDF
What was the causes of the Vietnam war What was the causes of .pdf
rajkumarm401
 
PDF
Transactions costs are zero in financial markets. zero in financial i.pdf
rajkumarm401
 
PDF
This is for an homework assignment using Java code. Here is the home.pdf
rajkumarm401
 
PDF
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
rajkumarm401
 
PDF
Program Structure declare ButtonState Global variable holding statu.pdf
rajkumarm401
 
PDF
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
rajkumarm401
 
PDF
Need help in assembly. Thank you Implement the following expression .pdf
rajkumarm401
 
PDF
mine whether the following s are true or false False A parabola has e.pdf
rajkumarm401
 
PDF
Locate an article where the technique of Polymerase chain reaction (.pdf
rajkumarm401
 
Explain the characterstic of web service techonolgy.SolutionT.pdf
rajkumarm401
 
Executive Summary i. Provide a succinct overview of your strategic p.pdf
rajkumarm401
 
eee230 Instruction details Answer the following questions in a typed.pdf
rajkumarm401
 
Essay questionPorter Combining business strategy What is itmeani.pdf
rajkumarm401
 
During oogenesis, will the genotypes of the first and second polar b.pdf
rajkumarm401
 
Does personal information available on the Internet make an employee.pdf
rajkumarm401
 
Determine whether each series is convergent or divergent..pdf
rajkumarm401
 
Describe the primary differences between WEP, WPA, and WPA2 protocol.pdf
rajkumarm401
 
Complete the provided partial C++ Linked List program. Main.cpp is g.pdf
rajkumarm401
 
Click the desktop shortcut icon that you created in this module, and .pdf
rajkumarm401
 
YOU DO IT 4! create an named YouDolt 4 and save it in the vB 2015Chap.pdf
rajkumarm401
 
What was the causes of the Vietnam war What was the causes of .pdf
rajkumarm401
 
Transactions costs are zero in financial markets. zero in financial i.pdf
rajkumarm401
 
This is for an homework assignment using Java code. Here is the home.pdf
rajkumarm401
 
Question 34 (1 point) D A check is 1) not money because it is not off.pdf
rajkumarm401
 
Program Structure declare ButtonState Global variable holding statu.pdf
rajkumarm401
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
rajkumarm401
 
Need help in assembly. Thank you Implement the following expression .pdf
rajkumarm401
 
mine whether the following s are true or false False A parabola has e.pdf
rajkumarm401
 
Locate an article where the technique of Polymerase chain reaction (.pdf
rajkumarm401
 

Recently uploaded (20)

PPTX
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPTX
PPT on the Development of Education in the Victorian England
Beena E S
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
PPTX
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PPTX
How to Manage Promotions in Odoo 18 Sales
Celine George
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
Presentation: Climate Citizenship Digital Education
Karl Donert
 
HEAD INJURY IN CHILDREN: NURSING MANAGEMENGT.pptx
PRADEEP ABOTHU
 
PPT on the Development of Education in the Victorian England
Beena E S
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Capitol Doctoral Presentation -July 2025.pptx
CapitolTechU
 
Views on Education of Indian Thinkers J.Krishnamurthy..pptx
ShrutiMahanta1
 
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
How to Create Rental Orders in Odoo 18 Rental
Celine George
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
How to Manage Promotions in Odoo 18 Sales
Celine George
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
Presentation: Climate Citizenship Digital Education
Karl Donert
 

Having issues with passing my values through different functions aft.pdf

  • 1. Having issues with passing my values through different functions after "EmployeeRecord()". Problem: This database must be capable of maintaining the employee ID, employee name, department, and annual salary of each sales rep. The first phase of development for this database will be to create the EmployeeRecord class. Header File #pragma once class EmployeeRecord { private: int m_iEmployeeID; char m_sLastName[32]; char m_sFirstName[32]; int m_iDeptID; double m_dSalary; public: EmployeeRecord(); //The default constructor EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor shall set the member values passed into the function. ~EmployeeRecord();// The destructor int getID();// shall return the value stored in the member variable void setID(int ID);// will set the member variable m_iEmployeeID to the value of its' argument. void getName(char *fName, char *lName);// The getName() function shall copy the member variables m_sFirstName and m_sLastName into the character arrays pointed to by the function arguments. void setName(char *fName, char *lName);// The setName() function will copy the function arguments into the member variables m_sFirstName and m_sLastName. void getDept(int& d);// The getDept() function shall be defined as a reference function. That is, a call to this function will copy the member variable m_iDeptID into the int variable referenced by the function argument. void setDept(int d);// The setDept() function will copy the function argument into the member variable m_iDeptID. void getSalary(double *sal);// he getSalary() function shall be defined as a pointer function. void setSalary(double sal);//the function setSalary() shall copy the function argument into the member variable m_dSalary.
  • 2. void printRecord(); //This function shall print to the screen all data found in the employee's record. }; Main File #include #include "EmployeeRecord.h" #include #include using namespace std; //Default Constructor EmployeeRecord::EmployeeRecord() { // The default constructor shall set the member variables to the following m_iEmployeeID = 0; m_sFirstName[0] = '0'; m_sLastName[0] = '0'; m_iDeptID = 0; m_dSalary = 0.0; } EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal) { fName=NULL; lName=NULL; strcpy(m_sFirstName, fName); strcpy(m_sLastName, lName); } // Default Desctrutor EmployeeRecord::~EmployeeRecord() { // It was tested in sprint 1 } int EmployeeRecord:: getID()
  • 3. { return m_iEmployeeID; } void EmployeeRecord::setID(int ID) { m_iEmployeeID = ID; } void EmployeeRecord::getName(char *fName, char *lName) { strcpy(m_sFirstName, fName); strcpy(m_sLastName, lName); /*char *newString = new char[strlen(theString) + 1]; strcpy(newString, theString); return newString;*/ } void EmployeeRecord::setName(char *fName, char *lName) { /*clearString(); // Clear the current string, if any theString = new char[strlen(str) + 1]; // Allocate memory for new string strcpy(theString, str); // Copy string argument into new memory space.*/ } void EmployeeRecord::getDept(int& d) { d = m_iDeptID; } void EmployeeRecord::setDept(int d) { m_iDeptID = d; } void EmployeeRecord::getSalary(double *sal) { *sal = m_dSalary; } void EmployeeRecord::setSalary(double sal) {
  • 4. m_dSalary = sal; } void EmployeeRecord::printRecord() { cout << "ID: " << m_iEmployeeID << endl; cout << "Last Name: " << m_sLastName << endl; cout << "First Name: " << m_sFirstName << endl; cout << "Dept: " << m_iDeptID << endl; cout << "Salary: " << m_dSalary << endl; } int main(void) { int input, employee_id, dept_id, i; char firstname[32], lastname[32]; double *p_salary; p_salary = NULL; double salary; cout << " What would you like to do?" << endl << endl; cout << " 1. Create a new Employee Record" << endl << endl; cout << " Enter the Employee's ID: "; cin >> employee_id; cout << endl; cout << " Enter Employee's First Name: "; cin >> firstname; cout << " Enter Employee's Last Name: "; cin >> lastname; cout << endl; cout << " Enter Department Number: "; cin >> dept_id; cout << endl;
  • 5. cout << " Enter Employee's Annual Salary: $"; cin >> *p_salary; EmployeeRecord *Employee1 = new EmployeeRecord(employee_id, firstname, lastname, dept_id, *p_salary); Employee1->printRecord(); system ("pause"); return 0; } Having issues with passing my values through different functions after "EmployeeRecord()". Problem: This database must be capable of maintaining the employee ID, employee name, department, and annual salary of each sales rep. The first phase of development for this database will be to create the EmployeeRecord class. Solution #include #include #include #include using namespace std; class EmployeeRecord { private: int m_iEmployeeID; char m_sLastName[32]; char m_sFirstName[32]; int m_iDeptID; double m_dSalary; public: EmployeeRecord(); //The default constructor EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);// Constructor shall set the member values passed into the function. ~EmployeeRecord();// The destructor int getID();// shall return the value stored in the member variable
  • 6. void setID(int ID);// will set the member variable m_iEmployeeID to the value of its' argument. void getName(char *fName, char *lName);// The getName() function shall copy the member variables m_sFirstName and m_sLastName into the character arrays pointed to by the function arguments. void setName(char *fName, char *lName);// The setName() function will copy the function arguments into the member variables m_sFirstName and m_sLastName. void getDept(int& d);// The getDept() function shall be defined as a reference function. That is, a call to this function will copy the member variable m_iDeptID into the int variable referenced by the function argument. void setDept(int d);// The setDept() function will copy the function argument into the member variable m_iDeptID. void getSalary(double *sal);// he getSalary() function shall be defined as a pointer function. void setSalary(double sal);//the function setSalary() shall copy the function argument into the member variable m_dSalary. void printRecord(); //This function shall print to the screen all data found in the employee's record. }; //Default Constructor EmployeeRecord::EmployeeRecord() { // The default constructor shall set the member variables to the following m_iEmployeeID = 0; m_sFirstName[0] = '0'; m_sLastName[0] = '0'; m_iDeptID = 0; m_dSalary = 0.0; } EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal) { // Commenting this out as this will lead to fName and lName getting lost before copying it to the member variables // fName=NULL;
  • 7. // lName=NULL; strcpy(m_sFirstName, fName); strcpy(m_sLastName, lName); // Copying other member variables m_iEmployeeID = ID; m_iDeptID = dept; m_dSalary = sal; } // Default Desctrutor EmployeeRecord::~EmployeeRecord() { // It was tested in sprint 1 } int EmployeeRecord:: getID() { return m_iEmployeeID; } void EmployeeRecord::setID(int ID) { m_iEmployeeID = ID; } void EmployeeRecord::getName(char *fName, char *lName) { //Copying member variables to parameters for name, as required in header file comments strcpy(fName, m_sFirstName); strcpy(lName, m_sLastName); /*char *newString = new char[strlen(theString) + 1]; strcpy(newString, theString); return newString;*/ } void EmployeeRecord::setName(char *fName, char *lName) { //Copying parameters to member variables, as required in header file comments
  • 8. strcpy(m_sFirstName, fName); strcpy(m_sLastName, lName); /*clearString(); // Clear the current string, if any theString = new char[strlen(str) + 1]; // Allocate memory for new string strcpy(theString, str); // Copy string argument into new memory space.*/ } void EmployeeRecord::getDept(int& d) { d = m_iDeptID; } void EmployeeRecord::setDept(int d) { m_iDeptID = d; } void EmployeeRecord::getSalary(double *sal) { *sal = m_dSalary; } void EmployeeRecord::setSalary(double sal) { m_dSalary = sal; } void EmployeeRecord::printRecord() { cout << "ID: " << m_iEmployeeID << endl; cout << "Last Name: " << m_sLastName << endl; cout << "First Name: " << m_sFirstName << endl; cout << "Dept: " << m_iDeptID << endl; cout << "Salary: " << m_dSalary << endl; } int main(void) { int input, employee_id, dept_id, i; char firstname[32], lastname[32]; double *p_salary;
  • 9. p_salary = NULL; double salary; cout << " What would you like to do?" << endl << endl; cout << " 1. Create a new Employee Record" << endl << endl; cout << " Enter the Employee's ID: "; cin >> employee_id; cout << endl; cout << " Enter Employee's First Name: "; cin >> firstname; cout << " Enter Employee's Last Name: "; cin >> lastname; cout << endl; cout << " Enter Department Number: "; cin >> dept_id; cout << endl; cout << " Enter Employee's Annual Salary: $"; cin >> salary; //Changed input param from *p_salary to salary, as the constructor for Employee class takes a double input param for salary and not a double pointer EmployeeRecord *Employee1 = new EmployeeRecord(employee_id, firstname, lastname, dept_id, salary); Employee1->printRecord(); //Using setter functions here to change the values in Employee1 object and then printing to test Employee1->setID(2); char* firstName = "Sam"; char* lastName = "Johnson"; Employee1->setName(firstName, lastName); Employee1->setDept(2); Employee1->setSalary(4000);
  • 10. cout << "--------------------------------"<printRecord(); system ("pause"); return 0; } NOTE: Please go through the comments thoroughly, I have made some small changes here and there and added commennts for the same. Also check the main method to see how we are passing values to the setter functions to change the objects attributes.