Question
I am writing a .h and .cpp file as well as modifying an existing .h and .cpp to accomplish the goals below. I have created
I am writing a .h and .cpp file as well as modifying an existing .h and .cpp to accomplish the goals below. I have created the new EmployeeDatabase files and have pasted them below, this is an assignment due soon and I just need a reference because I keep getting stuck. This should be all you need, please answer in the style of code I have given, thank you!
2.0 Requirements | ||||
The student shall define, develop, document, prototype, test, and modify as required the software system. | ||||
2.1 This software system shall consist of four source files (.cpp) and four header files (.h) defining four classes. The first class, which was developed in phase one and modified in phase two to hold a list of stores, is the EmployeeRecord class. It will be modified so that it can be used to build a binary tree of employee records. The second class shall be the Storeclass provided in phase 2. The third class shall be the CustomerList class developed in phase 2. The fourth class, which shall be called EmployeeDatabase, shall define and maintain a binary tree of EmployeeRecord objects. | ||||
2.2 The class EmployeeRecord, as used in Phase 2 shall be modified so that it can be used to build a binary tree of EmployeeRecord objects. | ||||
2.2.1 Two public pointers to a class of type EmployeeRecord called m_pLeft and m_pRight shall be added to the EmployeeRecord class. | ||||
2.2.2 The public function void removeCustomerList() will be added to the EmployeeRecord class. This function sets the pointer to a CustomerList object to NULL. This function is used by the removeEmployee() function in the EmployeeDatabase class. See details of how this function is used in the hints section below. | ||||
2.2.3 The public function void destroyCustomerList() will be added to the EmployeeRecord class. This function deletes the CustomerList object and sets the pointer to a CustomerList object to NULL. It is used by the removeEmployee() function in the EmployeeDatabase class. See details of how this function is used in the hints section below. NOTE: You will have to modify the destructor of EmployeeRecord to check to see if m_pCustomerList is not NULL before calling delete m_pCustomerList. | ||||
2.3 The class EmployeeDatabase, shall implement a binary tree of EmployeeRecord objects. | ||||
2.3.1 The class EmployeeDatabase, shall contain private variables called m_pRoot which shall be a pointer to an EmployeeRecord object and inFile which shall be an ifstream object. | ||||
2.3.2 The class EmployeeDatabase, shall contain the following public functions: | ||||
2.3.2.1 EmployeeDatabase() and ~EmployeeDatabase--A constructor and a destructor. The destructor function shall take care of deleting all EmployeeRecord objects in the tree to avoid memory leaks. It will do this by initializing a recursive traversal to the tree calling the private function destroyTree(m_pRoot) | ||||
2.3.2.2 bool addEmployee(EmployeeRecord *e)--This function will take a pointer to a completed EmployeeRecord object and insert the object into the binary tree. | ||||
2.3.2.3 EmployeeRecord *getEmployee(int ID)--This function will take an employee ID as an argument. It will search the tree and return a pointer to the employee whose ID matches the function argument. It will return NULL if it fails to find the employee in the tree. | ||||
2.3.2.4 EmployeeRecord *removeEmployee(int ID)--This function will take an employee ID as an argument. It will search the tree, locate (if it exists) the employee record, remove it from the tree and return it. It will return NULL if it failed to find the employee. Note, care must be taken when the EmployeeRecord removed has two children. See the notes below on how to handle this occurance. | ||||
2.3.2.5 void printEmployeeRecords()--This function shall call the private printEmployeeRecords() function passing in the root of the tree. This shall initialize a recursive traversal to print all records in the tree. | ||||
2.3.2.6 bool buildDatabase(char *dataFile)--This function shall take a char array specifying the name of the data file. It will read and build the database. This function is provided by the instructor. See below. | ||||
2.3.3 The class EmployeeDatabase, shall contain the following private functions. | ||||
2.3.3.1 void printEmployeeRecords(EmployeeRecord *rt)--This function overloads the public printEmployeeRecords() function and shall perform an in-order recursive traversal of the entire tree and print all data on all employees in the database. (Note: requirements for the printRecord() function in the EmployeeRecord class are the same as in phase 2.) | ||||
2.3.3.2 void destroyTree(EmployeeRecord *rt)--This function shall recursively traverse the entire tree and delete all nodes in the tree. |
////////////////////EmployeeDatabase.h/////////////////////
#ifndef EMPLOYEEDATABASE_H
#define EMPLOYEEDATABASE_H
#include
#include
#include "EmployeeRecord.h"
using namespace std;
class EmployeeDatabase{
private:
EmployeeRecord *m_pRoot;
ifstream inFile;
void printEmployeeRecords(EmployeeRecord *rt);
void destroyTree(EmployeeRecord *rt);
public:
EmployeeDatabase();
~EmployeeDatabase();
bool addEmployee(EmployeeRecord *e);
EmployeeRecord *getEmployee(int ID);
EmployeeRecord *removeEmployee(int ID);
void printEmployeeRecords();
};
/////////////////////EmployeeDatabase.cpp///////////////////////
#include #include #include #include "CustomerList.h" #include "Store.h" #include "EmployeeDatabase.h"
using namespace std;
EmployeeDatabase::EmployeeDatabase(){
}
EmployeeDatabase::~EmployeeDatabase(){
}
bool EmployeeDatabase::addEmployee(EmployeeRecord *e){
}
EmployeeRecord *EmployeeDatabase::getEmployee(int ID){
}
EmployeeRecord *EmployeeDatabase::removeEmployee(int ID){
}
void EmployeeDatabase::printEmployeeRecords(){
}
void EmployeeDatabase::printEmployeeRecords(EmployeeRecord *rt){
}
void EmployeeDatabase::destroyTree(EmployeeRecord *rt){
}
///////////////////////EmployeeRecord.h/////////////////////////
#ifndef EMPLOYEERECORD_H
#define EMPLOYEERECORD_H
#include "CustomerList.h"
using namespace std;
class EmployeeRecord{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
CustomerList *m_pCustomerList;
public:
EmployeeRecord();
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);
~EmployeeRecord();
CustomerList *getCustomerList();
int getID();
void setID(int ID);
void getName(char *fName, char *lName);
void setName(char *fName, char *lName);
int getDept();
void setDept(int d);
double getSalary();
void setSalary(double sal);
void printRecord();
EmployeeRecord *m_pLeft, *m_pRight;
void removeCustomerList();
void destroyCustomerList();
};
#endif EMPLOYEERECORD_H
///////////////////////EmployeeRecord.cpp////////////////////////
#include "EmployeeRecord.h"
#include
#include
#include
using namespace std;
EmployeeRecord::EmployeeRecord(){
m_iEmployeeID = 0;
strcpy(m_sLastName,"");
strcpy(m_sFirstName,"");
m_iDeptID = 0;
m_dSalary = 0.0;
m_pCustomerList = new CustomerList();
}
EmployeeRecord::EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal){
m_iEmployeeID = ID;
strcpy(m_sLastName,lName);
strcpy(m_sFirstName,fName);
m_iDeptID = dept;
m_dSalary = sal;
m_pCustomerList = new CustomerList();
}
EmployeeRecord::~EmployeeRecord(){
while(m_pCustomerList==NULL){
delete m_pCustomerList;
}
}
CustomerList *EmployeeRecord::getCustomerList(){
return m_pCustomerList;
}
int EmployeeRecord::getID(){
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID){
m_iEmployeeID = ID;
return;
}
void EmployeeRecord::getName(char *fName, char *lName){
strcpy(fName, m_sFirstName);
strcpy(lName, m_sLastName);
return;
}
void EmployeeRecord::setName(char *fName, char *lName){
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
return;
}
int EmployeeRecord::getDept(){
return m_iDeptID;
}
void EmployeeRecord::setDept(int d){
m_iDeptID = d;
return;
}
double EmployeeRecord::getSalary(){
return m_dSalary;
}
void EmployeeRecord::setSalary(double sal){
m_dSalary = sal;
return;
}
void EmployeeRecord::printRecord(){
cout << right << setw(10) << m_iEmployeeID << setw(10) << m_sLastName << "," << setw(10) << m_sFirstName
<< setw(10) << m_iDeptID << setw(8) << "$" << m_dSalary << endl;
return;
}
void EmployeeRecord::removeCustomerList(){
m_pCustomerList = NULL;
return;
}
void EmployeeRecord::destroyCustomerList(){
m_pCustomerList = NULL;
}
//////////////////CustomerList.h/////////////////////
#ifndef CUSTOMERLIST_H
#define CUSTOMERLIST_H
#include "Store.h"
#include
#include
using namespace std;
class CustomerList{
private:
Store *m_pHead;
public:
CustomerList();
bool addStore(Store *s);
Store *removeStore(int ID);
Store *getStore(int ID);
bool updateStore(int ID, char *name, char *addr, char *city, char *st, char *zip);
void printStoresInfo();
~CustomerList();
};
#endif CUSTOMERLIST_H
////////////////////////CustomerList.cpp//////////////////////
#include
#include
#include
#include "CustomerList.h"
#include "Store.h"
using namespace std;
CustomerList::CustomerList(){
m_pHead = NULL;
}
bool CustomerList::addStore(Store *s){
if(m_pHead == NULL){
s->m_pNext = NULL;
m_pHead = s;
}
else{
Store *temp = m_pHead;
if(temp->getStoreID() >= s->getStoreID()){
s->m_pNext = temp;
m_pHead = s;
return true;
}
while(temp->m_pNext != NULL){
if(temp->m_pNext->getStoreID() >= s->getStoreID()){
s->m_pNext = temp->m_pNext;
temp->m_pNext = s;
return true;
}
temp = temp->m_pNext;
}
s->m_pNext = NULL;
temp->m_pNext = s;
return true;
}
return false;
}
Store *CustomerList::removeStore(int ID){
Store *temp, *back;
temp = m_pHead;
back = NULL;
while((temp!=NULL)&&(ID!=temp->getStoreID())){
back = temp;
temp = temp->m_pNext;
}
if(temp==NULL)
return NULL;
else if(back==NULL){
m_pHead = m_pHead->m_pNext;
return temp;
}
else{
back->m_pNext = temp->m_pNext;
return temp;
}
return NULL;
}
Store *CustomerList::getStore(int ID){
Store *temp;
temp = m_pHead;
while((temp!=NULL)&&(ID!=temp->getStoreID())){
temp = temp->m_pNext;
}
if(temp==NULL)
return NULL;
else{
Store *getStore = new Store;
*getStore = *temp;
getStore->m_pNext=NULL;
return getStore;
}
}
bool CustomerList::updateStore(int ID, char *name, char *addr, char *city, char *st, char *zip){
return false;
}
void CustomerList::printStoresInfo(){
Store *temp;
cout << "" << endl;
if(m_pHead==NULL)
cout << "The list is empty." << endl;
else{
temp = m_pHead;
while(temp!=NULL){
temp->printStoreInfo();
temp = temp->m_pNext;
}
}
}
CustomerList::~CustomerList(){
delete m_pHead;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started