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

PLEASE write in basic c++ code PLEASE DO NOT USE #include <algorithm> , #include

ID: 3730629 • Letter: P

Question


PLEASE write in basic c++ code
PLEASE DO NOT USE #include <algorithm> , #include <locale> , #include <cstlib> , or .reserve() in any .cpp or .hpp file
PLEASE exactly copy the .hpp files member variables and functions to create the .cpp files
PLEASE include comments (especially for Store.cpp)
PLEASE include a main function file for testing purposes
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.
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
#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
Store.hpp
#ifndef STORE_HPP
#define STORE_HPP
#include
#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);
std::vector productSearch(std::string str);
std::string addProductToMemberCart(std::string pID, std::string mID);
double 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 - return a sorted vector of ID codes for every product whose title or description contains the search string. 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 (Links to an external site.)Links to an external site.. You may assume that the search string will consist of a single word.
addProductToMemberCart - If the product isn't found in the inventory, return "product ID not found". If the member isn't found in the members, return "member ID not found". If both are found and the product is still available, call the member's addProductToCart method to add the product and then return "product added to cart". If the product was not still available, return "product out of stock". This function does not need to check how many of that product are available - just that there is at least one. It should also not change how many are available - that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.
checkOutMember - If the member ID isn't found, return -1. Otherwise return the charge for the member's cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that's available, but won't be able to buy a second one, because it's now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member's cart has been tabulated, the member's cart should be emptied, and the charge amount returned.
  
You must submit these files: Product.cpp, Customer.cpp, and Store.cpp. You do not need to submit the .hpp files.
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.
PLEASE write in basic c++ code
PLEASE DO NOT USE #include <algorithm> , #include <locale> , #include <cstlib> , or .reserve() in any .cpp or .hpp file
PLEASE exactly copy the .hpp files member variables and functions to create the .cpp files
PLEASE include comments (especially for Store.cpp)
PLEASE include a main function file for testing purposes
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.
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
#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
Store.hpp
#ifndef STORE_HPP
#define STORE_HPP
#include
#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);
std::vector productSearch(std::string str);
std::string addProductToMemberCart(std::string pID, std::string mID);
double 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 - return a sorted vector of ID codes for every product whose title or description contains the search string. 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 (Links to an external site.)Links to an external site.. You may assume that the search string will consist of a single word.
addProductToMemberCart - If the product isn't found in the inventory, return "product ID not found". If the member isn't found in the members, return "member ID not found". If both are found and the product is still available, call the member's addProductToCart method to add the product and then return "product added to cart". If the product was not still available, return "product out of stock". This function does not need to check how many of that product are available - just that there is at least one. It should also not change how many are available - that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.
checkOutMember - If the member ID isn't found, return -1. Otherwise return the charge for the member's cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that's available, but won't be able to buy a second one, because it's now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member's cart has been tabulated, the member's cart should be emptied, and the charge amount returned.
  
You must submit these files: Product.cpp, Customer.cpp, and Store.cpp. You do not need to submit the .hpp files.
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.
PLEASE write in basic c++ code
PLEASE DO NOT USE #include <algorithm> , #include <locale> , #include <cstlib> , or .reserve() in any .cpp or .hpp file
PLEASE exactly copy the .hpp files member variables and functions to create the .cpp files
PLEASE include comments (especially for Store.cpp)
PLEASE include a main function file for testing purposes
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.
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
#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
Store.hpp
#ifndef STORE_HPP
#define STORE_HPP
#include
#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);
std::vector productSearch(std::string str);
std::string addProductToMemberCart(std::string pID, std::string mID);
double 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 - return a sorted vector of ID codes for every product whose title or description contains the search string. 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 (Links to an external site.)Links to an external site.. You may assume that the search string will consist of a single word.
addProductToMemberCart - If the product isn't found in the inventory, return "product ID not found". If the member isn't found in the members, return "member ID not found". If both are found and the product is still available, call the member's addProductToCart method to add the product and then return "product added to cart". If the product was not still available, return "product out of stock". This function does not need to check how many of that product are available - just that there is at least one. It should also not change how many are available - that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.
checkOutMember - If the member ID isn't found, return -1. Otherwise return the charge for the member's cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that's available, but won't be able to buy a second one, because it's now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member's cart has been tabulated, the member's cart should be emptied, and the charge amount returned.
  
You must submit these files: Product.cpp, Customer.cpp, and Store.cpp. You do not need to submit the .hpp files.
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. PLEASE write in basic c++ code
PLEASE DO NOT USE #include <algorithm> , #include <locale> , #include <cstlib> , or .reserve() in any .cpp or .hpp file
PLEASE exactly copy the .hpp files member variables and functions to create the .cpp files
PLEASE include comments (especially for Store.cpp)
PLEASE include a main function file for testing purposes
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.
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 #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
#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
Store.hpp
#ifndef STORE_HPP
#define STORE_HPP
#include
#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);
std::vector productSearch(std::string str);
std::string addProductToMemberCart(std::string pID, std::string mID);
double 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 - return a sorted vector of ID codes for every product whose title or description contains the search string. 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 (Links to an external site.)Links to an external site.. You may assume that the search string will consist of a single word.
addProductToMemberCart - If the product isn't found in the inventory, return "product ID not found". If the member isn't found in the members, return "member ID not found". If both are found and the product is still available, call the member's addProductToCart method to add the product and then return "product added to cart". If the product was not still available, return "product out of stock". This function does not need to check how many of that product are available - just that there is at least one. It should also not change how many are available - that happens during checkout. The same product can be added multiple times if the customer wants more than one of something.
checkOutMember - If the member ID isn't found, return -1. Otherwise return the charge for the member's cart. This will be the total cost of all the items in the cart, not including any items that are not in the inventory or are out of stock, plus the shipping cost. If a product is not out of stock, you should add its cost to the total and decrease the available quantity of that product by 1. Note that it is possible for an item to go out of stock during checkout. For example, if the customer has two of the same product in their cart, but the store only has one of that product left, the customer will be able to buy the one that's available, but won't be able to buy a second one, because it's now out of stock. For premium members, the shipping cost is $0. For normal members, the shipping cost is 7% of the total cost of the items in the cart. When the charge for the member's cart has been tabulated, the member's cart should be emptied, and the charge amount returned.
  
You must submit these files: Product.cpp, Customer.cpp, and Store.cpp. You do not need to submit the .hpp files.
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

#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include "Store.hpp"

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

// This program tests the functionality of the Store,
// Product and Customer implementation files.
int main()
{
   // create some products
   Product p1( "1", "Product1", "this is product 1",
           5.0, 2);
   Product p2( "2", "Product2", "This is product 2",
           3.99, 3);
   Product p3( "3", "Product3", "This is product 3",
           5.75, 1);
   Product p4( "4", "product4", "this is product 4",
           .5, 2);
   Product p5( "5", "product5", "this is product 5",
           5.1, 0);
   Product p6( "6", "product6", "this is product 6",
           20.25, 5);

   // create some customers
   Customer c1( "Jane Doe", "12345", false );
   Customer c2( "John Doe", "12346", true );
   Customer c3( "Lt Ripley", "01234", true );

   // create a store
   Store s1;

   // add inventory to the store
   s1.addProduct( &p1 );
   s1.addProduct( &p2 );
   s1.addProduct( &p3 );
   s1.addProduct( &p4 );
   s1.addProduct( &p5 );

   // add customers to the store
   s1.addMember( &c1 );
   s1.addMember( &c2 );

   // search for some products
   string searchTerms[5] = {"product1", "product",
       "Duct4", "Product6", "This"};

   vector<string> searchResults;
   for( string str : searchTerms )
   {
       searchResults = s1.productSearch( str );
       cout << "Your search for "" + str + "" returned the";
       cout << " following results: " << endl << endl;

       for( string s : searchResults )
       {
           cout << s << endl;
       }
   }

   // add some products to your shopping cart
   cout << "NOW WE WILL TEST ADDING PRODUCTS TO SHOPPING CARTS" << endl << endl;

   cout << "This test should not find any products..." << endl;
   cout << s1.addProductToMemberCart( p6.getIdCode(), c1.getAccountID() ) << endl << endl;

   cout << endl << "This test should not find any products..." << endl;
   cout << s1.addProductToMemberCart( "999999", c1.getAccountID() ) << endl << endl;

   cout << endl << "This test should not find any customers..." << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), c3.getAccountID() ) << endl << endl;

   cout << endl << "This test should not find any customer..." << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), "23232323" ) << endl << endl;

   cout << endl << "This test should return an out of stock message..." << endl;
   cout << s1.addProductToMemberCart( p5.getIdCode(), c2.getAccountID() ) << endl << endl;

   cout << endl << "This test should add products to the cart of a non premium member..." << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), c1.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), c1.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), c1.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p2.getIdCode(), c1.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p3.getIdCode(), c1.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p4.getIdCode(), c1.getAccountID() ) << endl << endl;

   // checkout the non premium member
   double cartTotal = s1.checkOutMember( c1.getAccountID() );
   cout << "The cart total for the non premium member should be 21.6568. The actual total is: " << cartTotal << endl << endl;
   cout << "The qty available for p1 should be 0. The qty available is: " << p1.getQuantityAvailable() << endl;
   cout << "The qty available for p2 should be 2. The qty available is: " << p2.getQuantityAvailable() << endl;
   cout << "The qty available for p3 should be 0. The qty available is: " << p3.getQuantityAvailable() << endl;
   cout << "The qty available for p4 should be 1. The qty available is: " << p4.getQuantityAvailable() << endl << endl;

   cout << endl << "This test should return an out of stock message since the product";
   cout << " just went out of stock after the previous customer checked out..." << endl;
   cout << s1.addProductToMemberCart( p1.getIdCode(), c2.getAccountID() ) << endl << endl;

   cout << endl << "This test should add products to the cart of a premium member..." << endl;
   cout << s1.addProductToMemberCart( p2.getIdCode(), c2.getAccountID() ) << endl;
   cout << s1.addProductToMemberCart( p4.getIdCode(), c2.getAccountID() ) << endl;

   // checkout the premium member
   cartTotal = s1.checkOutMember( c2.getAccountID() );
   cout << "The cart total for the premium member should be 4.49. The actual total is: " << cartTotal << endl << endl;
   cout << "The qty available for p2 should be 1. The qty available is: " << p2.getQuantityAvailable() << endl;
   cout << "The qty available for p4 should be 0. The qty available is: " << p4.getQuantityAvailable() << endl;


   // checkout nonexistent member
   cartTotal = s1.checkOutMember( c3.getAccountID() );
   cout << "This test should return -1 because the member is not found. Returned value: " << cartTotal << endl;
}


Customer.cpp


#include "Customer.hpp"
using std::string;
using std::vector;

/******************************************************
** Description: Constructor that takes as parameters
** three values with which to initialize the name,
** id and whether the customer is a premium member.
******************************************************/
Customer::Customer( string custName, string id,
            bool premiumMem )
{
   name = custName;
   accountID = id;
   premiumMember = premiumMem;
}

/******************************************************
** Description: Method that returns whether the
** customer is a premium member.
******************************************************/
bool Customer::isPremiumMember()
{
   if( premiumMember )
       return true;
   else
       return false;
}

/******************************************************
** Description: Method that adds the prod ID code to
** the customer's cart.
******************************************************/
void Customer::addProductToCart( string productID )
{
   cart.push_back( productID );
}

/******************************************************
** Description: Method that empties the customer's
** cart.
******************************************************/
void Customer::emptyCart()
{
   if( !( cart.empty() ) )
       cart.clear();
}

/******************************************************
** Description: Getters
******************************************************/
vector<string> Customer::getCart()
{
   return cart;
}

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

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

Product.cpp


#include "Product.hpp"
using std::string;

/******************************************************
** Description: Constructor that takes as parameters
** five values with which to initialize the Product's
** idCode, title, description, price and quantity
** available.
******************************************************/
Product::Product( string prodId, string prodTitle,
       string prodDesc, double prodPrice,
            int prodQuantity )
{
   idCode = prodId;
   title = prodTitle;
   description = prodDesc;
   price = prodPrice;
   quantityAvailable = prodQuantity;
}

/******************************************************
** Description: Method that decreases the quantity
** available by one
******************************************************/
void Product::decreaseQuantity()
{
   quantityAvailable--;
}

/******************************************************
** Description: Getters
******************************************************/
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;
}

Store.cpp


#include "Store.hpp"
#include <algorithm>
#include <iostream>
#include <vector>
#include <cctype>

using std::string;
using std::vector;
using std::sort;
using std::cout;
using std::endl;

/******************************************************
** Description: Method that adds a product to the
** inventory.
******************************************************/
void Store::addProduct( Product* p )
{
   if( p != nullptr )
       inventory.push_back( p );
   else
       cout << "null pointer" << endl;
}

/******************************************************
** Description: Method that adds a customer to the
** members.
******************************************************/
void Store::addMember( Customer* c )
{
   if( c != nullptr )
       members.push_back( c );
   else
       cout << "null pointer" << endl;
}

/******************************************************
** Description: Method that returns a pointer to a
** product with a matching ID if one is found. If none
** is found, then it returns NULL.
******************************************************/
Product* Store::getProductFromID( string id )
{
   Product* product = NULL;
   bool breakLoop = false;

   for( int i = 0; i < inventory.size() && !breakLoop; i++ )
   {
       if( inventory[i]->getIdCode() == id )
       {
           product = inventory[i];
           breakLoop = true;
       }
   }

   return product;
}

/******************************************************
** Description: Method that returns a pointer to a
** customer with a matching ID if one is found. If one
** is not found, then it returns NULL.
******************************************************/
Customer* Store::getMemberFromID( string id )
{
   Customer* customer = NULL;
   bool breakLoop = false;

   for( int i = 0; i < members.size() && !breakLoop; i++ )
   {
       if( members[i]->getAccountID() == id )
       {
           customer = members[i];
           breakLoop = true;
       }
   }

   return customer;
}

/******************************************************
** Description: Method that returns a sorted vector
** of ID codes for every product whose title or
** description contains the search string.
******************************************************/
vector<string> Store::productSearch( string str )
{
   static const size_t npos = -1;

   // vector of strings to store search results
   vector<string> searchResults;

   // create another search string
   string str2 = str;

   // set str to have a lower case first char
   // set str2 to have an upper case first char
   str[0] = tolower( str[0] );
   str2[0] = toupper( str2[0] );

   for( Product* p : inventory )
   {
       string title = p->getTitle();

       string desc = p->getDescription();

       // if search string is found add the id to the search results
       if( ( title.find( str ) != npos ) ||
               ( title.find( str2 ) != npos ) ||
               ( desc.find( str ) != npos ) ||
               ( desc.find( str2 ) != npos ) )
       {
           searchResults.push_back( p->getIdCode() );
       }

       // sort the vector
       sort( searchResults.begin(), searchResults.begin() + searchResults.size() );
   }

   return searchResults;
}

/******************************************************
** Description: Method that adds a product to the
** member's cart, if both the product and member are
** found.
******************************************************/
string Store::addProductToMemberCart( string pID,
       string mID )
{
   // declare some variables
   string returnedMessage = "";

   // get the product and the member
   Product* p = getProductFromID( pID );
   Customer* c = getMemberFromID( mID );

   if( ( p != NULL ) && ( c != NULL ) && ( p->getQuantityAvailable() > 0 ) )
   {
       c->addProductToCart( pID );
       returnedMessage = "product added to cart";
   }
   else if( ( p != NULL ) && ( c != NULL ) && ( p->getQuantityAvailable() == 0 ) )
   {
       returnedMessage = "product out of stock";
   }
   else if( p == NULL )
   {
       returnedMessage = "product ID not found";
   }
   else if( c == NULL )
   {
       returnedMessage = "member ID not found";
   }

   return returnedMessage;
}

/******************************************************
** Description: Method that returns the total charge
** of the cart. Charge includes the sum of all in
** stock items and shipping.
******************************************************/
double Store::checkOutMember( string mID )
{
   // declare your variables
   double cartTotal = 0.0;
   double shipping = 0.0;

   // get member
   Customer* c = getMemberFromID( mID );

   if( c == NULL )
   {
       cartTotal = -1;
   }
   else
   {
       // get the member's cart
       vector<string> cart = c->getCart();

       // sum each in stock item
       for( string id : cart )
       {
           Product* p = getProductFromID( id );

           if( p->getQuantityAvailable() > 0 )
           {
               cartTotal += p->getPrice();
               p->decreaseQuantity();
           }  
       }

       // calculate shipping and add to cart total
       if ( !(c->isPremiumMember()) )
       {
           shipping = .07 * cartTotal;
       }

       // calculate cart total with shipping
       cartTotal += shipping;

       // empty cart
       c->emptyCart();
   }

   return cartTotal;
}

Store.hpp

#ifndef STORE_HPP
#define STORE_HPP

#include <vector>
#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);
    std::vector<std::string> productSearch(std::string str);
    std::string addProductToMemberCart(std::string pID, std::string mID);
    double checkOutMember(std::string mID);
};

#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote