Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

---------------Please read instructions carefully------------------------ You wi

ID: 3862425 • Letter: #

Question

---------------Please read instructions carefully------------------------

You will be writing an online store simulator. It will have three classes: Product, Customer and Store. I am supplying you with the three .hpp files. You will write the three implementation files. (i.e. please write the .cpp files). You should not alter the provided .hpp files.

Here are the .hpp files: Product.hpp, Customer.hpp and Store.hpp -- All 3 have been posted below

--------------------------------------------------------------------------------------------------

Product.hpp

#ifndef PRODUCT_HPP
#define PRODUCT_HPP

#include <string>

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

------------------------------------------------------------------------

Customer.hpp

#ifndef CUSTOMER_HPP
#define CUSTOMER_HPP

#include <vector>
#include "Product.hpp"

class Customer
{
private:
    std::vector<std::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<std::string> getCart();
    void addProductToCart(std::string);
    bool isPremiumMember();
    void emptyCart();
};

#endif

--------------------------------------------------------------------------

Store.hpp

#ifndef STORE_HPP
#define STORE_HPP

#include <string>
#include "Customer.hpp"

class Store
{
private:
    std::vector<Product*> inventory;
    std::vector<Customer*> 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

-----------------------------------------------------------------------------------------

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.

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.

You must submit: Product.cpp, Customer.cpp, and Store.cpp.

In the main method you use for testing, you should only need to #include Store.hpp. Remember that your compile command needs to list all of the .cpp files.

Explanation / Answer

source file for product.hpp

#include "Product.hpp"

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

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

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

}

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

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

int Product::getQuantityAvailable() {
return quantityAvailable
}

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

source file for customer.hpp

#include "Customer.hpp"

Customer :: Customer(std::string n, std::string a, bool pm)
{
name=n;
accountID=a;
premiumMember=pm;
}
std::string Customer :: getAccountID()
{
return accountID;
}
std::vector<std::string> Customer :: getCart()
{
return cart;
}
void Customer :: addProductToCart(std::string a)
{
cart.push_back(a);
}
bool Customer :: isPremiumMember()
{
return premiumMember;
}
void Customer :: emptyCart()
{
cart.clear();
}

source file for store.hpp

#include "Store.hpp"

void Store::addProduct(Product* p) {
inventory.push_back(p);
}

void Store::addMember(Customer* c) {
members.push_back(c);
}

Product* Store::getProductFromID(std::string id) {
for (int i = 0; i < inventory.size(); i++) {
if (inventory.at(i)->getIdCode() == id)
return inventory.at(i);
}
return NULL;
}

Customer* Store::getMemberFromID(std::string id) {
for (int i = 0; i < members.size(); i++) {
if (members.at(i)->getIdCode() == id)
return members.at(i);
}
return NULL;
}

void Store::addProductToMemberCart(std::string pID, std::string mID) {
if (getProductFromID(pID) == NULL) {
std::cout << pID << " Not Found";
} else if (getMemberFromID(mID) == NULL) {
std::cout << mID << " Not Found";
} else {
if (getProductFromID(pID)->getQuantityAvailable() < 1)
std::cout << "Sorry, product " << pID << " is currently out of stock";
else
getMemberFromID(mID)->addProductToCart(pID);
}

}

void Store::checkOutMember(std::string mID) {
if (getMemberFromID(mID) == NULL) {
std::cout << mID << " Not Found";
} else {
double totalcost = 0, subtotal = 0;
std::vector<std::string> cart1 = getMemberFromID(mID)->getCart();
if (cart1.size() != 0) {
for (int i = 0; i < cart1.size(); i++) {
cout << cart1.at(i)->getTitle() << endl;
cout << cart1.at(i)->getPrice() << endl;
subtotal += cart1.at(i)->getPrice();
getProductFromID(cart1.at(i)->getIdCode())->decreaseQuantity();
}
if (getMemberFromID(mID)->isPremiumMember())
totalcost = subtotal;
else
totalcost = subtotal + (subtotal * 0.07);
cout << " Total cost= " << totalcost << endl;
getMemberFromID(mID)->emptyCart();
} else
cout << "There are no items in the cart.";
}

}