Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How would I go about fixing my productSearch function? For some reason it doesn't seem to properly search. I can't create any more functions since

How would I go about fixing my productSearch function? For some reason it doesn't seem to properly search. I can't create any more functions since we are locked into the header files. Here is the assignment :

"

You will be writing a (rather primitive) online store simulator. It will have three classes: Product, Customer and Store. To make things a little simpler for you, I am supplying you with the three .hpp files. You will write the three implementation files. You should not alter the provided .hpp files.

Here are the .hpp files: Product.hppimage text in transcribedimage text in transcribed , Customer.hppimage text in transcribedimage text in transcribed and Store.hppimage text in transcribedimage text in transcribed

Here are descriptions of methods for the three classes:

Product:

A Product object represents a product with an ID code, title, description, price and quantity available.

constructor - takes as parameters five values with which to initialize the Product's idCode, title, description, price, and quantity available

get methods - return the value of the corresponding data member

decreaseQuantity - decreases the quantity available by one

Customer:

A Customer object represents a customer with a name and account ID. Customers must be members of the Store to make a purchase. Premium members get free shipping.

constructor - takes as parameters three values with which to initialize the Customer's name, account ID, and whether the customer is a premium member

get methods - return the value of the corresponding data member

isPremiumMember - returns whether the customer is a premium member

addProductToCart - adds the product ID code to the Customer's cart

emptyCart - empties the Customer's cart

Store:

A Store object represents a store, which has some number of products in its inventory and some number of customers as members.

addProduct - adds a product to the inventory

addMember - adds a customer to the members

getProductFromID - returns pointer to product with matching ID. Returns NULL if no matching ID is found.

getMemberFromID - returns pointer to customer with matching ID. Returns NULL if no matching ID is found.

productSearch -for every product whose title or description contains the search string, prints out that product's title, ID code, price and description. The first letter of the search string should be case-insensitive, i.e. a search for "wood" should match Products that have "Wood" in their title or description, and a search for "Wood" should match Products that have "wood" in their title or description. You may use string::find() and string::npos. You may assume that the search string will consist of a single word.

addProductToMemberCart - If the product isn't found in the inventory, print "Product #[idCode goes here] not found." If the member isn't found in the members, print "Member #[accountID goes here] not found." If both are found and the product is still available, calls the member's addProductToCart method. Otherwise it prints "Sorry, product #[idCode goes here] is currently out of stock." The same product can be added multiple times if the customer wants more than one of something.

checkOutMember - If the member isn't found in the members, print "Member #[accountID goes here] not found." Otherwise prints out the title and price for each product in the cart and decreases the available quantity of that product by 1. If any product has already sold out, then on that line it should print 'Sorry, product #[idCode goes here], "[product name goes here]", is no longer available.' At the bottom it should print out the subtotal for the cart, the shipping cost ($0 for premium members, 7% of the cart cost for normal members), and the final total cost for the cart (subtotal plus shipping). If the cart is empty, it should just print "There are no items in the cart." When the calculations are complete, the member's cart should be emptied.

Here is an example of how the output of the Store::productSearch method might look (searching for "red"):

red blender ID code: 123 price: $350 sturdy blender perfect for making smoothies and sauces hot air balloon ID code: 345 price: $700 fly into the sky in your own balloon - comes in red, blue or chartreuse 

Here is an example of how the output of the Store::checkOutMember method might look:

giant robot - $7000 Sorry, product #347, "live goat", is no longer available. oak and glass coffee table - $250 Subtotal: $7250 Shipping Cost: $0 Total: $7250 

You must submit these files: Product.cpp, Customer.cpp, and Store.cpp. You do not need to submit the .hpp files. Remember to include your makefile for 10b in the zip file you submit."

Here is my code thus far

Product.hpp

#ifndef PRODUCT_HPP #define PRODUCT_HPP

#include

class Product { private: std::string idCode; std::string title; std::string description; double price; int quantityAvailable; public: Product(std::string id, std::string t, std::string d, double p, int qa); std::string getIdCode(); std::string getTitle(); std::string getDescription(); double getPrice(); int getQuantityAvailable(); void decreaseQuantity(); };

#endif

Product.cpp

#include "Product.hpp"

using std::string;

Product::Product(string id, string t, string d, double p, int qa) { idCode = id; title = t; description = d; price = p; quantityAvailable = qa;

}

string Product::getIdCode() { return idCode; }

string Product::getTitle() { return title; }

string Product::getDescription() { return description; }

double Product::getPrice() { return price; }

int Product::getQuantityAvailable() { return quantityAvailable; }

void Product::decreaseQuantity() { quantityAvailable--; }

Customer.hpp

#ifndef CUSTOMER_HPP #define CUSTOMER_HPP

#include #include "Product.hpp"

class Customer { private: std::vector<:string> cart; std::string name; std::string accountID; bool premiumMember; public: Customer(std::string n, std::string a, bool pm); std::string getAccountID(); std::vector<:string> getCart(); void addProductToCart(std::string); bool isPremiumMember(); void emptyCart(); };

#endif

Customer.cpp

#include "Customer.hpp"

using std::string; using std::vector;

Customer::Customer(string n, string a, bool pm) { name = n; accountID = a; premiumMember = pm;

}

string Customer::getAccountID() { return accountID; }

vector Customer::getCart() { return cart; }

void Customer::addProductToCart(string prodID) { cart.push_back(prodID); //add account ID to cart }

bool Customer::isPremiumMember() { return premiumMember; }

void Customer::emptyCart() { cart.clear(); //clear cart contents }

Store.hpp

#ifndef STORE_HPP #define STORE_HPP

#include #include "Customer.hpp"

class Store { private: std::vector inventory; std::vector members; public: void addProduct(Product* p); void addMember(Customer* c); Product* getProductFromID(std::string); Customer* getMemberFromID(std::string); void productSearch(std::string str); void addProductToMemberCart(std::string pID, std::string mID); void checkOutMember(std::string mID); };

#endif

Store.cpp - i think productSearch is my issue. Also includes main header.

#include "Store.hpp" #include #include #include

using std::string; using std::vector; using std::cout; using std::endl; using std::tolower; using std::locale;

void Store::addProduct(Product * p) { inventory.push_back(p); //add product to inventory }

void Store::addMember(Customer * c) { members.push_back(c); //add customer to members }

Product * Store::getProductFromID(string product) { for (int i = 0; i getIdCode()) == 0) return inventory[i]; }

return NULL; }

Customer * Store::getMemberFromID(string memID) { for (int i = 0; i getAccountID()) == 0) { return members[i]; } } return NULL; }

void Store::productSearch(string str) { cout

string lowerString = firstCharacter + str.substr(1, str.length() - 1); //make lower string for searching

bool found = false; vector productMatched;

for (int i = 0; i getTitle().find(str) != -1 || inventory[i]->getTitle().find(lowerString) != -1 || inventory[i]->getDescription().find(str) != -1 || inventory[i]->getDescription().find(lowerString) != -1) { found = true; productMatched.push_back(i); } } }

void Store::addProductToMemberCart(string pID, string mID) { Product *p = getProductFromID(pID); Customer *c = getMemberFromID(mID); if (p != NULL && c != NULL) { if (p->getQuantityAvailable() > 0) { c->addProductToCart(pID); }

else { cout

void Store::checkOutMember(string mID) { Customer *c = getMemberFromID(mID); double subTotal = 0.0; int numOfItems = 0;

if (c == NULL) { cout

vector cart = c->getCart(); for (int i = 0; i

if (p->getQuantityAvailable() > 0) { cout getTitle() getPrice() getPrice(); numOfItems++; p->decreaseQuantity(); } else { cout getIdCode() getTitle()

if (numOfItems == 0) { cout

double shippingCosts = 0.0; if (c->isPremiumMember() == true) { shippingCosts = 0.0; } else { shippingCosts = .07 * subTotal; } double finalCosts = subTotal + shippingCosts; cout

int main() {

Customer *m = new Customer("John Roger", "Johnl6818", false);

Product *p1 = new Product("mac123", "Macbook", "Macbook Air 15.5' ", 1122.5, 1);

Product *p2 = new Product("air12", "Air Purifier", "Aqua Air Purifier Alpha' ", 11.5, 3);

Product *p3 = new Product("aqua12", "Water Purifier", "Aqua Water Purifier' ", 10, 2);

Store *s = new Store();

s->addMember(m);

s->addProduct(p1);

s->addProduct(p3);

s->addProduct(p2);

s->productSearch("air");

s->addProductToMemberCart(p1->getIdCode(), m->getAccountID());

s->addProductToMemberCart(p2->getIdCode(), m->getAccountID());

s->addProductToMemberCart(p1->getIdCode(), m->getAccountID());

s->checkOutMember(m->getAccountID());

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

1461368332, 978-1461368335

More Books

Students also viewed these Databases questions