Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit…..

Using C++

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. (BELOW)

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

Expert Answer

 

Screenshot of the code:

Product.cpp:

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 1

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 2

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 3

Customer.cpp:

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 4

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 5

Store.cpp:

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 6

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 7

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 8

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 9

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 10

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 11

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 12

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 13

Sample output:

Question & Answer: store simulator. It will have three classes: Product, Customer and Store. To make things a lit..... 14

Code to copy:

Product.cpp:

// Use this header file if you are using the visual studio.

#include “stdafx.h”

// include the product header file.

#include “Product.h”

// constructor to add the product deatail in the list.

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;

}

// functio to get the price of the product.

double Product::getPrice()

{

return price;

}

// function to get the quantity available.

int Product::getQuantityAvailable() {

return quantityAvailable;

}

// function to decrease the quantity og ther

// product in the store.

void Product::decreaseQuantity() {

quantityAvailable -= 1;

}

// function to get the id code of the customer.

std::string Product::getIdCode()

{

return idCode;

}

// funtion to get the titele of the product.

std::string Product::getTitle() {

return title;

}

// fuction to get the description if the product.

std::string Product::getDescription() {

return description;

}

Customer.cpp:

// Use this header file if you are using the visual studio.

#include “stdafx.h”

#include “Customer.h”

// function to add the details of the customer.

Customer::Customer(std::string n, std::string a, bool pm)

{

name = n;

accountID = a;

premiumMember = pm;

}

// function to add the product to the cart.

void Customer::addProductToCart(std::string id) {

cart.push_back(id);

}

// function to check if the item is premium.

bool Customer::isPremiumMember() {

return premiumMember;

};

// function to empty the cart.

void Customer::emptyCart() {

cart.clear();

};

// function to get the acccount id.

std::string Customer::getAccountID()

{

return accountID;

}

// function to get the cart.

std::vector<std::string>Customer::getCart() {

return cart;

};

Store.cpp:

// Use this header file if you are using the visual studio.

#include “stdafx.h”

#include “Store.h”

#include <iostream>

// function to add a product to the inventory of the store class.

void Store::addProduct(Product *product)

{

inventory.push_back(product);

}

// add a customer to the member of store class

void Store::addMember(Customer *cuctomer)

{

members.push_back(cuctomer);

}

// function to add the data to the member.

void Store::addProductToMemberCart(std::string productID, std::string memberID)

{

// delare some local variable to add the product.

bool inStore = false;

bool inMember = false;

bool inStock = false;

int itemLocation = -1;

int memberLocation = -1;

double invSize = inventory.size();

double memberSize = members.size();

// Check if item is avail in the store

for (int i = 0; i < invSize; i++)

{

if (inventory[i]->getIdCode() == productID)

{

inStore = true;

itemLocation = i;

if (inventory[i]->getQuantityAvailable() > 0)

{

inStock = true;

}

}

}

// use for loop to search the item in the memebr of store.

for (int j = 0; j < memberSize; j++)

{

if (members[j]->getAccountID() == memberID)

{

inMember = true;

memberLocation = j;

}

}

if (inMember && inStock && inStore)

{

members[memberLocation]->addProductToCart(memberID);

}

// if the customer is member.

else if (!inMember)

{

std::cout << “Sorry you are not a member.” << std::endl;

}

 

// check if the item is in inventory.

else if (!inStore)

{

std::cout << “Sorry, the item you are looking for is not in our store” << std::endl;

}

else if (!inStock)

{

std::cout << “Sorry, product #” << inventory[itemLocation]->getIdCode()

<< ” is currently out of stock.” << std::endl;

}

else

{

std::cout << “Sorry, an error has occurred, try again.” << std::endl;

}

}

// function to check out the member.

void Store::checkOutMember(std::string memberID)

{

int mSize = members.size();

bool exists = false;

double totalCost = 0;

double shipping = 0;

// use for loop to find the member id in the memebr data store.

for (int i = 0; i < mSize; i++)

{

if (members[i]->getAccountID() == memberID) {

exists = true;

 

double cartSize = members[i]->getCart().size();

 

if (cartSize == 0)

{

std::cout << “There are no items in the cart.” << std::endl;

}

else

{

// use for loop to search each item in the cart.

for (int j = 0; j < cartSize; j++)

{

// search the matching item in entire inventory.

for (int k = 0; k < inventory.size(); k++)

{

// check if the inventory item is present.

if (inventory.at(k)->getIdCode() == members[i]->getCart().at(j))

{

// check if the item is in the stock.

if (inventory.at(k)->getQuantityAvailable() < 1)

{

std::cout << “Sorry, product #” << inventory.at(k)->getIdCode()

<< “, ” << inventory.at(k)->getTitle() << ” is no longer available”

<< std::endl;

}

// if the item is not avail in the stock.

else

{

std::cout << inventory.at(k)->getTitle() << ” – $”

<< inventory.at(k)->getPrice() << std::endl;

// add the price to the total and decrease the item from the stock

totalCost += inventory.at(k)->getPrice();

inventory.at(k)->decreaseQuantity();

}

}

}

}

// check if the user is premier member.

if (members[i]->isPremiumMember())

{

shipping = 0;

}

else

{

shipping = totalCost * 0.07;

}

// print all the price deatails.

std::cout << “Subtotal: $” << totalCost << std::endl;

std::cout << “Shipping: $” << shipping << std::endl;

std::cout << “Total: $” << totalCost + shipping << std::endl;

// empty the cart when all the calculation done.

members[i]->emptyCart();

}

}

}

// check if the data member is not exist.

if (!exists)

{

std::cout << “Member #” << memberID << ” not found.” << std::endl;

}

}

// returns pointer to product if the id is matches.

// Returns NULL if the id is not matching with the anyone.

Product *Store::getProductFromID(std::string item)

{

for (int i = 0; i < inventory.size(); i++)

{

if (item == inventory[i]->getIdCode())

{

return inventory[i];

}

}

return NULL;

}

 

// returns pointer to customer if the id matches.

// and if id not matches it returns null.

Customer *Store::getMemberFromID(std::string str)

{

for (int i = 0; i < members.size(); i++)

{

// check If the ID is equivalent to the customer query

if (str == members[i]->getAccountID())

{

// return the pointer to the member

return members[i];

}

}

return NULL;

}

// function to search the product.

void Store::productSearch(std::string str)

{

// declare a boolean variable.

bool exists = false;

// declare a variable to find the size of the inventory.

double invSize = inventory.size();

for (int i = 0; i < invSize; i++)

{

// set the first letter smaller.

std::string itemTitle = inventory.at(i)->getTitle();

itemTitle[0] = tolower(itemTitle[0]);

// Set the first letter smaller.

std::string itemDesc = inventory.at(i)->getDescription();

itemDesc[0] = tolower(itemDesc[0]);

str[0] = tolower(str[0]);

if (itemTitle.find(str) != std::string::npos || itemDesc.find(str) != std::string::npos)

{

exists = true;

std::cout << inventory[i]->getTitle() << std::endl;

std::cout << “ID Code: ” << inventory[i]->getIdCode() << std::endl;

std::cout << “Price: $” << inventory[i]->getPrice() << std::endl;

std::cout << inventory[i]->getDescription() << std::endl;

std::cout << “n”;

}

}

// if the inventory item does not exist.

if (!exists)

{

std::cout << “There are no items that match this search. Try again!n” << std::endl;

}

}

Still stressed from student homework?
Get quality assistance from academic writers!