Question

In: Computer Science

I am having issues using bool CustomerList::updateStore(). I am using strcpy in order to update input...

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.\n" ;
}

   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 << "\n";
}

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] = '\0';
m_sLastName[0] = '\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 << "\t";
   cout << "\tName: " << m_sLastName << " , " << m_sFirstName << "\t";
   cout << "\tDept: " << m_iDeptID << "\t" << "\t";
   cout << "Salary: $" << m_dSalary << "\t" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << endl;
   cout << "   Stores in List " << endl;
   cout <<"===============================================================================================================" << endl;
       cl ->printStoresInfo();
   cout <<"===============================================================================================================" << endl;
   }
   else
       cout << "updateStore test failed\n";

   bool chk1 = cl -> updateStore(9999, "NoName", "1111 NoAddress", "NoCity", "NoState", "NoZip");

   if(!chk1)
       cout << "updateStore negative test passed.\n";
   else
       cout << "updateStore negative test failed.\n";
   //---------------------------------------------------------------------------------------------------------
     
     

   //--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 << "\nRemoving 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 << "\nRemoving 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 << "\nRemoving 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;
}

Solutions

Expert Solution

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 << "\n";
}
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("\n1test1 --- %d %s %s\n",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.\n" ;
}
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] = '\0';
m_sLastName[0] = '\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 << "\t";
cout << "\tName: " << m_sLastName << " , " << m_sFirstName << "\t";
cout << "\tDept: " << m_iDeptID << "\t" << "\t";
cout << "Salary: $" << m_dSalary << "\t" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << 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 <<"\n===============================================================================================================" << endl;
cout << " Stores in List " << endl;
cout <<"===============================================================================================================" << endl;
cl ->printStoresInfo();
cout <<"===============================================================================================================" << endl;
}
else
cout << "updateStore test failed\n";
bool chk1 = cl -> updateStore(9999, "NoName", "1111 NoAddress", "NoCity", "NoState", "NoZip");
if(!chk1)
cout << "updateStore negative test passed.\n";
else
cout << "updateStore negative test failed.\n";
//---------------------------------------------------------------------------------------------------------


//--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 << "\nRemoving 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 << "\nRemoving 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 << "\nRemoving 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 Solutions

This needs to be done in Excel and that is where I am having issues Healthy...
This needs to be done in Excel and that is where I am having issues Healthy Snacks Co. produces snack mixes. Recently, the company has decided to introduce a new snack mix that has peanuts, raisins, pretzels, dries cranberries, sunflower seeds and pistachios. Each bag of the new snack is designed in order to hold 250 grams of the snack. The company has decided to market the new product with a emphasis on its health benefits. After consulting nutritionists, Healthy...
I have the below program and I am having issues putting all the output in one...
I have the below program and I am having issues putting all the output in one line instead of two. how can I transform the program for the user enter format ( HH:MM) Like: Enter time using 24 format ( HH:MM) : " and the user enter format " 14:25 then the program convert. instead of doing two lines make all one line. Currently I have the user enter first the Hour and then the minutes but i'd like to...
I am having an issue with the code. The issue I am having removing the part...
I am having an issue with the code. The issue I am having removing the part when it asks the tuter if he would like to do teach more. I want the program to stop when the tuter reaches 40 hours. I believe the issue I am having is coming from the driver. Source Code: Person .java File: public abstract class Person { private String name; /** * Constructor * @param name */ public Person(String name) { super(); this.name =...
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks....
I am having trouble fixing my build errors. The compiler I am using is Visual Studio.Thanks. #include <iostream> #include <string> #include <cstdlib> using namespace std; /* * structure to store employee details * employee details are stored as linked list */ struct Employee { private:    string full_name; //full name    double net_income; //income public:    struct Employee *next; //pointing to the next employee details in the list                        /*                   ...
Hi, Working on a project in my group for class and I am having some issues...
Hi, Working on a project in my group for class and I am having some issues My part is current state of the business. It is a store and the annual sales are $460,000 Other info I have is: Ownership and Compensation; Percent Ownership Personal Investment Mitchell George, Founder & CEO 25% $125,000Katie Beauseigneur, COO 15% $75,000 Melissa Dunnells, CFO15% $75,000 Also, a medium coffee price from store is $3.75 Sarah Griffin, Marketing Officer 10% $50,000 Katharina Ferry, HR Director10%...
Please fix this code I am having issues compiling it all together there is 3 codes...
Please fix this code I am having issues compiling it all together there is 3 codes here and it's giving me errors in my main method..... I feel like it might be something simple but I can't seem to find it. package assignement2; import java.util.ArrayList; import java.util.Scanner; public class reg1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of items: "); int number = input.nextInt(); input.nextLine(); for (int i = 0; i <...
Adding code that will keep cumulative count of characters? Hello, I am having issues in figuring...
Adding code that will keep cumulative count of characters? Hello, I am having issues in figuring out how to keep letter from a .txt file with the declaration of independence, this is my code, I can keep track of the frequency but can't figure out the way to keep adding the total characters, as the you go down the alphabet the number is supposed to be counting up #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #define DEBUG void main() {   ...
Using dev c++ I'm having trouble with classes. I think the part that I am not...
Using dev c++ I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues: The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
Using the BAII Plus calculator I am having a difficult time using this calculator to solve...
Using the BAII Plus calculator I am having a difficult time using this calculator to solve this MIRR 0 =-325,000 1=50,000 2= 75,000 3=-60,000 4=225,000 5=300,000 Required rate of return =15% We discount all negative CFs(at 15%) time 0 We compound all positive cash flows (at 15%) to 5 years This is now the TV or Terminal Value Please help me understand how to calculate these numbers?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT