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

In C++ using pointers and structures please!!! Create a shopping cart for the us

ID: 3732441 • Letter: I

Question

In C++ using pointers and structures please!!!
Create a shopping cart for the user. Use a data structure of your choice to store what the user has selected to purchase. Remember the user can add as many items to their cart as there are in the inventory list. a. You need to be able to search through the shopping cart. b. If a person enters in a duplicate item that is already in the cart then it should increase the qty in the cart. You need to make sure that you have enough inventory to support the change. c. Do not worry right now about the user removing anything in the cart. In C++ using pointers and structures please!!!
Create a shopping cart for the user. Use a data structure of your choice to store what the user has selected to purchase. Remember the user can add as many items to their cart as there are in the inventory list. a. You need to be able to search through the shopping cart. b. If a person enters in a duplicate item that is already in the cart then it should increase the qty in the cart. You need to make sure that you have enough inventory to support the change. c. Do not worry right now about the user removing anything in the cart. In C++ using pointers and structures please!!!
Create a shopping cart for the user. Use a data structure of your choice to store what the user has selected to purchase. Remember the user can add as many items to their cart as there are in the inventory list. a. You need to be able to search through the shopping cart. b. If a person enters in a duplicate item that is already in the cart then it should increase the qty in the cart. You need to make sure that you have enough inventory to support the change. c. Do not worry right now about the user removing anything in the cart.

Explanation / Answer

//cart with items

#include <iostream>

using namespace std;

//Item.cpp file
class Item
{
string name;
double price;
int quantity;

public:
//get and set methods
void setName(string nm)
{name=nm;}

string getName()
{return name;}

void setPrice(double pr)
{price=pr;}

double getPrice()
{return price;}

void setQuantity(int qty)
{quantity=qty;}

int getQuantity()
{return quantity;}
//constructor with parameters
Item(string nm,double pr,int qty)
{
name=nm;price=pr;quantity=qty;
}

Item() //default constructor
{
name="";
price=0;
quantity=0;
}
};

//ShoppingCart.cpp
class ShoppingCart
{
Item *items[100]; //declare 100 items of pointers
int arrayEnd;//for end of array

public:
ShoppingCart()
{
for(int i=0;i<100;i++) items[i]=NULL; // assign array element to NULL
arrayEnd=0;
}

void addItem(Item *tItem)
{
items[arrayEnd++]=tItem; //adding each item to array
}

double totalPrice()
{
double total=0;
for(int i=0;i<arrayEnd;i++) //repeat until end of items array
total+=(items[i]->getQuantity()*items[i]->getPrice()); //calling price and quantity by get methods
return total; //return total
}
};

//Main program to for testing your input
int main()
{
Item a("affadavit", 179.99, 12);
Item b("Bildungsroman", 0.7, 20);
Item c("capybara", 4.5, 6);
Item d("dirigible", 0.05, 16);
ShoppingCart sc1;
sc1.addItem(&a);
sc1.addItem(&b);
sc1.addItem(&c);
sc1.addItem(&d);
double diff = sc1.totalPrice();
cout<<"Total price is : "<<diff;
return 0;
}