Dana Vrajitoru
C201/I211 Computer Programming II

Homework 7

Due Date: Wednesday, October 25, 2006.

Ex. 1 Download the following files in a separate folder than your other homeworks. Do not rename the files:
product.h
product.cpp
inventory.h
inventory.cpp
main.cpp

Create a project just like for the previous homework and include these three files. If you compile this on Linux, here is a Makefile for this project.

Ex. 1. Modify the default constructor to use the initialization for the barcode, type, quantity, and price instead of assignments as in the example given by the default constructor for the class Inventory.

Complete the class methods Input and Output in the class Product to input an object from the user and to output its content. For the class input you'll need to input the type in a local integer variable, and then assign it to the data member type with a conversions (like Category(t), if t is the integer). In the function output, write a switch instruction that output a string corresponding to each possible value of the type. For example, if the type is equal to food_ty, output the string "food".

Complete the class methods Sell_by_name and Output_all in the class Inventory. See the comments in the source file for their functionality.

Ex. 2 Add the following class methods to the class Inventory:

a. A Boolean function Add_by_barcode() similar in functionality to the function Add_by_name that inputs a barcode and a quantity from the user and adds the quantity to the item in the inventory that matched the entered barcode. If the barcode does not exist in the inventory, the function should print an error message and return false.

b. A Boolean function Sell_by_barcode() similar to the function Sell_by_name but using the barcode as selection criterion. This function should also output the total cost of the sold items (quantity times price) if the operation is successful.

c. A function Total_count that adds the quantities of all the items in the inventory and returns it. No output should be done from this function.

Ex. 3 Add options to the menu in the main function to test for the new functions you added to the class Inventory. For the last function, output the result in the function Execute_menu called from the main.