Skip to content

Instantly share code, notes, and snippets.

@davidsda
Last active December 2, 2016 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsda/71f30592c6859365403e8742b6100987 to your computer and use it in GitHub Desktop.
Save davidsda/71f30592c6859365403e8742b6100987 to your computer and use it in GitHub Desktop.
#include "Customer.hpp"
#include "Product.hpp"
Customer::Customer(std::string n, std::string a, bool pm)
{
name = n;
accountID = a;
premiumMember = pm;
}
std::string Customer::getAccount()
{
return accountID;
}
std::vector<std::string> Customer::getCart()
{
return cart;
}
bool Customer::isPremiumMember()
{
if(premiumMember == true)
return true;
else(premiumMember == false)
return false;
}
void Customer::addProductToCart(std::string idCode)
{
cart.push_back (idCode);
}
void Customer::emptyCart()
{
cart.clear();
}
#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
#include <string>
#include <vector>
#include <iostream>
#include "Store.hpp"
using namespace std;
int main()
{
string prodID = "11";
string prodT = "Red Chair";
string prodD = "Brown";
double prodP = 21.21;
int prodQ = 3;
Product::Product(string, string, string, double, int);
Store::addProduct();
Customer::addProductToCart();
string cName = "Joe";
string aID = "111";
bool premium = false;
Customer::Customer(string, string, bool);
Store::addMember();
return 0;
}
#include "Product.hpp"
#include <string>
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--;
}
#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
#include <string>
#include <vector>
#include <iostream>
#include "Customer.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 productID)
{
for(int i=0; i<inventory.size(); i++)
{
if (productID == inventory[i].idCode)
return inventory[i];
else
return NULL;
}
}
Customer* Store::getMemberFromID(std::string memberID)
{
for(int j=0; j<members.size(); j++)
{
if (memberID == members[j].accountID)
return members[j];
else
return NULL;
}
}
std::string lower(std:string input)
{
std::string lowCase;
for(int g=0; g<input.size(); g++)
{
std::lowCase[g] = std::input[tolower(g)];
myCopy[g] = lowCase[g];
}
std::string myCopy = std::string(&input);
}
bool findCaseInsensitive(std::string source, std::string query)
{
for(int h=0; h<source.size(); h++)
}
void Store::productSearch(std::string str)
{
for(int k=0; k<inventory.size(); k++)
{
if(inventory.find(str) == inventory[tolower(k)].title || inventory.find(str) == inventory[tolower(k)].description)
std::cout << inventory[k].title << std::endl;
std::cout << inventory[k].idCode << std::endl;
std::cout << inventory[k].price << std::endl;
std::cout << inventory[k].description << std::endl;
}
}
void Store::addProductToMemberCart(std::string pID, std::string mID)
{
if(getProductFromID(pID) != NULL && getMemberFromID(mID) != NULL)
{
if(getQuantityAvailable(pID) > 0)
addProductToMemberCart(pID);
else
std::cout << "Sorry, product #" << idCode << " is currently out of stock." << std::endl;
}
if(getProductFromID(pID) == NULL)
std::cout << "Product #" << idCode << " not found." << std::endl;
if(getMemberFromID(mID) == NULL)
std::cout << "Member #" << accountID << " not found." << std::endl;
}
void Store::checkOutMember(std::string mID)
{
if(getMemberFromID(mID) == NULL)
std::cout << "Member #" << accountID << " not found." << std::endl;
if(inventory.getQuantityAvailable(pID) < 1)
std::cout << "Sorry, product " << idCode << " " << title << " is no longer available." << std::endl;
if(cart.size() = 0)
std::cout << "Cart is empty." << std::endl;
else
for(int l=0; l<cart.size(); l++)
{
std::cout << cart[l].title << std::endl;
std::cout << cart[l].price << std::endl;
inventory.decreaseQuantity();
double cartSum = cart[l].price + cartSum;
}
double shipping;
shipping = 0.00;
if(customer.isPremiumMember() != true)
shipping = cartSum * 0.07;
double totalPrice = shipping + cartSum;
std::cout << "Total Product(s) Price: $" << cartSum << std::endl;
std::cout << "Total Shipping Price: $" << shipping << std::endl;
std::cout << "Total Price, Shipping Included: $" << totalPrice << std::endl;
cart.emptyCart();
}
#include <string>
#include <vector>
#include <iostream>
#include "Customer.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 productID)
{
for(int i=0; i<inventory.size(); i++)
{
if (productID == inventory[i].idCode)
return inventory[i];
else
return NULL;
}
}
Customer* Store::getMemberFromID(std::string memberID)
{
for(int j=0; j<members.size(); j++)
{
if (memberID == members[j].accountID)
return members[j];
else
return NULL;
}
}
std::string lower(std::string input)
{
for(int h=0; h<input.size(); h++)
std::string lowCase;
{
tolower(&input[h]);
std::string myCopy = std::string(&input);
}
return input;
}
void Store::productSearch(std::string str)
{
for(int k=0; k<inventory.size(); k++)
{
if(inventory.find(str) == inventory[tolower(k)].title || inventory.find(str) == inventory[tolower(k)].description)
std::cout << inventory[k].title << std::endl;
std::cout << inventory[k].idCode << std::endl;
std::cout << inventory[k].price << std::endl;
std::cout << inventory[k].description << std::endl;
}
}
void Store::addProductToMemberCart(std::string pID, std::string mID)
{
if(getProductFromID(pID) != NULL && getMemberFromID(mID) != NULL)
{
if(getQuantityAvailable(pID) > 0)
addProductToMemberCart(pID);
else
std::cout << "Sorry, product #" << idCode << " is currently out of stock." << std::endl;
}
if(getProductFromID(pID) == NULL)
std::cout << "Product #" << idCode << " not found." << std::endl;
if(getMemberFromID(mID) == NULL)
std::cout << "Member #" << accountID << " not found." << std::endl;
}
void Store::checkOutMember(std::string mID)
{
if(getMemberFromID(mID) == NULL)
std::cout << "Member #" << accountID << " not found." << std::endl;
if(inventory.getQuantityAvailable(pID) < 1)
std::cout << "Sorry, product " << idCode << " " << title << " is no longer available." << std::endl;
if(cart.size() = 0)
std::cout << "Cart is empty." << std::endl;
else
for(int l=0; l<cart.size(); l++)
{
std::cout << cart[l].title << std::endl;
std::cout << cart[l].price << std::endl;
inventory.decreaseQuantity();
double cartSum = cart[l].price + cartSum;
}
double shipping;
shipping = 0.00;
if(customer.isPremiumMember() != true)
shipping = cartSum * 0.07;
double totalPrice = shipping + cartSum;
std::cout << "Total Product(s) Price: $" << cartSum << std::endl;
std::cout << "Total Shipping Price: $" << shipping << std::endl;
std::cout << "Total Price, Shipping Included: $" << totalPrice << std::endl;
cart.emptyCart();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment