Confidential Teaching Materials
Homework 7 Criteria, Page 1 of 8
Homework 7 Grading Criteria
Note: To receive any credit whatsoever, your answers must be legible and readily readable in the
judgment of the grader. Add brief explanatory comments as necessary to make sure your answers
are clear and unambiguous to the grader.
You have been hired to write a system to keep track of inventory in a major department store. The
specifications for the project state that you must use an object-oriented approach, so all data must be stored
using objects (as opposed to something like records).
Each item in the store has the following information associated with it:
* UPC number (a unique numeric code that identifies the item)
* Description
* Quantity available
* Price each
The store wishes to have the following functionality for the inventory control system:
1. Add an item – asks the user for all of the information about an item, then adds the new item to the
database. When a new item is added to the database, it’s quantity available field should be set to 0.
2. Check availability – given a UPC number, searches the database and prints out all information about an
item. If the item is not present in the database, the system should print “Item not found!”
3. Discontinue item – removes an item from the database given it’s UPC number. If there is no item in the
database associated with the given UPC number, the system should print “Item not found!”
4. Sell item – given a UPC number, searches the database for the given item and decrements it’s quantity
5. Stock item – given a UPC number, searches the database for the given item and increments its quantity
The client has also given you a Dictionary class that you can use for the item database (see description following
Problem 3, below).
[p1] 40 points
Write a class that represents a single item in the store’s inventory. The class should provide the following
abilities:
* Get and set UPC number
* Get and set description
* Get and set quantity available
* Get and set price each
* Increment quantity available
* Decrement quantity available
All data in the class should be stored in the protected section, with appropriate accessor functions to manipulate
it.
[c1] 40 points
Confidential Teaching Materials
Sample Solution:
class Item
public:
procedure Set_UPC (p_upc isoftype in Num)
function Get_UPC returnsa Num ()
protected:
upc, qty, price isoftype Num
desc isoftype String
procedure Set_UPC (p_upc isoftype in Num)
upc <- p_upc
endprocedure
function Get_UPC returnsa Num ()
Get_UPC returns upc
endfunction
endfunction
procedure Set_Price (p_price isoftype in Num)
price <- p_price
endprocedure
function Get_Price returnsa Num ()
Confidential Teaching Materials
Homework 7 Criteria, Page 3 of 8
endclass
GRADING:
For each public header:
~~~~~~~~~~~~~~~~~~~~~~~
Private section:
~~~~~~~~~~~~~~~~
[p2] 20 points
Write a module that takes in a parameter a Item object (as defined in problem 1) and prints out all information
about the item.
[c2] 20 points
Sample Solution:
procedure Print_Item_Info (item isoftype in Item)
GRADING:
-1 for not making it a procedure (pro)
-1 for not making the parameter an Item class (obj)
Confidential Teaching Materials
Homework 7 Criteria, Page 4 of 8
[p3] 20 points
Write a module that fills in the data of an item and passes it back to the calling module via a parameter. The
module should prompt for, read in (from the user), and set all of the properties of the Item object except
quantity, which should automatically be set to 0.
[c3] 20 points
Sample Solution:
procedure Get_Item_Info (item isoftype out Item)
upc, qty, price isoftype Num
desc isoftype String
GRADING:
-1 for not making it a procedure (pro)
-1 for not making the parameter an Item class (obj)
-1 (x4) for not reading each item into a temp variable (ird)
To store information on the items in the store, the client has provided you with a Dictionary class. A dictionary
allows you to store and retrieve items based on some key element of the item. For the inventory management
system, you should store the Items based on the UPC number. The public section for the Dictionary class is
given below.
class Dictionary( Key_Type, Value_type isoftype type )
Confidential Teaching Materials
Homework 7 Criteria, Page 5 of 8
function Get returnsa Value_Type ( Key isoftype in Key_Type )
// returns the item associated with K in the dictionary
function Contains returnsa Boolean( Key isoftype in Key_Type )
// returns true if an item associated with Key is present
// in the dictionary.
[p4] 60 points
Write the main algorithm to complete the program specifications above. You must use the Item class (defines in
problem 1) and the Dictionary (given above). You do not have to write the protected section of the Dictionary.
Your algorithm should display a menu for the five options of the system (plus a “quit” option), read the user’s
selection, and process it until the “quit” option is selected.
[c4] 60 points
Sample Solution:
algorithm InventoryManagement
uses Item, Dictionary
procedure Get_UPC (upc isoftype out Num)
print (“Enter UPC number: “)
read (upc)
endprocedure
// main
elseif (sel = 2) then
Get_UPC (temp_upc)
if (dict.Contains (temp_upc) = FALSE)
print (“Invalid UPC”)
else
Confidential Teaching Materials
dict.Remove (temp_upc)
endif
elseif (sel = 4) then
Get_UPC (temp_upc)
if (dict.Contains (temp_upc) = FALSE)
GRADING:
-2 for not saying “uses dictionary”
-0.5 (x6) for each selection not displayed (wro)
-1 (x2) for missing selection or temp_upc variables (nav)
-2 for missing or wrong dict variable (nav)
-1 for not calling Initialize on dictionary (ibu)
-2 for not reading item info into temp item (log)
-2 for not reading UPC number first (log)
-1 for calling Contains wrong (e.g. did not include
(“dict.”) (fci)
-1 for not passing proper parameter (npo)
-1 for printing error when appropriate (wro)
Confidential Teaching Materials
Homework 7 Criteria, Page 7 of 8
For selection 3:
-2 for not checking if the UPC number exists in dictionary
-3 for not calling Remove when appropriate (log)
-1 for not putting “dict.” (pci)
-2 for not reading UPC number first (log)
-1 for calling Contains wrong (e.g. did not include
(“dict.”) (fci)
-1 for not passing proper parameter (npo)
-1 for printing error when appropriate (wro)
For selection 5:
-2 for not checking if the UPC number exists in dictionary
-3 for not calling Dec when appropriate (log)
-1 for not putting “dict.” (pci)
-1 for not exiting when quit option selected (log)
[p5] 10 points
Explain inheritance with respect to object-oriented programming. Give
an example of where inheritance could be used.
[c5] 10 points
Sample Solution:
Confidential Teaching Materials
GRADING:
[p6] 10 points
Explain the concept of generic parameters. Why are they used?
[c6] 10 points
Sample Solution:
GRADING:
[p7] 10 points
Explain the idea of polymorphism.
[c7] 10 points
[p8] 10 points
Explain the difference between the copy and clone operations.
[c8] 10 points
Sample Solution:
GRADING: