Question
Using C++ implement the two classes, item and order , that are used to represent the order a customer can place with the service. The
Using C++
implement the two classes, item and order, that are used
to represent the order a customer can place with the service. The item class is specically
going to represent individual items with the order class being used to organise a collection
of items for a single person. Each of these classes is dened in a simple UML diagram
below:
order
-items: item**
-customerName:string
-orderID: string
-orderSize: int
-currentSize: int
-----------------------------
+order()
+order(cName:string, cID:string, sizeOrder:int)
+order(cName:string, cID:string, itemsList: item**, sizeOrder:int, sizeList:int)
+~order()
+addItem(i:item*):int
+tallyCost():double
+getItems():item**
+getCustomerName():string
+getOrderID():string
+getCurrentSize():int
+getOrderSize():int
The variables of the class are as follows:
-customerName: The name assigned to the order based on the customer who placed
it.
-orderID: A string of numeric characters that identify each order uniquely.
-items: a 1D array of pointers to objects of the class item. This is a list of items
that is contained within the order class and represents the bulk of the functionality
of the class.
-orderSize: This variable is the maximum number of items in the order.
-currentSize: This is the current number of items in the order. This can be less than
the orderSize but cannot be over.
The methods dened for the class are as follows:
-order(): The default constructor. This must simply print the sentence, "order class
constructed", without the quotation marks to the screen with a new line at the end.
-order(cName:string, cID:string, sizeOrder:int): This will receive three arguments,
the customer name, order ID and the maximum size of the order respectively. Then
it will create an instance of the order and instantiate the class with the passed in
arguments. When created it will mean the item list is blank and so the currentSize
should reect that. The items variable is also instantiated but left as an array of
the specied size.
-order(cName:string, cID:string, itemsList: item**, sizeOrder:int, sizeList:int): This
will receive the customer name, order ID and a list of pre-created items with the
maximum number of items specied as an argument. It must then create an instance
of the order class with these arguments, copying the information contained within
the list of items passed in as an argument. The variable sizeList refers to the size
of the current itemsList.
-~order: This is the destructor. It will deallocate the memory assigned to the
items variable before the class is deleted. Be sure to make sure that the memory
is allocated rst before deallocating it. The nal state of the variable should be
NULL.
-addItem(i:item*): This method will simply copy the information contained with the
argument passed in and add a new item to the array of items already maintained.
It will return the index at which the new item was added. If the number of items is
already equal to the size of the order, then the item is not added and the function
returns -1. The new item added is always added in the next available position.
-tallyCost(): This function will calculate the cost of all the items in the order. This
is the summation of every item's costPerItem multiplied by the quantity ordered.
This is returned.
-getItems(): Returns the items variable
-getCustomerName(): Returns the customer name
-getOrderID(): Returns the order ID
-getCurrentSize(): Returns the current size of the order in terms of the number of
items, just distinct items, contained within.
-getOrderSize(): Returns the maximum size of the order that is allowed.
item
-itemName: string
-quantityOrdered: int
-costPerItem: double
-----------------------------
+item()
+item(name:string, quantity: int,cost:double)
+~item()
+getItemName():string
+getQuantityOrdered():int
+getCostPerItem():double
+print():void
The variables are as follows:
itemName: The individual name for the item
quantityOrdered: The number of this specic item ordered. For example, the item
might be a Chocolate Bar A, but 25 have been ordered of this one type.
costPerItem: This is the specic cost for 1 quantity of this item. For example if the
costPerItem is 5.00 and the quantity is 2, the total cost of this item is 10.00
The methods have the following behaviour:
item(): The default constructor. This must simply print the sentence, "item class
constructed", without the quotation marks to the screen with a new line at the end.
item(name:string, quantity: int,cost:double): This constructor must instantiate an
instance of the item class using the arguments provided.
item(): This is the default destructor. It simply prints "item deleted", without
the quotation marks with a new line at the end.
getItemName(): This returns the itemName.
getQuantityOrdered(): This returns the quantity of the items ordered.
getCostPerItem(): This returns their per unit cost.
print(): This just prints out each of the values, each on a new line, stored in the
item. For example:
Name: Potatoes
Quantity: 25
Cost Per Item: 1.25
You will be allowed to use the following libraries: string, iostream. You will have a
maximum of 10 uploads for this task. Your submission must contain item.cpp, item.h,
order.cpp, order.h, main.cpp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started