Programming Project 3--Writing a Program to Keep a Personal Inventory

Due Dates and Times:

This project is due on the following days depending on your section of the course: Wednesday, May 7th for Townsend's and Howard's section. Thursday, May 8th for Berque's section. Your instructor will announce the exact time when your project will be due.

Where to Work:

Copy the folder proj3 from public into your directory and complete the project there. The files in ``proj3'' are set up to support the use of the STL string class, so it is important that you use this folder as a basis for your project. In addition, these files will provide you with an empty .cpp file to write your program in, and an empty .h file to write your class in.

Overview:

For this project, you will be writing a program for your personal use. This program will keep track of inventory of a personal collection of yours. You will be writing a class to represent a single object of your collection, and completing a program that will allow you to keep track of inventory of your entire collection.

Project Specifications:

There are two parts to this project. Depending on your sections, some parts may be due before the entire project is due--if this is the case, specifics will be announced in your class.

Part one involves implementing a class for whatever object you choose to represent for your inventory program. You must adhere to the following:

We strongly suggest you write a simple program to test your class before moving on to part two. Debugging will be much easier if you are sure your class is correct before moving on to part two.

Part two involves writing a program to store and organize a collection of the objects of the class designed above. This program should define an array of objects of the class you designed in part one above. You may assume that the program will store no more than 30 objects--although you should plan ahead for changing this at some future date. The program should then present the user with a menu similar to the following:

  1. Load a collection from a file whose name is specified by the user
  2. Display all the objects in the collection to the screen.
  3. Save a collection to a file whose name is specified by the user.
  4. Add an item to the collection.
  5. Sort the items, based on a single characteristic (title, number, etc.).
  6. Quit the program.

Then, based upon what option the user chooses, you should perform the required task. After performing the specified task, the program should clear the screen and display the menu again. This should continue until the user chooses to quit the program--note this will require a loop in your .cpp file.

Some explanatory notes on a few of the options:

All six options must be available to the user for your program to receive full credit. When the program is run initially, the collection should be empty. The file format, in particular, is up to you. Below, we provide you with a function that will allow you to store strings with spaces in them on a single line of a file.

Notes on Style and Suggestions for Getting Started:

The program should exhibit good style, using functions to separate the problem into small, manageable units (this includes the main body of the program, which should be at most a screenful or so long). It should be well commented (including pre and post conditions for each subprogram) and easy to read.

Do your writing in stages--make sure one function works before writing the next. In particular, you should write a small test program to test the class before actually writing the final program.

New Function available:

To truly make this inventory program useful, you should be able to read and write strings containing spaces--for example, many book titles contain spaces, as do CD titles, book titles, etc. Up until this point in class, we have only been able to read strings from a file or from the user that do not contain strings.

There is a function in "cs1utils.h" called getline that allows us to read an entire line of text into a single string variable. Here are some examples of how getline works:

string x;
cout << "Enter a string with as many spaces as you want: ";
getline( cin, x );
This particular example will allow the user to type until he or she hits <Return>, then the entire string will be put into x. We can also use getline to read strings from a file. Assuming that inFile is an fstream variable that has already been opened to a specific file, we can type:
cout << "Getting a line from the file..." << endl;
getline( inFile, x );

The getline function should be useful for this project--for example, it allows you to store multiple word titles on a single line in your file. Remember, you must #include "cs1utils.h" to use it.