Header file: #pragma once; class EmployeeRecord { private: int m_iEmployeeID; ch
ID: 3786379 • Letter: H
Question
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);//he 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.
};
CPP File:
#include <iostream>
#include "EmployeeRecord.h"
#include <string>
#include <stdio.h>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = '';
m_sLastName[0] = '';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
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)
{
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[35], lastname[35];
double *salary;
salary = NULL;
menu:
do
{
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
cout << " 8. Quit" << endl << endl;
cin >> input;
if (input == 1)
{
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
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: ";
i = 0;
cin >> firstname[i];
while (firstname[i] != ' ' && i < 35)
{
i++;
cin >> firstname[i];
}
cout << endl;
cout << " Enter Employee's Last Name: ";
i = 0;
cin >> lastname[i];
while (lastname[i] != ' ' && i < 35)
{
i++;
cin >> lastname[i];
}
cout << endl;
cout << " Enter Department Number: ";
cin >> dept_id;
cout << endl;
cout << " Enter Employee's Annual Salary: $";
cin >> *salary;
//EmployeeRecord Employee1 = EmployeeRecord();
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 2)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " The current Employee ID is: " << Employee1.getID();
system("pause");
system("CLS");
goto menu;
}
else if (input == 3)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " Enter the Employee ID: ";
cin >> employee_id;
Employee1.setID(employee_id);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 4)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
Employee1.getName(firstname, lastname);
cout << " Enter the Employee's First Name: ";
cin >> firstname;
cout << " and Last Name: ";
cin >> lastname;
Employee1.setName(firstname, lastname);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 5)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
Employee1.getDept(dept_id);
cout << " Enter Department ID: ";
cin >> dept_id;
Employee1.setDept(dept_id);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 6)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
Employee1.getSalary(salary);
cout << " Enter the Employee's Annual Salary: ";
cin >> *salary;
Employee1.setSalary(*salary);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 7)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
} while (input == 1 || input == 2 || input == 3 || input == 4 || input == 5 || input == 6 || input == 7);
if (input != 8)
{
system("CLS");
cout << "Invalid input! Please Choose one of the 8 options below, then press [Enter]." << endl << endl;
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
cout << " 8. Quit" << endl << endl;
cin >> input;
}
else if (input == 8)
{
system("CLS");
cout << "Closing program" << endl;
}
system ("pause");
return 0;
}
Explanation / Answer
Fixed compilation warnings.
Please post a new question with whole program requirement so that this can be completely worked on. This is completely broken as of now and will not work.
#ifndef MYFILE_H
#define MYFILE_H
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);//he 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.
};
#endif
#include <iostream>
#include "EmployeeRecord.h"
#include <string>
#include <stdio.h>
#include <time.h>
#include <cstdlib>
#include<string.h>
using namespace std;
//Default Constructor
EmployeeRecord::EmployeeRecord()
{
// The default constructor shall set the member variables to the following
m_iEmployeeID = 0;
m_sFirstName[0] = '';
m_sLastName[0] = '';
m_iDeptID = 0;
m_dSalary = 0.0;
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal)
{
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)
{
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[35], lastname[35];
double *salary;
salary = NULL;
menu:
do
{
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
cout << " 8. Quit" << endl << endl;
cin >> input;
if (input == 1)
{
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
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: ";
i = 0;
cin >> firstname[i];
while (firstname[i] != ' ' && i < 35)
{
i++;
cin >> firstname[i];
}
cout << endl;
cout << " Enter Employee's Last Name: ";
i = 0;
cin >> lastname[i];
while (lastname[i] != ' ' && i < 35)
{
i++;
cin >> lastname[i];
}
cout << endl;
cout << " Enter Department Number: ";
cin >> dept_id;
cout << endl;
cout << " Enter Employee's Annual Salary: $";
cin >> *salary;
//EmployeeRecord Employee1 = EmployeeRecord();
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 2)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " The current Employee ID is: " << Employee1.getID();
system("pause");
system("CLS");
goto menu;
}
else if (input == 3)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " Enter the Employee ID: ";
cin >> employee_id;
Employee1.setID(employee_id);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 4)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
Employee1.getName(firstname, lastname);
cout << " Enter the Employee's First Name: ";
cin >> firstname;
cout << " and Last Name: ";
cin >> lastname;
Employee1.setName(firstname, lastname);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 5)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
Employee1.getDept(dept_id);
cout << " Enter Department ID: ";
cin >> dept_id;
Employee1.setDept(dept_id);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 6)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
Employee1.getSalary(salary);
cout << " Enter the Employee's Annual Salary: ";
cin >> *salary;
Employee1.setSalary(*salary);
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
else if (input == 7)
{
EmployeeRecord Employee1 = EmployeeRecord(employee_id, firstname, lastname, dept_id, *salary);
system("CLS");
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
Employee1.printRecord();
system("pause");
system("CLS");
goto menu;
}
} while (input == 1 || input == 2 || input == 3 || input == 4 || input == 5 || input == 6 || input == 7);
if (input != 8)
{
system("CLS");
cout << "Invalid input! Please Choose one of the 8 options below, then press [Enter]." << endl << endl;
cout << "================================================================================" << endl;
cout << " EMPLOYEE RECORD" << endl;
cout << "================================================================================" << endl;
cout << " 1. Create a new Employee Record" << endl << endl;
cout << " 2. Obtain Employee ID of the current Employee Record" << endl << endl;
cout << " 3. Enter Employee ID into the current Employee Record" << endl << endl;
cout << " 4. Enter Employee's Name into the current Employee Record" << endl << endl;
cout << " 5. Enter Department ID into the current Employee Record" << endl << endl;
cout << " 6. Enter Employee's Annual Salary into the current Employee Record" << endl << endl;
cout << " 7. Print current Employee Record" << endl << endl;
cout << " 8. Quit" << endl << endl;
cin >> input;
}
else if (input == 8)
{
system("CLS");
cout << "Closing program" << endl;
}
system ("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.