Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I update my checkOutMember function so that is shows Sorry, product# is no longer available in the output for checkoutMember? I can't

How do I update my checkOutMember function so that is shows "Sorry, product#" " is no longer available" in the output for checkoutMember? I can't figure out where my problem is and need this to print right above or below "

giant robot - $7000" 

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 

Here is my code:

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 cart; std::string name; std::string accountID; bool premiumMember; public: Customer(std::string n, std::string a, bool pm); std::string getAccountID(); std::vector 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 & main with the checkoutMember function

#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 }

/********************************************************************* ** Description: Adds a customer to the members. *********************************************************************/ 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

for (int i = 0; i getTitle().find(searchLower)) != string::npos || (inventory[i]->getDescription().find(searchLower)) != string::npos || (inventory[i]->getTitle().find(searchUpper)) != string::npos || (inventory[i]->getDescription().find(searchUpper)) != string::npos) { std::cout getTitle() getIdCode() getPrice() getDescription()

void Store::addProductToMemberCart(string pID, string mID) { Product *p = getProductFromID(pID); Customer *c = getMemberFromID(mID); if (p != NULL && c != NULL) { //if quantity is greater than zero, add prod to cart. if (p->getQuantityAvailable() > 0) { c->addProductToCart(pID); }

else { cout

void Store::checkOutMember(string mID) {

Customer *c = getMemberFromID(mID);

if (c == NULL) { //if no customer found cout

vector cart = c->getCart(); double subTotal = 0.0; int numOfItems = 0; for (int i = 0; i

if (p->getQuantityAvailable() getIdCode() getTitle() getTitle() getPrice() getPrice(); numOfItems++; p->decreaseQuantity(); } }

if (numOfItems == 0) { cout

double shippingCosts = 0.0; if (c->isPremiumMember() == true) { //if premium member, no shiping costs associated. shippingCosts = 0.0; } else { //shipping costs are 7% for non-members. shippingCosts = .07 * subTotal; } double finalCosts = subTotal + shippingCosts; cout

}

int main() {

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

Product *p1 = new Product("123", "red blender", "sturdy blender perfect for making smoothies and sauces", 350, 1);

Product *p2 = new Product("345", "hot air balloon", "fly into the sky in your own balloon - comes in red, blue or chartreuse ", 700, 3);

Product *p3 = new Product("346", "giant robot", "a big robot", 7000, 2);

Product *p4 = new Product("347", "live goat", "a big goat", 200, 0);

Store *s = new Store();

s->addMember(m);

s->addProduct(p1);

s->addProduct(p2);

s->addProduct(p3);

s->addProduct(p4);

s->productSearch("red");

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

s->addProductToMemberCart(p3->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

More Books

Students also viewed these Databases questions

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago