Question

Trying to pass a pointer through the function bool CustomerList::updateStore() that will allow me to modify...

Trying to pass a pointer through the function bool CustomerList::updateStore() that will allow me to modify an input.

Ex.

(1234, "Name", "Street Address", "City", "State", "Zip")

Using the function bool CustomerList::updateStore()

Updating..successful

New Address:

(0001, "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()
{

   // Default constructor

}

CustomerList::~CustomerList()
{

   // Destructor

}

bool CustomerList:: addStore(Store *s)
{
  
   //creating a new instance
   s = new Store();

   if(s==NULL)

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)
{
   return false;
}

void CustomerList::printStoresInfo()
{
   Store *temp;
   cout << " ===================================================================================== " << endl;
   if(m_pHead == NULL)
   {
       cout << " The List is currently empty.\n" ;
   }
   else
   {

       temp = m_pHead;
       while(temp != NULL)
       {
           cout << temp->m_pNext << endl;
       }
   }
}

Store.h

#pragma once;

#include <string.h>
#include <iostream>

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 <iomanip>

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

Homework Answers

Answer #1

NOTE: Store_ID will remain same. If you want to change that, you need to give new store_ID in updateStore arguments and add

temp->m_iStoreID = new_ID;

in the else loop.

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->m_sStoreName, name);

strcpy(temp->m_sAddress, addr);

strcpy(temp->m_sCity, city);

strcpy(temp->m_sState, st);

strcpy(temp->m_sZip, zip);

return true;

   }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
How do I fix my error of binding on line 74? #include <iostream> #include <fstream> #include...
How do I fix my error of binding on line 74? #include <iostream> #include <fstream> #include <cctype> #include <cstring> #include <iomanip> using namespace std; #include "AvlTree.h" class WordCount { public:     char *word;     int *lines;     int count;     int size;     bool operator<(const WordCount &rhs) const {return strcmp(word, rhs.word) < 0;}     bool operator!= (const WordCount &rhs) const {return strcmp(word, rhs.word) != 0;}     WordCount():lines(NULL), count(0), size(0) {word = new char[1]; word[0] = '\0';}     friend ostream& operator<<...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete....
c++ data structures linked list delete node bool deleteNode(int); pass this method an id to delete. Return true or false to indicate success or failure. Delete the memory the node was using The algorithm for deleting a Node to a Linked List (general case): ● Begin at the head. ● Compare the id to the current node. ● If search id > current id, stop. ● Detach the current Node ○ current->previous->next = current->next ○ current->next->previous = current->previous ● Deallocate...
How to stop the program from exiting after display detail. When there is food detail, it...
How to stop the program from exiting after display detail. When there is food detail, it will display and exit the program. What can i do to make it not exit the program and back to main menu. #include <iostream> #include <iomanip> #include<string.h> using namespace std; struct food{ int order_id; string food_code,flavor,customer_id; string address,name; int weight,unit_price,qty,contact_number; struct food *next; };    class Foodsystem{ food *head,*temp,*temp2,*end; static int id;    public: Foodsystem(){ head=NULL;end=NULL;} void Place_Order(); void View_food_details(); void Modify_food_details(); void Delete_food_details();...
Complete the missing code for the constructors as indicated in the comments in all three header...
Complete the missing code for the constructors as indicated in the comments in all three header files. C++ mainDriver.cpp #include <string> #include "Address.h" #include "Date.h" #include "Person.h" using namespace std; int main() {    Person p1;    Person p2("Smith", "Bobby", "[email protected]", 111, "Main St", "Clemson",            "SC", 29630, 1, 31, 1998);    cout << endl << endl;    p1.printInfo();    p2.printInfo();    return 0; } Person.h #ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> using namespace std; class...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in...
Getting the following errors: Error 1 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 565 Error 2 error C2436: '{ctor}' : member function or nested class in constructor initializer list on line 761 I need this code to COMPILE and RUN, but I cannot get rid of this error. Please Help!! #include #include #include #include using namespace std; enum contactGroupType {// used in extPersonType FAMILY, FRIEND, BUSINESS, UNFILLED }; class addressType { private:...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels...
IN C PROGRAMMING A Tv_show structure keeps track of a tv show’s name and the channels (integer values) that broadcast the show. For this problem you can ONLY use the following string library functions: strcpy, strlen, strcmp. You MAY not use memcpy, memset, memmove. You can assume memory allocations are successful (you do not need to check values returned by malloc nor calloc). typedef struct tv_show { char *name; int num_channels, *channels; } Tv_show; a. Implement the init_tv_show function that...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using...
Question: I get a Segmentation fault error sometimes when I addElementBack or print. Am I using pointers correctly and deleting memory properly? #ifndef DYNAMICARRAY_H #define DYNAMICARRAY_H #include <cstdlib> #include <iostream> using namespace std; // Node class class Node { int data; Node* next; Node* prev; public: Node(); Node(int); void SetData(int newData) { data = newData; }; void SetNext(Node* newNext) { next = newNext; }; void SetPrev(Node* newPrev) { prev = newPrev; }; int getData() { return data; }; Node* getNext()...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT