Programming Example: Daily Menu Planner
This sample program makes heavy use of listboxes. It was originally given as a student programming assignment.
Description:
Provide the user with the capability to plan his or her daily menu by selecting foods for breakfast, lunch, dinner, and snacks from a master list of foods. The user will decide at the beginning of each session whether they wish to track calories, fat, carbohydrates, protein, or cholesterol. The program will then monitor this quantity and present the total of that quantity for each meal as well as for the whole day.
Input File:
The input file for this program is a sequential file called FOODLIST.TXT. The first two records of the file consist of headings and should be ignored by the program (just read past them). The data records consist of fixed-width fields, in the following format (for this program, we are not concerned with the last two fields):
Field |
Record (byte) positions |
Target Data Type |
Food description |
1 – 30 |
String |
Serving Size |
31-40 |
String |
Fat (grams) |
44-48 |
Integer |
Calories |
53-58 |
Integer |
Carbohydrates (grams) |
65-70 |
Integer |
Protein (grams) |
76-79 |
Integer |
Cholesterol (mg) |
84-89 |
Integer |
Weight (grams) [not used in this project] |
93-99 |
Single |
Saturated Fat (grams) [not used in this project] |
103-108 |
Single |
Program Operation:
· Present the user with a combo box containing the following items: Calories, Fat, Carbohydrates, Protein, and Cholesterol. Pre-select Calories for the user as a default. Whatever the user selects from this combo box is the item that will tracked by the program.
· Your interface should contain list boxes for the following: master food list, breakfast, lunch, dinner, and snacks. Buttons should also be provided to add or remove items from the breakfast, lunch, dinner, and snack list boxes.
· Load the master food list box from with the food description concatenated with the serving size from the input file. In addition, the food count item selected by the user (calories, fat, carbohydrates, etc.) should be loaded into this listbox's ItemData property.
· The user should be able to select one or more items from the master food list. When the user clicks the "Add to Breakfast" (or Lunch, Dinner, or Snacks) button, the items selected from the master food list should then appear in the listbox for that meal. A label next to the listbox for that meal should display the total of the food count selected for this run (calories, fat, etc.). In addition, a running total for all meals should be displayed at the bottom of the form.
· The user should be able to remove items from the meal listboxes. When the user selects items from a meal listbox and clicks the "Remove" button for that meal, the selected items should disappear from that listbox, and the calorie count (or fat count, or whatever) should be subtracted from that meal's total and from the running total.
· When the user clicks the Print button, print a simple report showing the user's food selections for each meal, along with the food count totals for each meal and for the whole day.
To give you an idea of what the forms should look like, I have provided screen shots of my solution to the project.
Splash Screen:
Selection Screen:
Main Screen:
Printout:
Download the solution for this project here.