Homework 1 - Dynamic Arrays of Structures
Due: Tuesday, January 18, 2011 at 5:00pm
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:
- A C-style string for the product name (you may choose the length for this string)
- A C-style string for the product description (you may choose the length for this string)
- A 13 character C-style string for the UPC (Universal Product Code)
- An integer for how many of that product are in stock
You will have the following two void functions to manipulate ProductInfo objects:
- addProduct - Takes a single ProductInfo object as a parameter. It will set
the name, description, UPC and amount in stock for that product by prompting
the user for this information.
- showProduct - Takes a single ProductInfo object as a parameter. It will
display the name, description, UPC and amount in stock for that product.
Your main function will have an infinite loop (similar to Lab 1) which will do
the following steps:
- Prompt the user for the number of products they wish to add to the
inventory and read the response in.
- If the user enters 0, exit the loop.
- 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.
- 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.
- For each object in the ProductInfo array, call addProduct.
- For each object in the ProductInfo array, call showProduct.
- Deallocate the array. Points will be deducted if you do not deallocate
the array as this will be a memory leak.
- Continue to the next iteration of the loop.
Email your source code to me by the due date.