Store.cpp - #include <iostream>#include <cstring>#include <sstream>#include"Store.h#include"Product.h#include"Customer.h using namespace std int

Store.cpp - #include <iostream>#include <cstring>#include...

This preview shows page 1 - 2 out of 3 pages.

#include <iostream> #include <cstring> #include <sstream> #include "Store.h" #include "Product.h" #include "Customer.h" using namespace std; int Store::counter = 0; // defines and initializes Store::Store(): numProducts(0), numCustomers(0) { // Set the store name counter++; ostringstream oss; oss << "Store " << counter; strcpy(this->name, oss.str().c_str()); } Store::Store(const char name[]): numProducts(0), numCustomers(0) { setName(name); } const char* Store::getName() { return name; } void Store::setName(const char storeName[]) { if (strlen(storeName) > 0) { strcpy(this->name, storeName); } else { counter++; ostringstream oss; oss << "Store " << counter; strcpy(this->name, oss.str().c_str()); } } bool Store::addProduct(int productID, const char productName[]) { // If there are no more slots for a new product, return false. if (numProducts >= 100) { return false; } // Check if there's duplicate of productID for (int i = 0; i < numProducts; i++) { if (products[i]->getID() == productID) { return false; } } // Otherwise, create a new Product, add it to products, and return true. Product* pptr = new Product(productID, productName); products[numProducts] = pptr; numProducts++; return true; }
Image of page 1

Subscribe to view the full document.

Image of page 2
  • Fall '09
  • Walter Daugherity
  • Homework 7

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes