I am having issues using bool CustomerList::updateStore(). I am using strcpy in
ID: 3800199 • Letter: I
Question
I am having issues using bool CustomerList::updateStore(). I am using strcpy in order to update input for the Store class, but all I am getting is the same input from before. Here is what I am trying to do:
Ex.
(1234, "Name", "Street Address", "City", "State", "Zip")
Using the function bool CustomerList::updateStore()
Updating..successful
New Address:
(1234, "Store", "111 Main St.", "Townsville", "GA", "67893")
CustomerList.h
#pragma once;
#include
#include "Store.h"
class CustomerList
{
public:
Store *m_pHead;
CustomerList();
~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.cpp
#include
#include "CustomerList.h"
#include "Store.h"
using namespace std;
CustomerList::CustomerList()
{
m_pHead = NULL;
}
CustomerList::~CustomerList()
{
delete m_pHead;
}
bool CustomerList:: addStore(Store *s)
{
if(m_pHead==NULL)
{
m_pHead = new Store(s->getStoreID(),s->getStoreName(), s->getStoreAddress(), s->getStoreCity(), s->getStoreState(), s->getStoreZip());
return true;
}
else
{
Store * temp;
temp=m_pHead;
while(temp->m_pNext != NULL)
{
temp = temp->m_pNext;
}
temp->m_pNext = new Store(s->getStoreID(),s->getStoreName(), s->getStoreAddress(), s->getStoreCity(), s->getStoreState(), s->getStoreZip());
return true;
}
}
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 *retStore = new Store();
*retStore = *temp;
retStore->m_pNext = NULL;
return retStore;
}
}
bool CustomerList::updateStore(int ID, char *name, char *addr, char *city, char *st, char *zip)
{
Store *temp;
temp = m_pHead;
while((temp!= NULL)&&(ID != temp->getStoreID()))
{
temp = temp->m_pNext;
}
if(temp == NULL)
{
return false;
}
else
{
strcpy(temp->getStoreName(),name);
strcpy(temp->getStoreAddress(),addr);
strcpy(temp->getStoreCity(),city);
strcpy(temp->getStoreState(),st);
strcpy(temp->getStoreZip(),zip);
return true;
}
}
void CustomerList::printStoresInfo()
{
Store *temp;
if(m_pHead == NULL)
{
cout << " The List is empty. " ;
}
else
{
temp = m_pHead;
while(temp != NULL)
{
temp->printStoreInfo();
temp = temp->m_pNext;
}
}
}
Store.h
#pragma once;
#include
#include
using namespace std;
class Store
{
private:
int m_iStoreID;
char m_sStoreName[64];
char m_sAddress[64];
char m_sCity[32];
char m_sState[32];
char m_sZip[11];
public:
Store *m_pNext;
Store(); // Default constructor
Store(int ID, // Constructor
char *name,
char *addr,
char *city,
char *st,
char *zip);
~Store(); // Destructor
int getStoreID(); // Get/Set store ID
void setStoreID(int ID);
char *getStoreName(); // Get/Set store name
void setStoreName(char *name);
char *getStoreAddress(); // Get/Set store address
void setStoreAddress(char *addr);
char *getStoreCity(); // Get/Set store city
void setStoreCity(char *city);
char *getStoreState(); // Get/Set store state
void setStoreState(char *state);
char *getStoreZip(); // Get/Set store zip code
void setStoreZip(char *zip);
void printStoreInfo(); // Print all info on this store
};
Store.cpp
#include "Store.h"
#include
using namespace std;
Store::Store()
{
m_pNext = NULL;
}
Store::Store(int ID, char *name, char *addr, char *city, char *st, char *zip)
{
m_iStoreID = ID;
strcpy(m_sStoreName, name);
strcpy(m_sAddress, addr);
strcpy(m_sCity, city);
strcpy(m_sState, st);
strcpy(m_sZip, zip);
m_pNext = NULL;
}
Store::~Store()
{
// Nothing to do here
}
int Store::getStoreID()
{
return m_iStoreID;
}
void Store::setStoreID(int ID)
{
m_iStoreID = ID;
}
char *Store::getStoreName()
{
char *name = new char[strlen(m_sStoreName) + 1];
strcpy(name, m_sStoreName);
return name;
}
void Store::setStoreName(char *name)
{
strcpy(m_sStoreName, name);
}
char *Store::getStoreAddress()
{
char *addr = new char[strlen(m_sAddress) + 1];
strcpy(addr, m_sAddress);
return addr;
}
void Store::setStoreAddress(char *addr)
{
strcpy(m_sAddress, addr);
}
char *Store::getStoreCity()
{
char *city = new char[strlen(m_sCity) + 1];
strcpy(city, m_sCity);
return city;
}
void Store::setStoreCity(char *city)
{
strcpy(m_sCity, city);
}
char *Store::getStoreState()
{
char *state = new char[strlen(m_sState) + 1];
strcpy(state, m_sState);
return state;
}
void Store::setStoreState(char *state)
{
strcpy(m_sState, state);
}
char *Store::getStoreZip()
{
char *zip = new char[strlen(m_sZip) + 1];
strcpy(zip, m_sZip);
return zip;
}
void Store::setStoreZip(char *zip)
{
strcpy(m_sZip, zip);
}
void Store::printStoreInfo()
{
cout << m_iStoreID << setw(20) << m_sStoreName << setw(15) << m_sAddress
<< setw(15) << m_sCity << ", " << m_sState << setw(10) << m_sZip << " ";
}
Employee Record.h
#pragma once
#include "CustomerList.h"
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
CustomerList *getCustomerList();
CustomerList *m_pCustomerList;
//The default constructor
EmployeeRecord();
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);
~EmployeeRecord();
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();
};
Employee Record.cpp
#include
#include "EmployeeRecord.h"
#include "CustomerList.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);
m_iEmployeeID = ID;
m_iDeptID = dept;
m_dSalary = sal;
fName = NULL;
lName = NULL;
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
delete m_pCustomerList;
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(fName, m_sFirstName);
strcpy(lName, m_sLastName);
}
void EmployeeRecord::setName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
int EmployeeRecord::getDept()
{
return m_iDeptID;
}
void EmployeeRecord::setDept(int d)
{
m_iDeptID = d;
}
double EmployeeRecord::getSalary()
{
return m_dSalary;
}
void EmployeeRecord::setSalary(double sal)
{
m_dSalary = sal;
}
void EmployeeRecord::printRecord()
{
cout << "ID: " << m_iEmployeeID << " ";
cout << " Name: " << m_sLastName << " , " << m_sFirstName << " ";
cout << " Dept: " << m_iDeptID << " " << " ";
cout << "Salary: $" << m_dSalary << " " << endl << endl;
}
CustomerList *EmployeeRecord::getCustomerList()
{
CustomerList *m_pCustomerList = new CustomerList();
return m_pCustomerList;
}
MainProgram.cpp
#include
#include "EmployeeRecord.h"
#include
using namespace std;
int main()
{
int employee_id = 100, dept_id = 42, IDNum;
char fname [32];
char lname [32];
double salary = 65000;
double salaryp;
double *p_salary ;
salaryp = 65000;
p_salary = &salaryp;
//=========================================================================EmployeeRecord Testing==========================================================================================
EmployeeRecord *Employee1 = new EmployeeRecord(dept_id, fname, lname, dept_id, salary);
Employee1->setID(employee_id);
Employee1->setName("John", "Doe");
Employee1->setDept(42);
Employee1->setSalary(salary);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == employee_id)
//Test Successful
if((strcmp(fname, "John") == 0)&&(strcmp(lname,"Doe") == 0))
//Test Successful
if(dept_id == 42)
//Test Successful
if(*p_salary == salary)
//Test Successful
Employee1->printRecord();
Employee1->setID(456);
Employee1->setName("Jane", "Smith");
Employee1->setDept(45);
Employee1->setSalary(4000);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == 456)
//Test Successful
if((strcmp(fname, "Jane") == 0)&&(strcmp(lname,"Smith") == 0))
//Test Successful
if(dept_id == 45)
//Test Successful
if(*p_salary == 4000)
Employee1->printRecord();
//=====================================Customer List Testing====================================
cout <<" ===============================================================================================================" << endl;
cout <<" Adding stores to the list " << endl;
cout <<"===============================================================================================================" << endl << endl;
CustomerList *cl = Employee1 ->getCustomerList();
//----Testing the addStore, and printStoresInfo functions:--------------------------------------
Store *s = new Store(4567,"A Computer Store", "1111 Main St." ,"West City" ,"Alabama", "12345");
Store *s1 = new Store(7654,"Jones Computers", "1234 Main St." ,"North City" ,"Alabama", "54321");
Store *s2 = new Store(1234, "Smith Electronics", "2222 2nd St." ,"Eastville", "Alabama","12346");
cout <<"Calling printStoresInfo() after adding one store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
cout <<"Calling printStoresInfo() after adding second store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s1);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl<< endl;
cout <<"Calling printStoresInfo() after adding third store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s2);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
//---Testing the get store function:---------
Store *s3 = NULL;
s3=cl->getStore(1234);
if((s3 != NULL) && (s3->getStoreID() == 1234))
cout << "Testing getStore(1234)...successful" << endl;
Store *s4 = NULL;
s4=cl->getStore(7654);
if((s4 != NULL) && (s4->getStoreID() == 7654))
cout << "Testing getStore(7654)...successful" << endl;
cout << "Testing getStore(9999)..." << endl;
Store *s9 = NULL;
s9 = cl->getStore(9999);
if(s9 == NULL)
cout << "getStore() correctly reported failure to find the store." << endl;
//-------------------------------------------
//---Testing updateStore Function: ----------------------------------------------------------------------
bool chk = cl->updateStore(1234, "hello", "1111 TestAddress", "TestCity", "TestState", "TestZip");
if(chk)
{
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl ->printStoresInfo();
cout <<"===============================================================================================================" << endl;
}
else
cout << "updateStore test failed ";
bool chk1 = cl -> updateStore(9999, "NoName", "1111 NoAddress", "NoCity", "NoState", "NoZip");
if(!chk1)
cout << "updateStore negative test passed. ";
else
cout << "updateStore negative test failed. ";
//---------------------------------------------------------------------------------------------------------
//--Testing the removeStore function-------------------------------------------------------------------------------------------------
Store *s5;
s5 = cl ->removeStore(4567);
if(s5 == NULL)
Store *s5 = cl -> removeStore(4567);
if(( s5 != NULL) && (s5->getStoreID() == 4567))
cout << " Removing store 4567 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
Store *s6;
s6 = cl ->removeStore(1234);
if(s6 == NULL)
Store *s6 = cl -> removeStore(1234);
if(( s6 != NULL) && (s6->getStoreID() == 1234))
cout << " Removing store 1234 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
Store *s7;
s7 = cl ->removeStore(7654);
if(s7 == NULL)
Store *s7 = cl -> removeStore(7654);
if(( s7 != NULL) && (s7->getStoreID() == 7654))
cout << " Removing store 7654 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---Testing the destructor-----------------
EmployeeRecord *e = new EmployeeRecord();
delete e;
//------------------------------------------
system ("pause");
return 0;
}
Explanation / Answer
You are using getter method to set the class fields value which is incorrect. Should be setter method to do it. See the highlighted code, where changes required.
I have merged your code into one file and ran it refer the output in url http://ideone.com/ysAjEh
Code:
#define NULL 0
#include <string.h>
#include <iostream>
#include <iomanip>
using namespace std;
class Store
{
private:
int m_iStoreID;
char m_sStoreName[64];
char m_sAddress[64];
char m_sCity[32];
char m_sState[32];
char m_sZip[11];
public:
Store *m_pNext;
Store(); // Default constructor
Store(int ID, // Constructor
char *name,
char *addr,
char *city,
char *st,
char *zip);
~Store(); // Destructor
int getStoreID(); // Get/Set store ID
void setStoreID(int ID);
char *getStoreName(); // Get/Set store name
void setStoreName(char *name);
char *getStoreAddress(); // Get/Set store address
void setStoreAddress(char *addr);
char *getStoreCity(); // Get/Set store city
void setStoreCity(char *city);
char *getStoreState(); // Get/Set store state
void setStoreState(char *state);
char *getStoreZip(); // Get/Set store zip code
void setStoreZip(char *zip);
void printStoreInfo(); // Print all info on this store
};
Store::Store()
{
m_pNext = NULL;
}
Store::Store(int ID, char *name, char *addr, char *city, char *st, char *zip)
{
m_iStoreID = ID;
strcpy(m_sStoreName, name);
strcpy(m_sAddress, addr);
strcpy(m_sCity, city);
strcpy(m_sState, st);
strcpy(m_sZip, zip);
m_pNext = NULL;
}
Store::~Store()
{
// Nothing to do here
}
int Store::getStoreID()
{
return m_iStoreID;
}
void Store::setStoreID(int ID)
{
m_iStoreID = ID;
}
char *Store::getStoreName()
{
char *name = new char[strlen(m_sStoreName) + 1];
strcpy(name, m_sStoreName);
return name;
}
void Store::setStoreName(char *name)
{
strcpy(m_sStoreName, name);
}
char *Store::getStoreAddress()
{
char *addr = new char[strlen(m_sAddress) + 1];
strcpy(addr, m_sAddress);
return addr;
}
void Store::setStoreAddress(char *addr)
{
strcpy(m_sAddress, addr);
}
char *Store::getStoreCity()
{
char *city = new char[strlen(m_sCity) + 1];
strcpy(city, m_sCity);
return city;
}
void Store::setStoreCity(char *city)
{
strcpy(m_sCity, city);
}
char *Store::getStoreState()
{
char *state = new char[strlen(m_sState) + 1];
strcpy(state, m_sState);
return state;
}
void Store::setStoreState(char *state)
{
strcpy(m_sState, state);
}
char *Store::getStoreZip()
{
char *zip = new char[strlen(m_sZip) + 1];
strcpy(zip, m_sZip);
return zip;
}
void Store::setStoreZip(char *zip)
{
strcpy(m_sZip, zip);
}
void Store::printStoreInfo()
{
cout << m_iStoreID << setw(20) << m_sStoreName << setw(15) << m_sAddress
<< setw(15) << m_sCity << ", " << m_sState << setw(10) << m_sZip << " ";
}
class CustomerList
{
public:
Store *m_pHead;
CustomerList();
~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::CustomerList()
{
m_pHead = NULL;
}
CustomerList::~CustomerList()
{
delete m_pHead;
}
bool CustomerList:: addStore(Store *s)
{
if(m_pHead==NULL)
{
m_pHead = new Store(s->getStoreID(),s->getStoreName(), s->getStoreAddress(), s->getStoreCity(), s->getStoreState(), s->getStoreZip());
return true;
}
else
{
Store * temp;
temp=m_pHead;
while(temp->m_pNext != NULL)
{
temp = temp->m_pNext;
}
temp->m_pNext = new Store(s->getStoreID(),s->getStoreName(), s->getStoreAddress(), s->getStoreCity(), s->getStoreState(), s->getStoreZip());
return true;
}
}
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 *retStore = new Store();
*retStore = *temp;
retStore->m_pNext = NULL;
return retStore;
}
}
bool CustomerList::updateStore(int ID, char *name, char *addr, char *city, char *st, char *zip)
{
Store *temp, *newNode;
temp = m_pHead;
while((temp!= NULL)&&(ID != temp->getStoreID()))
{
temp = temp->m_pNext;
}
//printf(" 1test1 --- %d %s %s ",temp->getStoreID(),name,temp->getStoreName());
if(temp == NULL)
{
return false;
}
else
{
temp->setStoreName(name);
temp->setStoreAddress(addr);
temp->setStoreCity(city);
temp->setStoreState(st);
temp->setStoreZip(zip);
return true;
}
}
void CustomerList::printStoresInfo()
{
Store *temp;
if(m_pHead == NULL)
{
cout << " The List is empty. " ;
}
else
{
temp = m_pHead;
while(temp != NULL)
{
temp->printStoreInfo();
temp = temp->m_pNext;
}
}
}
class EmployeeRecord
{
private:
int m_iEmployeeID;
char m_sLastName[32];
char m_sFirstName[32];
int m_iDeptID;
double m_dSalary;
public:
CustomerList *getCustomerList();
CustomerList *m_pCustomerList;
//The default constructor
EmployeeRecord();
EmployeeRecord(int ID, char *fName, char *lName, int dept, double sal);
~EmployeeRecord();
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();
};
//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);
m_iEmployeeID = ID;
m_iDeptID = dept;
m_dSalary = sal;
fName = NULL;
lName = NULL;
}
// Default Desctrutor
EmployeeRecord::~EmployeeRecord()
{
delete m_pCustomerList;
}
int EmployeeRecord:: getID()
{
return m_iEmployeeID;
}
void EmployeeRecord::setID(int ID)
{
m_iEmployeeID = ID;
}
void EmployeeRecord::getName(char *fName, char *lName)
{
strcpy(fName, m_sFirstName);
strcpy(lName, m_sLastName);
}
void EmployeeRecord::setName(char *fName, char *lName)
{
strcpy(m_sFirstName, fName);
strcpy(m_sLastName, lName);
}
int EmployeeRecord::getDept()
{
return m_iDeptID;
}
void EmployeeRecord::setDept(int d)
{
m_iDeptID = d;
}
double EmployeeRecord::getSalary()
{
return m_dSalary;
}
void EmployeeRecord::setSalary(double sal)
{
m_dSalary = sal;
}
void EmployeeRecord::printRecord()
{
cout << "ID: " << m_iEmployeeID << " ";
cout << " Name: " << m_sLastName << " , " << m_sFirstName << " ";
cout << " Dept: " << m_iDeptID << " " << " ";
cout << "Salary: $" << m_dSalary << " " << endl << endl;
}
CustomerList *EmployeeRecord::getCustomerList()
{
CustomerList *m_pCustomerList = new CustomerList();
return m_pCustomerList;
}
int main()
{
int employee_id = 100, dept_id = 42, IDNum;
char fname [32];
char lname [32];
double salary = 65000;
double salaryp;
double *p_salary ;
salaryp = 65000;
p_salary = &salaryp;
//=========================================================================EmployeeRecord Testing==========================================================================================
EmployeeRecord *Employee1 = new EmployeeRecord(dept_id, fname, lname, dept_id, salary);
Employee1->setID(employee_id);
Employee1->setName("John", "Doe");
Employee1->setDept(42);
Employee1->setSalary(salary);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == employee_id)
//Test Successful
if((strcmp(fname, "John") == 0)&&(strcmp(lname,"Doe") == 0))
//Test Successful
if(dept_id == 42)
//Test Successful
if(*p_salary == salary)
//Test Successful
Employee1->printRecord();
Employee1->setID(456);
Employee1->setName("Jane", "Smith");
Employee1->setDept(45);
Employee1->setSalary(4000);
IDNum = Employee1-> getID();
Employee1->getName(fname,lname);
Employee1->getDept();
Employee1->getSalary();
if(IDNum == 456)
//Test Successful
if((strcmp(fname, "Jane") == 0)&&(strcmp(lname,"Smith") == 0))
//Test Successful
if(dept_id == 45)
//Test Successful
if(*p_salary == 4000)
Employee1->printRecord();
//=====================================Customer List Testing====================================
cout <<" ===============================================================================================================" << endl;
cout <<" Adding stores to the list " << endl;
cout <<"===============================================================================================================" << endl << endl;
CustomerList *cl = Employee1 ->getCustomerList();
//----Testing the addStore, and printStoresInfo functions:--------------------------------------
Store *s = new Store(4567,"A Computer Store", "1111 Main St." ,"West City" ,"Alabama", "12345");
Store *s1 = new Store(7654,"Jones Computers", "1234 Main St." ,"North City" ,"Alabama", "54321");
Store *s2 = new Store(1234, "Smith Electronics", "2222 2nd St." ,"Eastville", "Alabama","12346");
cout <<"Calling printStoresInfo() after adding one store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
cout <<"Calling printStoresInfo() after adding second store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s1);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl<< endl;
cout <<"Calling printStoresInfo() after adding third store to list."<< endl;
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> addStore(s2);
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
//---Testing the get store function:---------
Store *s3 = NULL;
s3=cl->getStore(1234);
if((s3 != NULL) && (s3->getStoreID() == 1234))
cout << "Testing getStore(1234)...successful" << endl;
Store *s4 = NULL;
s4=cl->getStore(7654);
if((s4 != NULL) && (s4->getStoreID() == 7654))
cout << "Testing getStore(7654)...successful" << endl;
cout << "Testing getStore(9999)..." << endl;
Store *s9 = NULL;
s9 = cl->getStore(9999);
if(s9 == NULL)
cout << "getStore() correctly reported failure to find the store." << endl;
//-------------------------------------------
//---Testing updateStore Function: ----------------------------------------------------------------------
bool chk = cl->updateStore(1234, "hello", "1111 TestAddress", "TestCity", "TestState", "TestZip");
if(chk)
{
cout <<" ===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl ->printStoresInfo();
cout <<"===============================================================================================================" << endl;
}
else
cout << "updateStore test failed ";
bool chk1 = cl -> updateStore(9999, "NoName", "1111 NoAddress", "NoCity", "NoState", "NoZip");
if(!chk1)
cout << "updateStore negative test passed. ";
else
cout << "updateStore negative test failed. ";
//---------------------------------------------------------------------------------------------------------
//--Testing the removeStore function-------------------------------------------------------------------------------------------------
Store *s5;
s5 = cl ->removeStore(4567);
if(s5 == NULL)
Store *s5 = cl -> removeStore(4567);
if(( s5 != NULL) && (s5->getStoreID() == 4567))
cout << " Removing store 4567 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
Store *s6;
s6 = cl ->removeStore(1234);
if(s6 == NULL)
Store *s6 = cl -> removeStore(1234);
if(( s6 != NULL) && (s6->getStoreID() == 1234))
cout << " Removing store 1234 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
Store *s7;
s7 = cl ->removeStore(7654);
if(s7 == NULL)
Store *s7 = cl -> removeStore(7654);
if(( s7 != NULL) && (s7->getStoreID() == 7654))
cout << " Removing store 7654 from the list...successful" << endl;
cout << "Calling printStoresInfo after deleting a store from the head of the list." << endl;
cout <<"===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl -> printStoresInfo();
cout <<"===============================================================================================================" << endl << endl;
//---------------------------------------------------------------------------------------------------------------------------------------
//---Testing the destructor-----------------
EmployeeRecord *e = new EmployeeRecord();
delete e;
//------------------------------------------
system ("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.