Homework 1 - Dynamic Arrays of Structures

Due: Wednesday, January 18, 2012 at 5:30pm

Coding Conventions

The following coding conventions should be used for all assignments.

Assignment

The purpose of this assignment is to create a structure called ProductInfo for a small inventory control system. You will also be using a dynamic array to track the collection of products in the inventory. You MUST use a dynamic array for this assignment. Any assignment that does not use new/delete will have points deducted.

The ProductInfo structure must have the following pieces of data:

You will have the following two void functions to manipulate ProductInfo objects: The ProductInfo parameters for these two functions may be either a pointer or a reference parameter. Choose which style you prefer.

Your main function will have an infinite loop (similar to Lab 1) which will do the following steps:

  1. Prompt the user for the number of products they wish to add to the inventory and read the response in.
  2. If the user enters 0, exit the loop.
  3. Validate that the integer given by the user is greater than 0 by continuing to the next iteration if the user enters a negative number. Points will be deducted if you do not validate the user's input.
  4. Dynamically allocate an array of ProductInfo objects using the integer given by the user. Continue to the next iteration of the loop if the allocation fails. Points will be deducted if you do not continue to the next iteration when allocation fails. You may use a modified allocateArray() function from Lab 1 for this step.
  5. For each object in the ProductInfo array, call addProduct.
  6. For each object in the ProductInfo array, call showProduct.
  7. Deallocate the array. Points will be deducted if you do not deallocate the array as this will be a memory leak.
  8. Continue to the next iteration of the loop.
Email your source code to me by the due date.