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

Using c++ Objectives: 1. Students will use class inheritance to solve a problem

ID: 3753343 • Letter: U

Question

Using c++

Objectives: 1. Students will use class inheritance to solve a problem 2. Students will write correct, will-documented and readable programs in a reasonable amount of time.
Problem Description: When shopping online, you select items and add them to a shopping cart. Duplicate items are permitted in a shopping cart, as you can purchase multiples of the same item. You also can remove an item from a shopping cart, if you change your mind about buying it. The shopping cart can show its current contents with their prices and the total cost of these items. Design the ADT item and shopping cart.
Requirements Shopping cart o Design the shopping cart as a derived class from the Bag class o Declare total price as a data member o Define a default constructor o Define a member function to get the total price o Override the base class methods: add and remove Item Declare three data members: name of item, unit price of item, and quantity of item Define a default constructor Define a constructor that initializes all three data members by the parameters. Define set and get functions for each data member. Define the following operators: Equal to: ==         Input : >>        Output: << Write and document the class in header and implementation files, and compile it separately from the client program. You are required to use javadoc-style comments (page 759 of the textbook) in your code following the example of the ADT Bag interface template posted on D2L.

Examples A run of the program might look like this:

csci>a.out
  
Welcome to XXX SHOPPING CENTER. Enter the item you selected as the following order: name unitPrice quantity (Name can not contain any space. Otherwise errors happen!) --> T-shirt 19.99 2 Want to continue y/n-->y

-->Sweater 39.99 1 Want to continue y/n-->y

-->iphone_case 25.50 3 Want to continue y/n-->y

-->Towel 9.99 5 Want to continue y/n-->n

Here is your order: ------------------------------------------------- Name                Unit_Price          Quantity T-shirt             $19.99               2

Sweater             $39.99               2

iphone_case         $25.5                3

Towel               $9.99                5

The total charge is $246.41 --------------------------------------------------

Want to modify your order? y/n-->y What do you want? Enter 1: add 2: remove 3: change quantity --> 1 Enter the item to add as the following order: name unitPrice quantity --> shoe 99.99 1 The item is added.

Want to modify your order? y/n-->y What do you want? Enter 1: add 2: remove 3: change quantity --> 2 Enter the item to remove as the following order: name unitPrice quantity --> Sweater 29.99 2

No such item in your shopping cart!

Want to modify your order? y/n-->y What do you want? Enter 1: add 2: remove 3: change quantity --> 2 Enter the item to remove as the following order: name unitPrice quantity --> Sweater 39.99 2 The item has been removed.

Want to modify your order? y/n-->y What do you want? Enter 1: add 2: remove 3: change quantity --> 3 Enter the item to change as the following order: name unitPrice quantity --> Towel 9.99 5 Enter a new quantity --> 2 The quantity has been modified.

Want to modify your order? y/n-->n


Here is your updated order: ------------------------------------------------- You have ordered the following items: Name                Unit_Price          Quantity T-shirt             $19.99               2

Shoe                $99.99               1

iphone_case         $25.5                3

Towel               $9.99                2

The total charge is $236.45 Thanks for shopping in XXX SHOPPING CENTER. ---------------------------------------------------

Explanation / Answer

hi please follow below instructions to meet our requirement'
C++ source code:-
=============
#include<iostream>//input & output
#include<string> // string library
#include<fstream>
#include<sstream>
#include<cstdlib>
using namespace std;
//structure to save products available on store
struct Product
{
int id;
string name;
int price;
string description;
int quantity;
};
int findProductId(Product products[], int count, int id)
{
for (int i = 0;i<count;i++)
{
if (products[i].id == id)
return id;
}
return -1;
}
string findProductName(Product products[], int count, int id)
{
for (int i = 0;i<count;i++)
{
if (products[i].id == id)
return products[i].name;
}
}
string findProductDescription(Product products[], int count, int id)
{
for(int i = 0;i<count;i++)
{
if (products[i].id == id)
return products[i].description;
}
}
int findProductPrice(Product products[], int count, int id)
{
for(int i = 0;i<count;i++)
{
if (products[i].id == id)
return products[i].price;
}
}
int findProductQuantity(Product products[], int count, int id)
{
for (int i = 0;i<count;i++)
{
if (products[i].id == id)
return products[i].quantity;
}
}
int main()
{
Product products[20];
Product myCart[20];
int id, quantity, found;
double saving, totalPrice, finalCost;
char reward, creditCard;
int productCount = 0, cartCount = 0;
int option;
ifstream ifile;
ifile.open("Inventory.txt"); //file containing the inventory
if (!ifile.is_open())
{
cout << " Product not Available !";
system("pause");
return 0;
}
string line, data;
while (getline(ifile, line)) // read in file the inventory separated by comma in line
{
istringstream read(line);
getline(read, data, ',');
products[productCount].id = atoi(data.c_str());
getline(read, data, ',');
products[productCount].name = data;
getline(read, data, ',');
products[productCount].description = data;
getline(read, data, ',');
products[productCount].price = atoi(data.c_str());
getline(read, data, ',');
products[productCount].quantity = atoi(data.c_str());
productCount++;
}
cout<<"Product in Inventory: " <<productCount<<endl;
while (1)
{
//Menu
cout << " 1.Inventory;";
cout << " 2.Select Merchandise";
cout << " 3.Shopping Cart";
cout << " 0Exit";
cout << " Select a option : ";
cin >> option;
switch (option)
{
case 1:
cout << " ID Item Name Description price Quantity ";
for (int i = 0;i<productCount;i++)
{
cout << products[i].id << " " << products[i].name << " " << products[i].description << " $" << products[i].price;
cout << " " << products[i].quantity << " " << endl;
}
break;
case 2: //look for product id
cout << " Enter product id : ";
cin >> id;
found = findProductId(products, productCount, id);
if (found>0) //product id has to be gratter than 0
{
cout << " Enter Quantity : ";
cin >> quantity;
int quantt = findProductQuantity(products, productCount, id);
while (quantity>quantt)
{
cout << " Quanity available : " << quantt << " Please Enter valid Quantity : "; //if quantity asked is greatter than the inventory diplay a error message
cin >> quantity;
} //adding product the shopping cart
myCart[cartCount].id = id;
myCart[cartCount].name = findProductName(products, productCount, id);
myCart[cartCount].description = findProductDescription(products, productCount, id);
myCart[cartCount].price = findProductPrice(products, productCount, id);
myCart[cartCount].quantity = quantity;
cartCount++;
cout << " Item has been added to card successfully !" << endl;
}
else
{
cout << " Product not found with id : " << id << endl; // if id is not in the inventory list
}
break;
case 3: //Shopping Cart
cout << " Items in Cart " << endl;
cout << " ID Item Name Description price Quantity Total Price " << endl;
for (int i = 0;i<cartCount;i++)
{
cout << myCart[i].id << " " << myCart[i].name << " " << myCart[i].description << " $" << myCart[i].price;
cout << " " << myCart[i].quantity << " $" << myCart[i].price*myCart[i].quantity << endl;
}
cout << " 1.Checkout " << endl;
cout << "2.Continue Shopping" << endl;
cin >> option;
switch (option)
{
case 1: //Reward Card & Discount
cout << " (Get $5.00 off)Do you Have Reward card (y/n) :" << endl;
cin >> reward;
cout << " (Get extra 20% off )Would like to payment through store's Credit Card (y/n)" << endl;
cin >> creditCard;
cout << " ***********Customer Receipt********* ";
totalPrice = 0; //total price reset to 0
for (int i = 0;i<cartCount;i++)
{
cout << myCart[i].id << " " << myCart[i].name << " " << myCart[i].description << " $" << myCart[i].price;
cout << " " << myCart[i].quantity << " $" << myCart[i].price*myCart[i].quantity << endl;
totalPrice = totalPrice + myCart[i].price*myCart[i].quantity;
}
cout << " Total Cost : $" << totalPrice;
//discount Menu
saving = 0;// reset saving to 0
if (reward == 'y' || reward == 'Y')
saving = 5;
if (creditCard == 'y' || creditCard == 'Y')
saving = saving + totalPrice*.2;
cout << " You Saved : $" << saving;
totalPrice -= saving;
//Tax Calculator
cout << " stat Tax (10.5%) : $" << totalPrice*.105;
cout << " Muncipal Tax(1%) : $" << totalPrice*.01;
finalCost = totalPrice + totalPrice*.105 + totalPrice*.01; //Total Cost
cout << " Final Cost : $" << finalCost;
cout << " *****Thank you for Shopping******** ";
cout << " ******** Come Back Soon! ********** ";
break;
system("pause");
case 2:
break;
}
case 0:
system("pause"); //Pause system for no automatic close
return 0;
default: cout << " Invalid option"; // if any option selected is invalid
break;
}
}
system("pause");
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