CMSC 201
Programming Project Five
Meals
Out: Monday 11/29/04
Due: Before Midnight, Monday 12/13/04
The design document for this project,
design5.txt,
is due: Before Midnight, Monday
12/06/04 |
The Objective
The objective of this assignment is to give you practice with project and
function design. It will also give you an opportunity to work with linked
lists, reading information from a file, using dynamic memory allocation,
and dealing with command line arguments.
The Background
An important activity in any household, is the planning and serving of
balanced meals to the family. This process begins when you visit the
grocery store to purchase items to stock the pantry. Even if you are not
currently concerned about how many calories, or grams of fat, or milligrams
of sodium you are consuming each day, there will come a time in your life
when you will have to be aware of such things, either for yourself or some
member of your family.
My local grocery store provides a book called the "Food Guide" for under
$3.00. This book has listed the nutritional data for almost every item
they sell. This includes information on pre-made items, mixes and kits,
canned or frozen foods, as well as fresh meats, seafood and produce. This
book can be used along with your family recipes to construct the nutritional
data for each dish you prepare.
Meals can be constructed from these food items that are available in your
pantry and totals of the nutritional data can be calculated, so that you'll
know how many calories, sodium, etc. each person will consume if they have
one helping of each item.
The Task
Design and code a project that will allow you to read in the information
from a text file, create linked lists of those items by type (MEAT, STARCH,
VEGETABLE, FRUIT, or DESSERT) to represent the pantry, allow the user to
build meals from these items (also linked lists) and report the nutritional
data for the full meal. The user can create as many as 7 meals, one for
each day of the week. I have restricted the food items in the file to be
those typically served for dinner.
The Specifics
- Your program should allow the user to choose to create a meal, print the
meals already selected, or print the remaining contents of the pantry.
- If the user wants to create a meal, you should:
- present him/her with a list of food types to choose from
- After the user has chosen a type, provide a list of items currently
in the pantry of that type
- The user gets to view the nutritional infomation for the food item
they've indicated
- The user must either accept or reject the choice
- If the user accepts this food item, add it to the current meal and
remove it from the pantry
- Display the list of food item names in the current meal before
presenting the list of food types again
- Choosing quit on the food type menu simply means that the user is
finished building the current meal
- When the user is finished building a meal, present the names of the
food items chosen to be in that meal and the nutritional totals per
person for the meal.
- If the user chooses to print his meals, print out the names of the
food items that comprise each meal s/he has selected.
- If the user chooses to print the inventory of the pantry, print out
the names of the items still remaining in the pantry in lists by type.
See the sample output for a suggested format.
The contents of the text file is a list of food items and their nutritional
information. Each food item has the following form in the file:
- The food's name - a string of no more than 49 characters
- The food's type - either MEAT, STARCH, VEGETABLE, FRUIT or DESSERT
- The food's serving size - a string of no more than 49 characters
- An integer, number of calories
- An integer, milligrams of sodium
- A float, grams of fat
- An integer, milligrams of cholesterol
- A float, grams of saturated fat
- An integer, grams of carbohydrates
- An integer, grams of sugar
- An integer, grams of fiber
- An integer, grams of protein
-
The data file, food.dat
You should copy this file into your account by using the following
commands:
(don't forget that there is a dot (.) at the end of the command)
cp /afs/umbc.edu/users/s/b/sbogar1/pub/food.dat .
The Specifications
- Your program must take the name of the data file as a command line
argument.
- You must make a linked list of food items for each meal chosen.
- You must allow the user to construct as many as seven meals.
- Since you will be using dynamic memory allocation, you must
free all of the memory that you have allocated before ending your
program. Freeing the head of a list will NOT accomplish this
task, so you MUST have a function called DestroyList() that frees
all of the memory used for a list and also sets the head of the
list to NULL. Here is its prototype, which you must use and
cannot modify.
void DestroyList(NODEPTR* headPtr);
- Although the menus that you present to the user do not have to look
exactly like those shown in the sample output, they must be neat
and orderly.
- Presenting the user with a list of items already chosen for a meal,
is helpful feedback when the user is about to make another food item
choice, so it is required.
- All errors must be reported to stderr.
- You must guard your .h file(s)
- You must use separate compilation
Your program may make the following assumptions
- The text file will have the format specified above.
- The text file will not contain more items than can fit in memory when
you are running on gl.
SampleOutput
Although your output need not look exactly like the
sample output, all information must be present. Your
program must also print a short greeting. Don't be concerned
if your output scrolls off the top of the screen. It will be
very difficult to keep all output on a single screen.
There are two approaches to this problem...
- Use the unix script command to capture your output in a file
(named typescript) in order to examine it.
For more information on the script command, see the Unix
man pages.
- Redirect the output of your program into a file using Unix
redirection as discussed in class.
Submitting the Program
You are to use separate compilation for this project, so you will be submitting
a minimum of three files.
Your C source code file that contains main() MUST be called
proj5.c. I would expect that you would also have files called
pantry.c and pantry.h, but you may choose to have additional
.c and .h files.
To submit your project, type the following at the Unix prompt. Note
that the project name starts with uppercase 'P'.
submit cs201 Proj5 proj5.c pantry.c pantry.h (and possibly other
files, seperated by spaces)
To verify that your project was submitted, you can execute the following
command at the Unix prompt. It will show all files that you submitted in
a format similar to the Unix 'ls' command.
submitls cs201 Proj5