Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide the necessary c++ code based on the given UML, main, and instructions. Output is also given. Thank you! #include #include #include CartItem.h using

Please provide the necessary c++ code based on the given UML, main, and instructions. Output is also given. Thank you!

image text in transcribedimage text in transcribed

#include

#include

#include "CartItem.h"

using namespace std;

int main()

{

//Code to Test CartItem Class

// Change the following to print your name

// ******************************

cout

cout

string itemName;

double costPerItem;

int qty;

cout

cout

cin >> itemName;

cout

cin >> qty;

cout

cin >> costPerItem;

cout

// Create an object called firstItem and use the constuctor

// that has formal parameters. Pass in the values the

// user typed in

// ***************************

CartItem secondItem("eggs", 1.29, 3);

CartItem thirdItem("Doritos", 4.59, 2);

cout

// Call the displayCartItem method (in the class) three times

// Use the three objects that were created

// **********************************

cout

cout

cin >> qty;

cout

cin >> costPerItem;

// Change the quantity and cost per item of firstItem

// Use the values that the user just typed

// *********************************

cout

// Call the displayCartItem method in the class three times

// Use the three objects that were created

// **********************************

cout

cout

cout

cout

itemName = secondItem.getItem();

costPerItem = secondItem.getPrice();

qty = secondItem.getQuantity();

cout

cout

cout

cout

// Notice - there is no way to change the Item name - so the only way to give an item a

// name is using the constructor - why do you think it is set up this way

system("pause");

}

Constructor One of the constructors assigns the fields the values of the formal parameters. The other does nothing, but-item: string there has to be a no argument CartItem quantity: int rice: double -p +CartItem(item:String, price double, qty:int) +CartItem() constructor Mutators Sets the appropriate fields to the values passed in getItem):String getPriceO:double Accessors Returns the appropriate fields +getQuantityO:int +setPrice(price.double):void +setQuantity(qty:int) :void displayCartItem Displays the cart item as shown on the output. It displays the item, quantity, price, and total cost for the item. setItem( item:String. price:double, qty int)void +displayCartItemO:void Constructor One of the constructors assigns the fields the values of the formal parameters. The other does nothing, but-item: string there has to be a no argument CartItem quantity: int rice: double -p +CartItem(item:String, price double, qty:int) +CartItem() constructor Mutators Sets the appropriate fields to the values passed in getItem):String getPriceO:double Accessors Returns the appropriate fields +getQuantityO:int +setPrice(price.double):void +setQuantity(qty:int) :void displayCartItem Displays the cart item as shown on the output. It displays the item, quantity, price, and total cost for the item. setItem( item:String. price:double, qty int)void +displayCartItemO:void

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_2

Step: 3

blur-text-image_3

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

More Books

Students also viewed these Databases questions

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago