Question: I'm having errors when compiling my codes: flip2 ~ 169% g++ Store.cpp Product.cpp Customer.cpp main.cpp Store.cpp: In member function void Store::productSearch(std::string): Store.cpp:93:28: error: class Product
I'm having errors when compiling my codes:
flip2 ~ 169% g++ Store.cpp Product.cpp Customer.cpp main.cpp Store.cpp: In member function void Store::productSearch(std::string): Store.cpp:93:28: error: class Product has no member named getDescription if ((inventory[i]->getDescription()).find (Cstr) != std::string::npos) //I check for a match by seeing if the Cstr is found in the descriptions and checking against npos. if something is found... ^ Store.cpp:98:42: error: class Product has no member named getDescription std::cout << inventory[i] -> getDescription() << std::endl; ^ Store.cpp:111:42: error: class Product has no member named getDescription std::cout << inventory[i] -> getDescription() << std::endl; ^ Store.cpp:127:36: error: class Product has no member named getDescription if ((inventory[i]->getDescription()).find (Lstr) != std::string::npos) //checks for matches in descriptions ^ Store.cpp:132:50: error: class Product has no member named getDescription std::cout << inventory[i] -> getDescription() << std::endl; ^ Store.cpp:145:50: error: class Product has no member named getDescription std::cout << inventory[i] -> getDescription() << std::endl; ^ Product.cpp:24:37: error: no std::string Product::getDescription() member function declared in class Product std::string Product::getDescription() //returns product description ^ Customer.cpp:108:9: error: expected unqualified-id before . token Customer.hpp ^ main.cpp: In function int main(): main.cpp:22:30: error: class Product has no member named getDescription std::cout << blackCherry.getDescription() << std::endl; ^ flip2 ~ 170%
main.cpp ---------------------------- #include
using std::string;
int main() { Store myStore;
Product product1("001", "Giant Robot", "Description for Giant Robot", 6998.35, 2); Product product2("002", "Live Goat", "Just what it sounds like - a goat that is alive.", 695.97, 1); Product product3("003", "red blender", "sturdy blender perfect for making smoothies and sauces", 350, 1); Product product4("004", "hot air ballon", "fly into the sky in your own balloon - comes in red, blue, or chartreuse", 700, 1); Product product5("005", "whoopie cushion", "Perfect for playing jokes on the unsuspecting victim", 5, 2); Product product6("006", "Nintendo Switch", "The hottest console out there - get yours today!", 299.95, 2); Product product7("007", "Destiny 2", "Will be released September 6, 2017.", 60, 2); Product product8("008", "GoPro Hero Black 5", "The hottest action camera out there.", 399, 1); Product product9("009", "Joke Kit", "Includes a whoopie cushion and many more surprises", 45, 10); Product product10("010", "Box of Pencils", "A big box of pencils. You can use them for writing or whatever.", 10, 99);
Product* prod1 = &product1; Product* prod2 = &product2; Product* prod3 = &product3; Product* prod4 = &product4; Product* prod5 = &product5; Product* prod6 = &product6; Product* prod7 = &product7; Product* prod8 = &product8; Product* prod9 = &product9; Product* prod10 = &product10;
myStore.addProduct(prod1); myStore.addProduct(prod2); myStore.addProduct(prod3); myStore.addProduct(prod4); myStore.addProduct(prod5); myStore.addProduct(prod6); myStore.addProduct(prod7); myStore.addProduct(prod8); myStore.addProduct(prod9); myStore.addProduct(prod10);
Customer customer1("Cuyler", "001", true); Customer customer2("Meghan", "002", true); Customer customer3("Beckett", "003", false);
Customer* cust1 = &customer1; Customer* cust2 = &customer2; Customer* cust3 = &customer3;
myStore.addMember(cust1); myStore.addMember(cust2); myStore.addMember(cust3);
myStore.productSearch("red");
myStore.addProductToMemberCart("001", "001"); myStore.addProductToMemberCart("001", "001"); myStore.addProductToMemberCart("001", "001"); myStore.addProductToMemberCart("010", "001"); myStore.addProductToMemberCart("002", "001"); myStore.addProductToMemberCart("999", "004");
myStore.checkOutMember("001"); myStore.checkOutMember("002"); myStore.checkOutMember("004"); } ------------------------------------------------------------------------------------------ Customer.cpp ----------------------------------------
#include
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
void Customer::addProductToCart(string id) { cart.push_back(id); }
bool Customer::isPremiumMember() { if (premiumMember == true) return true; else return false; }
void Customer::emptyCart() { cart.clear(); } ---------------------------------------------------------------------------- Customer.hpp ------------------------------ #ifndef CUSTOMER_HPP #define CUSTOMER_HPP
#include
class Customer { private: std::vector
#endif ----------------------------------------------------------------------- Store.cpp -------------------------- #include
using std::string; using std::vector; using std::toupper; using std::tolower; using std::cout; using std::endl;
void Store::addProduct(Product* p) { inventory.push_back(p); }
void Store::addMember(Customer* c) { members.push_back(c); }
Product* Store::getProductFromID(string id) { Product* matchingProduct = NULL;
for (int count = 0; count < inventory.size(); count++) { if (inventory[count]->getIdCode() == id) { matchingProduct = inventory[count]; } }
return matchingProduct;
}
Customer* Store::getMemberFromID(string id) { Customer* matchingCustomer = NULL;
for (int count = 0; count < members.size(); count++) { if (members[count]->getAccountID() == id) { matchingCustomer = members[count]; } }
return matchingCustomer;
}
void Store::productSearch(string str) { string strUpper = str; string strLower = str;
strUpper[0] = toupper(strUpper[0]); strLower[0] = tolower(strLower[0]);
for (int count = 0; count < inventory.size(); count++) { if (inventory[count]->getTitle().find(strUpper) != string::npos || inventory[count]->getDescription().find(strUpper) != string::npos || inventory[count]->getTitle().find(strLower) != string::npos || inventory[count]->getDescription().find(strLower) != string::npos ) { cout << inventory[count]->getTitle() << endl; cout << "ID Code: " << inventory[count]->getIdCode() << endl; cout << "Price: $" << inventory[count]->getPrice() << endl; cout << inventory[count]->getDescription() << endl; cout << endl; } } }
void Store::addProductToMemberCart(string pID, string mID) { Product* product = getProductFromID(pID); Customer* member = getMemberFromID(mID);
if (product) { if (member) { if (product->getQuantityAvailable() > 0) { member->addProductToCart(pID); } else { cout << "Sorry, product #" << pID << " is currently out of stock." << endl; } } }
if (!product) cout << "Product #" << pID << " not found." << endl; if (!member) cout << "Member #" << mID << " not found." << endl; }
void Store::checkOutMember(string mID) { Customer* member = getMemberFromID(mID); double shippingCostPercentage = 0.07; double cartSubtotal = 0;
if (!member) { cout << "Member #" << mID << " not found." << endl; } else { if (member->isPremiumMember()) shippingCostPercentage = 0;
if (member->getCart().empty()) { cout << "There are no items in the cart." << endl; } else { for (int count = 0; count < member->getCart().size(); count++) { Product* product = getProductFromID(member->getCart()[count]);
if (product->getQuantityAvailable() > 0) { cout << product->getTitle() << " - $" << product->getPrice() << endl; cartSubtotal += product->getPrice(); product->decreaseQuantity(); } else { cout << "Sorry, product #" << product->getIdCode() << ", \"" << product->getTitle() << "\", is no longer available." << endl; } } double shippingCost = cartSubtotal * shippingCostPercentage;
cout << "Subtotal: $" << std::fixed << std::setprecision(2) << cartSubtotal << endl; cout << "Shipping Cost: $" << std::fixed << std::setprecision(2) << shippingCost << endl; cout << "Total: $" << cartSubtotal + shippingCost << endl; member->emptyCart(); } } } ------------------------------------------------------------------------ Store.hpp ------------------------------------ #ifndef STORE_HPP #define STORE_HPP
#include
class Store { private: std::vector
#endif ------------------------------------------------------------------------- Product.cpp ------------------------------------------- #include
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--; } ------------------------------------------------------------------- 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
