Homework 2 - Basic Classes

Due: Wednesday, January 28, 2009 at 5:00pm

Coding Conventions

Use the same coding conventions as described in Homework 1. Additionally, make sure to indent each section of the class in the class definition.

Assignment

For this assignment, you will be modifying the structure from Question 2 of Homework 1 into a class. Your ProductInfo class will contain the following member variables in the private section: Your class will now have the following member functions in the public section: Additionally, your member functions must enforce the following constraint:

Main Function

Your main() function will create an array of products, similar to Homework 1. However, this time you will use the following menu to drive your main() function. You can do all of the menu operations within main() or you can add functions to support the menu operations. See menu_example.cpp for an example of a menu-driven program.
         Welcome to the CS222 Homework 2 Menu
  ===================================================
  1.  Input all product information from the keyboard
  2.  Print all product information to the screen
  3.  Edit the stock level for a single product

  0.  Exit
  ===================================================
Option 1 will work similarly to Homework 1. It should prompt the user for how many products there are, verify that the number of products is greater than 0, dynamically allocate an array of products and then call setProduct for each item in the array.

If the user selects Option 1 a second time, the old array should be deallocated before following the above steps.

Option 2 will loop through all products in the array and call printProduct. If the user has NOT selected Option 1 yet (there is no array allocated), Option 2 should print an error message reminding the user to select Option 1 first.

Option 3 will print all the products and ask the user which product they wish to update. It will then ask the user what the new stock level is for that product. It will then update that product to the new stock level and reprint just the selected product to show the user that the new stocking level has been set.

As with Option 2, if the user selects Option 3 before selecting Option 1, you should print an error message reminding the user to select Option 1 first.