Before Submission
Before Submission
Troubleshooting:
If the given project (e.g. Q1) runs with error, you need to run "Clean and Build Project"
(Shift+F11). If still error, try to rename or copy the project to other one, e.g. from Q1 to Q1X or
Q1Y.
The given files already contain statements to implement a program for managing a computer store.
The structure of the main classes is as follows:
Class Item: contains information about a Item object, including name, quantity, and price.
- Class Node: includes a Item object and a next pointer for linking.
- Class ItemList: is a singly linked list that manages regular Nodes with complete
information. This class plays the role of managing all items in the Store.
- Class RequestQueue: is a queue structure (implemented as a linked list), where the
component data of the Nodes only contains the name and quantity. This means that the
corresponding request is to purchase an item with a specific name and quantity.
- Class ComputerStore: is the main class of the program, containing a ItemList used to store
data on the items currently available in the store and a RequestQueue corresponding to a
queue of people wanting to make purchases.
Students are required to carefully read the provided code segments to fully understand the
relationships between the classes and the functions within each class. The specific task of the test is
to execute the following requirements:
a. f1(): To complete the requirement f1, students need to fulfill two specific tasks: implement
the function addLast() in the ItemList structure and the function enQueue() (similar to
addLast) in the RequestQueue structure. The expected output used to test your code are as
follows:
Data Item: (Computer,10,2000) (Keyboard,10,300) (Mouse,10,100) (Tablet,10,3000)
(Phone,10,3000) (Monitor,10,2000)
1
Request : (Computer,2) (Keyboard,5) (Tablet,3) (Monitor,12) (Mouse,2)
b. f2(): To complete the requirement f2, students need to perform two specific tasks:
implement the deQueue() function of the RequestQueue structure, then use the returned
result to execute the purchase action for the f2 function. The purchase action can be
implemented directly within the body of the f2 function or executed outside of the function
by a helper function, which will then be called by f2. The purchase action consists of two
steps:
o First, search for the item (name) to be purchased. If found, proceed to step 2.
o If the quantity (quantity) available in the ItemList is not less than the quantity to
be purchased, perform the purchase action: update the remaining quantity in the
ItemList .
The expected output used to test your code are as follows:
Data Item: (Computer,10,2000) (Keyboard,10,300) (Mouse,10,100) (Tablet,10,3000)
(Phone,10,3000) (Monitor,10,2000)
Request : (Computer,2) (Keyboard,5) (Tablet,3) (Monitor,12) (Mouse,2)
Data Item: (Computer,8,2000) (Keyboard,10,300) (Mouse,10,100) (Tablet,10,3000)
(Phone,10,3000) (Monitor,10,2000)
Request : (Keyboard,5) (Tablet,3) (Monitor,12) (Mouse,2)
c. f3(): Perform the pair of operations deQueue() and purchase for all items in the
RequestQueue. The expected output used to test your code are as follows:
Data Item: (Computer,10,2000) (Keyboard,10,300) (Mouse,10,100) (Tablet,10,3000)
(Phone,10,3000) (Monitor,10,2000)
Request : (Computer,2) (Keyboard,5) (Tablet,3) (Monitor,12) (Mouse,2)
Data Item: (Computer,8,2000) (Keyboard,5,300) (Mouse,8,100) (Tablet,7,3000)
(Phone,10,3000) (Monitor,10,2000)
Request : Empty
d. f4(): Perform the pair of actions, deQueue() and purchase, for all the items in the
RequestQueue and calculate the total revenue. The revenue (money) from selling an item
is equal to the multiplication of the quantity purchased and the selling price. The expected
output used to test your code are as follows:
Data Item: (Computer,10,2000) (Keyboard,10,300) (Mouse,10,100) (Tablet,10,3000)
(Phone,10,3000) (Monitor,10,2000)
Request : (Computer,2) (Keyboard,5) (Tablet,3) (Monitor,12) (Mouse,2)
Money : 14700