Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8.21 Main Lab 8 - Online shopping cart Background This main lab extends the earlier prep lab Online shopping cart Part 1. (You should save

8.21 Main Lab 8 - Online shopping cart

Background

This main lab extends the earlier prep lab "Online shopping cart Part 1". (You should save this as a separate project from the earlier prep lab). You will create an on-line shopping cart like you might use for your on-line purchases. The goal is to become comfortable with setting up classes and using objects. This is your first main lab with objects so review the Objects and Classes section of the style guide.

Requirements

This lab can be done individually or as pair programming.

Expanded ItemToPurchase Class (15 points)

Extend the ItemToPurchase class as follows. We will not do unit testing in this lab so we will not be giving you the names of the member functions. Create good ones on your own.

Create a parameterized constructor to assign item name, item description, item price, and item quantity (default values of "none" for name and description, and 0 for price and quantity).

Additional public member functions

Set an item description

Get an item description

Print the cost of an item - Outputs the item name followed by the quantity, price, and subtotal (see example)

Print the description of an item - Outputs the item name and description (see example)

Additional Private data members

a string for the description of the item.

Example output of the function which prints the cost of an item:

Bottled Water 10 @ $1.50 = $15.00 

Example output of the function which prints the item description:

Bottled Water: Deer Park, 12 oz. 

ShoppingCart Class (25 points)

Create three new files - Name all your files exactly as specified as that is required for zyBook file submission.

ShoppingCart.h - Class declaration

ShoppingCart.cpp - Class definition

main.cpp - main function (main's functionality will differ significantly from that of the prep lab)

Build the ShoppingCart class with the following specifications. Note: Some functions can be function stubs (empty functions) initially, to be completed in later steps. Also, we usually declare all variable at the top of the code block. Note that you could be declaring some class objects after receiving user input, so that is a case where it would be all right to declare a variable later in your code.

Parameterized constructor which takes the customer name and date as parameters

Private data members

Name of the customer - Initialized in constructor to "none" if no parameter included

Date the cart was created - Initialized in constructor to "January 1, 2016" if no parameter included

Vector of items objects

Must have the following public member functions

Get the name of the customer

Get the date the cart was created

Add an item object to the cart vector. Accepts a new item object as a parameter.

If item name is already in the cart, output this message: "Item is already in cart. Nothing added."

Remove an item object from the cart. Accepts an item name as a parameter.

If item name cannot be found, output this message: "Item not found in cart. Nothing removed."

Update the quantity of an item object in the cart

If item name cannot be found, output this message: "Item not found in cart. Nothing modified." If the quantity is set to 0, still leave the item in the cart, but treat it as a 0 in all counts, etc.

Return the quantity of items in the cart

Return the total cost of all items in the cart

Print the total number and cost of items in the cart

If cart is empty, output this message: "Shopping cart is empty"

Print the description of each item in the cart

If cart is empty, output this message: "Shopping cart is empty"

Example output of the function which prints the number and costs of items in the cart:

John Doe's Shopping Cart - February 1, 2016 Number of Items: 8 Nike Romaleos 2 @ $189.00 = $378.00 Chocolate Chips 5 @ $3.50 = $17.50 Powerbeats 2 Headphones 1 @ $128.00 = $128.00 Total: $523.50 

Example output of the function which prints the item descriptions:

John Doe's Shopping Cart - February 1, 2016 Item Descriptions Nike Romaleos: Volt color, Weightlifting shoes Chocolate Chips: Semi-sweet Powerbeats 2 Headphones: Bluetooth headphones 

You may also create private helper functions in the ShoppingCart class if you'd like. Hint: A function to find if and where an item name resides in the cart could be helpful in multiple places.

Main Function Options Menu (8 points)

See the full input/output example below to know the expected format. In main, first prompt the user for a customer's name and today's date. Create an object of type ShoppingCart. Note that you have to declare (and thus create) your cart after you have input the name and date, since you have to set those with the parameterized constructor since you do not have setter functions for name and date.

In main, create a loop and allow the user to enter options to manipulate the cart. First implement the options and quit options. If the user enters an incorrect option, just print the options menu.

add - Add item to cart remove - Remove item from cart change - Change item quantity descriptions - Output items' descriptions cart - Output shopping cart options - Print the options menu quit - Quit 

In this lab you may assume that when you prompt the user for an input, that they will input an appropriate value (e.g. an int would not be negative, or a string, etc.). Thus, you are not required to do error checking (you may if you want but we will not test for it). Note that in any "real-world" program, you would ALWAYS check for all possible input errors. However, we have done that sufficiently in previous labs for you to understand the concept, so in this lab you may assume legal inputs and focus on other programming aspects. The one exception is if the user enters an unknown option you will print the options menu. Note that you will still have a mix of >> and getline, so make sure you deal with that properly (See section 7.2 if necessary).

Implement the remaining user options (52 points). Think about what parameters need to be passed to class member functions, etc.

cart: Output shopping cart. Note that to do this, all you should need to do is call the appropriate member function on the shopping cart object. Note that by implementing printing options first, it is easy to test and verify later options as you implement them.

descriptions: Output description of item's in the cart.

add: Add an item to the cart.

change: Update the quantity of a current item in the cart to a new value.

remove: Remove an item from the cart.

Deductions graded by TA's

Adherence to the style guidelines. (up to 20 points)

Always create your own default constructor for each class, and create a parameterized constructor(s) as required. You may combine these into one constructor function by creating a default constructor with default parameters. Hint: One way to test this is to declare a default and a fully parameterized object at the top of your code and make sure that works. Then delete them after testing. (5 points each).

Each class must be created and submitted in separate cpp and header files. (15 points)

Note that you can have all your files in a folder and then drag and drop them ALL AT ONCE into the zyBook submit file area, and zyBook will sort each file into its proper place.

You must solve this problem using classes and members as specified. You must not submit a solution that solves the lab, while not using classes. (60 points)

Sample Input

Mary Jane Lewis September 1, 2017 options descriptions cart add BYU game shirt Perfect shirt to wear with the ROC 5.00 2 add Sunscreen 50 SPF Perfect to avoid the fourth quarter burn 4.50 3 add Sunscreen 50 SPF Perfect to avoid the fourth quarter burn 4.50 1 descriptions cart change buffalo wings 4 change BYU game shirt 4 cart remove Sunscreen 50 SPF descriptions cart quit 

Sample Output - Visual Studio View

Enter Customer's Name: Mary Jane Lewis Enter Today's Date: September 1, 2017 Enter option: options MENU add - Add item to cart remove - Remove item from cart change - Change item quantity descriptions - Output items' descriptions cart - Output shopping cart options - Print the options menu quit - Quit Enter option: descriptions Mary Jane Lewis's Shopping Cart - September 1, 2017 Shopping cart is empty. Enter option: cart Mary Jane Lewis's Shopping Cart - September 1, 2017 Shopping cart is empty. Enter option: add Enter the item name: BYU game shirt Enter the item description: Perfect shirt to wear with the ROC Enter the item price: 5.00 Enter the item quantity: 2 Enter option: add Enter the item name: Sunscreen 50 SPF Enter the item description: Perfect to avoid the fourth quarter burn Enter the item price: 4.50 Enter the item quantity: 3 Enter option: add Enter the item name: Sunscreen 50 SPF Enter the item description: Perfect to avoid the fourth quarter burn Enter the item price: 4.50 Enter the item quantity: 1 Item is already in cart. Nothing added. Enter option: descriptions Mary Jane Lewis's Shopping Cart - September 1, 2017 Item Descriptions BYU game shirt: Perfect shirt to wear with the ROC Sunscreen 50 SPF: Perfect to avoid the fourth quarter burn Enter option: cart Mary Jane Lewis's Shopping Cart - September 1, 2017 Number of Items: 5 BYU game shirt 2 @ $5.00 = $10.00 Sunscreen 50 SPF 3 @ $4.50 = $13.50 Total: $23.50 Enter option: change Enter the item name: buffalo wings Enter the new quantity: 4 Item not found in cart. Nothing modified. Enter option: change Enter the item name: BYU game shirt Enter the new quantity: 4 Enter option: cart Mary Jane Lewis's Shopping Cart - September 1, 2017 Number of Items: 7 BYU game shirt 4 @ $5.00 = $20.00 Sunscreen 50 SPF 3 @ $4.50 = $13.50 Total: $33.50 Enter option: remove Enter name of the item to remove: Sunscreen 50 SPF Enter option: descriptions Mary Jane Lewis's Shopping Cart - September 1, 2017 Item Descriptions BYU game shirt: Perfect shirt to wear with the ROC Enter option: cart Mary Jane Lewis's Shopping Cart - September 1, 2017 Number of Items: 4 BYU game shirt 4 @ $5.00 = $20.00 Total: $20.00 Enter option: quit Goodbye.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

Students also viewed these Databases questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago