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

How do I get the following output to display? \" Here is an example of how the o

ID: 3847186 • Letter: H

Question

How do I get the following output to display?

"

Here is an example of how the output of the Store::checkOutMember method might look:

I need to update my checkoutMember to display the line "

Subtotal: $7000

Shipping Costs: $0

Final Costs: $7000

Here is my Store.cpp & Main


#include "Store.hpp"
#include <iostream>
#include <string>
#include <locale>

using std::string;
using std::vector;
using std::cout;
using std::endl;
using std::tolower;
using std::locale;


void Store::addProduct(Product * p)
{
   inventory.push_back(p); //add product to inventory
}

/*********************************************************************
** Description: Adds a customer to the members.
*********************************************************************/
void Store::addMember(Customer * c)
{
   members.push_back(c); //add customer to members
}

Product * Store::getProductFromID(string product)
{
   for (int i = 0; i < inventory.size(); i++)
   {
       //check if product ID matches product in inv
       if (product.compare(inventory[i]->getIdCode()) == 0)
           return inventory[i];
   }

return NULL;
}

Customer * Store::getMemberFromID(string memID)
{
   for (int i = 0; i < members.size(); i++)
   {
       //check if member ID matches any member of store
       if (memID.compare(members[i]->getAccountID()) == 0)
       {
           return members[i];
       }
   }
   return NULL;
}

/*********************************************************************
** Description: For every product whose title/description contains
** search string, proint out product's title, ID code, price, and description - case insensitive.
*********************************************************************/
void Store::productSearch(string str)
{
   cout << "****Search Results****" << endl;
   string searchLower = str;
   string searchUpper = str;
   searchLower[0] = tolower(searchLower[0]);
   searchUpper[0] = toupper(searchUpper[0]);

   for (int i = 0; i < inventory.size(); i++) {
       if ((inventory[i]->getTitle().find(searchLower)) != string::npos ||
           (inventory[i]->getDescription().find(searchLower)) != string::npos ||
           (inventory[i]->getTitle().find(searchUpper)) != string::npos ||
           (inventory[i]->getDescription().find(searchUpper)) != string::npos) {
           cout << inventory[i]->getTitle() << std::endl;
           cout << "ID code: " << inventory[i]->getIdCode() << endl;
           cout << "price: $" << inventory[i]->getPrice() << endl;
           cout << inventory[i]->getDescription() << endl << endl;
       }
   }
}


void Store::addProductToMemberCart(string pID, string mID)
{
   Product *p = getProductFromID(pID);
   Customer *c = getMemberFromID(mID);

   if (p != NULL && c != NULL)
   {
       //if quantity is greater than zero, add prod to cart.
       if (p->getQuantityAvailable() > 0)
       {
           c->addProductToCart(pID);
       }

       else
       {
           cout << "Sorry, product #[" << pID << "] is currently out of stock." << endl;
       }
   }
   else
   {
       if (p == NULL)
       {
           cout << "Product #[" << pID << "] not found." << endl;
       }
       if (c == NULL)
       {
           cout << "Member #" << mID << "] not found." << endl;
       }
   }
}


void Store::checkOutMember(string mID)
{

   Customer *c = getMemberFromID(mID);
   double subTotal = 0.0;
   int numOfItems = 0;

   if (c == NULL)
   {
       //if no customer found
       cout << "Member #[" << mID << "] not found." << endl;
   }
   else
   {
       cout << " ****Cart for Checkout**** " << endl;

       vector<string> cart = c->getCart();
       if (cart.size()) == 0)
       {
       cout << "There are no items in the cart." << endl;
       }
       else
      
       for (int i = 0; i < cart.size(); i++)
       {
           Product *p = getProductFromID(cart[i]);


           if (p->getQuantityAvailable() < 1)
           {
               //if product is not found //why doesn't this work for live goat???
               cout << "Sorry, product #" << p->getIdCode() << ", " <<
                   "'" << p->getTitle() << "', is no longer available." << endl;
           }

          
           else
           {
               //print out title and price and decrease quantity.
               cout << "Title: " << p->getTitle() << ", Price: " << p->getPrice() << endl;
               subTotal += p->getPrice();
               numOfItems++;
               p->decreaseQuantity();
           }
             
       }

       if (numOfItems == 0)
       {
           cout << "There are no items in the cart." << endl;
           return;
       }

       double shippingCosts = 0.0;
       if (c->isPremiumMember() == true)
       {
           //if premium member, no shiping costs associated.
           shippingCosts = 0.0;
       }
       else
       {
           //shipping costs are 7% for non-members.
           shippingCosts = .07 * subTotal;
       }
      
       double finalCosts = subTotal + shippingCosts;
      
       cout << "Subtotal: $" << subTotal << endl << "Shipping Costs:$" << shippingCosts << endl
           << "Final Costs:$" << finalCosts << endl;
   }

}


int main() {

   Customer *m = new Customer("John Roger", "Johnl6818", true);

   Product *p1 = new Product("123", "red blender", "sturdy blender perfect for making smoothies and sauces", 350, 1);

   Product *p2 = new Product("345", "hot air balloon", "fly into the sky in your own balloon - comes in red, blue or chartreuse ",
       700.25, 3);

   Product *p3 = new Product("346", "giant robot", "a big robot", 7000, 2);

   Product *p4 = new Product("347", "live goat", "a big goat", 200, 0);

   Store *s = new Store();

   s->addMember(m);

   s->addProduct(p1);

   s->addProduct(p2);

   s->addProduct(p3);

   s->addProduct(p4);

   s->productSearch("red");

   s->addProductToMemberCart(p4->getIdCode(), m->getAccountID());

   s->addProductToMemberCart(p3->getIdCode(), m->getAccountID());


   s->checkOutMember(m->getAccountID());


   return 0;

}

Explanation / Answer

#include "Store.hpp"
#include <iostream>
#include <string>
#include <locale>
using std::string;
using std::vector;
using std::cout;
using std::endl;
using std::tolower;
using std::locale;

void Store::addProduct(Product * p)
{
inventory.push_back(p); //add product to inventory
}
/*********************************************************************
** Description: Adds a customer to the members.
*********************************************************************/
void Store::addMember(Customer * c)
{
members.push_back(c); //add customer to members
}
Product * Store::getProductFromID(string product)
{
for (int i = 0; i < inventory.size(); i++)
{
//check if product ID matches product in inv
if (product.compare(inventory[i]->getIdCode()) == 0)
return inventory[i];
}
return NULL;
}
Customer * Store::getMemberFromID(string memID)
{
for (int i = 0; i < members.size(); i++)
{
//check if member ID matches any member of store
if (memID.compare(members[i]->getAccountID()) == 0)
{
return members[i];
}
}
return NULL;
}
/*********************************************************************
** Description: For every product whose title/description contains
** search string, proint out product's title, ID code, price, and description - case insensitive.
*********************************************************************/
void Store::productSearch(string str)
{
cout << "****Search Results****" << endl;
string searchLower = str;
string searchUpper = str;
searchLower[0] = tolower(searchLower[0]);
searchUpper[0] = toupper(searchUpper[0]);
for (int i = 0; i < inventory.size(); i++) {
if ((inventory[i]->getTitle().find(searchLower)) != string::npos ||
(inventory[i]->getDescription().find(searchLower)) != string::npos ||
(inventory[i]->getTitle().find(searchUpper)) != string::npos ||
(inventory[i]->getDescription().find(searchUpper)) != string::npos) {
cout << inventory[i]->getTitle() << std::endl;
cout << "ID code: " << inventory[i]->getIdCode() << endl;
cout << "price: $" << inventory[i]->getPrice() << endl;
cout << inventory[i]->getDescription() << endl << endl;
}
}
}

void Store::addProductToMemberCart(string pID, string mID)
{
Product *p = getProductFromID(pID);
Customer *c = getMemberFromID(mID);
if (p != NULL && c != NULL)
{
//if quantity is greater than zero, add prod to cart.
if (p->getQuantityAvailable() > 0)
{
c->addProductToCart(pID);
}
else
{
cout << "Sorry, product #[" << pID << "] is currently out of stock." << endl;
}
}
else
{
if (p == NULL)
{
cout << "Product #[" << pID << "] not found." << endl;
}
if (c == NULL)
{
cout << "Member #" << mID << "] not found." << endl;
}
}
}

void Store::checkOutMember(string mID)
{
Customer *c = getMemberFromID(mID);
double subTotal = 0.0;
int numOfItems = 0;
if (c == NULL)
{
//if no customer found
cout << "Member #[" << mID << "] not found." << endl;
}
else
{
cout << " ****Cart for Checkout**** " << endl;
vector<string> cart = c->getCart();
if (cart.size()) == 0)
{
cout << "There are no items in the cart." << endl;
}
else
  
for (int i = 0; i < cart.size(); i++)
{
Product *p = getProductFromID(cart[i]);

if (p->getQuantityAvailable() < 1)
{
//if product is not found //why doesn't this work for live goat???
cout << "Sorry, product #" << p->getIdCode() << ", " <<
"'" << p->getTitle() << "', is no longer available." << endl;
}
  
else
{
//print out title and price and decrease quantity.
cout << "Title: " << p->getTitle() << ", Price: " << p->getPrice() << endl;
subTotal += p->getPrice();
numOfItems++;
p->decreaseQuantity();
}

}
if (numOfItems == 0)
{
cout << "There are no items in the cart." << endl;
return;
}
double shippingCosts = 0.0;
if (c->isPremiumMember() == true)
{
//if premium member, no shiping costs associated.
shippingCosts = 0.0;
}
else
{
//shipping costs are 7% for non-members.
shippingCosts = .07 * subTotal;
}
  
double finalCosts = subTotal + shippingCosts;
  
cout << "Subtotal: $" << subTotal << endl << "Shipping Costs:$" << shippingCosts << endl
<< "Final Costs:$" << finalCosts << endl;
}
}

int main() {
Customer *m = new Customer("John Roger", "Johnl6818", true);
Product *p1 = new Product("123", "red blender", "sturdy blender perfect for making smoothies and sauces", 350, 1);
Product *p2 = new Product("345", "hot air balloon", "fly into the sky in your own balloon - comes in red, blue or chartreuse ",
700.25, 3);
Product *p3 = new Product("346", "giant robot", "a big robot", 7000, 2);
Product *p4 = new Product("347", "live goat", "a big goat", 200, 0);
Store *s = new Store();
s->addMember(m);
s->addProduct(p1);
s->addProduct(p2);
s->addProduct(p3);
s->addProduct(p4);
s->productSearch("red");
s->addProductToMemberCart(p4->getIdCode(), m->getAccountID());
s->addProductToMemberCart(p3->getIdCode(), m->getAccountID());

s->checkOutMember(m->getAccountID());

return 0;
}

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