Lab 10 - Structures and Functions
The purpose of this lab is to learn how to create and use a structure object
and how to pass a structure object to a function.
Program Requirements: You will be creating a structure called
ProductInfo to hold information on products in a store inventory. In main(),
you will create a single ProductInfo object, then call the getProduct()
function to read in the product attributes, and finally call the
printProduct() function to print the product attributes.
The ProductInfo structure must have the following attributes:
- A C-style string for the product name (you may choose the length for this
string, but it should be a reasonable length)
- A 13 character C-style string for the UPC (Universal Product Code)
- An integer for how many of that product are in stock
The functions will have the following features:
- void getProduct(ProductInfo &) - This function takes a single product
by-reference. It prompts the user for the name, UPC and stocking level and
reads the user's responses in to the appropriate fields in the structure
(using the dot operator). Note that the name should be read in using
cin.getline
so the user can put spaces in the name,
- void printProduct(const ProductInfo &) - This function takes a single
product object. It prints the product name, UPC, and stocking level to the
screen. You should use formatted output for each attribute.
The output should resemble the following (the user input is in
blue font face):
Enter product name: red ball
Enter UPC code: 12497438956
Enter quantity in stock: 15
Product Information is:
Name: red ball UPC: 12497438956 Stock: 15
Name your code lab10.cpp and email your completed code to me.