Homework 1 - Recursion and Structures

Due: Tuesday, January 20, 2009 at 5:00pm

Coding Conventions

The following coding conventions should be used for all assignments. There are two parts to this assignment. Each part is worth 10 points. Name your files hw1_1.cpp for part 1 and hw1_2.cpp for part 2.

  1. Write a recursive function that will take an integer and print its digits in reverse order. For example, if given the number 321, it will print 123. Your function MUST take an integer, not a string. Your main function should prompt the user to enter an integer and then print the reversed integer to the screen.
    Hint: n % 10 will get the last digit of an integer.
  2. Write a structure called ProductInfo for a small inventory control system. Your ProductInfo structure will have the following pieces of data: Create the following two functions to manipulate ProductInfo objects: Your main function should 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. Validate that the integer given by the user is greater than 0.
    3. Dynamically allocate an array of ProductInfo objects using the integer given by the user.
    4. For each object in the ProductInfo array, call addProduct
    5. For each object in the ProductInfo array, call showProduct
Email hw1_1.cpp and hw1_2.cpp to me on Sleipnir.