Lab Assignment #4, CSE 1320 Spring 2007
Due Date: See section website for due date
(see instructions on website for how to turn this in)
Topic objectives: Classes
Objects
Methods
C++
Do you enjoy eating out? If only I could always pick a good restaurant for my favorite types of food! Since almost everyone enjoys eating out, you have begun creating a program to recommend restaurants based on a variety of factors such as type of food, number of entrŽe choices on the menu, average entrŽe cost, distance, age of the restaurant, family-friendliness, average wait time, hours of operation, and other factors.
We are now going to modify the implementation of our restaurant selection system. In this lab we will modify the data structures from the previous labs and begin the change to an object oriented paradigm, we will continue to search and we will do more sophisticated updates.
The tasks for this lab, Lab #4,are:
¬ Introduce the system to a new user.
¬ Develop
a class type to record all the restaurant data, constructor functions,
destructor functions, accessor functions, and mutator functions about any one restaurant.
(This will be all the data from the previous labs)
¬
Create
one array of objects to store the restaurants in and then populate the array
with data from a file.
¬ Create and display a screen menu of the following choices for the user.
1) Using the objects in the array search for restaurants by
i. Distance
ii. Type of food
iii. Total cost estimate for dinner for x number of guests
iv. Hours and days of operation
v. Average wait time
vi. Family friendliness
vii. Restaurant name
2) Sort the list by average entrŽe cost, restaurant name, food type, or distance
3) Update the data in the listÐthis will take the user to a submenu for doing updates
4) End the program
Each of these tasks is described in more detail below. There are also a few simplifying assumptions for Lab #4..
Simplifying assumptions for Lab 4:
a) This lab is basically Lab 2 with objects and methods plus some of the extra functionality from Lab 3. This will cause a good bit of the program to be rearranged and rewritten.
b) All distances will be calculated from Nedderman Hall at UTA.
c) Each restaurant serves only one kind of food using the codes given below
Task Descriptions:
¬ Introduce the system to a newuser.
For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key.
¬ Develop a class type to record all the restaurant data about any one restaurant.
For Lab #4 all the data for one restaurant must be stored in a single object. You must declare a class type to hold this data. The class type you create should be placed in a header file for the program. The class must contain data and methods. Some of your existing functions may become methods and some may still be global functions requiring regular function prototypes.
All objects (variables) instantiated (created) from this class (struct) type must be declared inside of the main function of the program, i.e. the array of objects must be declared in main. Each object must hold the following data in the following form. Note that some elements may now be stored differently than they were previously.
All restaurant data to be given by the user must be in a file (a data file will be posted) and the program will read the pieces of data from the file. The format for a line of the data file is given later in this description. The pieces of data to be read from the file and included in the struct for each restaurant are as follows:
o Restaurant name Ð a string to hold a name of length <= 30 characters. For this lab you will read this data from a file and each restaurant name must have no blanks in it. For example the input file should read Kentucky_Fried_Chicken or KentuckyFriedChicken for that particular restaurant.
o Restaurant code Ð the integer numeric code associated with a particular restaurant. Restaurants with the same name should have different codes so that they can be distinguished (e.g. McDonaldÕs #4 and McDonaldÕs #20)
o Type of foodÐ the letter code for the type of food served at the restaurant.
The food type abbreviations are:
A Asian
B Buffet
C Cajun
D Deli
F Fast food
H steakHouse
I Italian
J Japanese
L saLad
M Mexican
N chiNese
P Pizza
Q Barbeque
S Seafood
T Thai
V Vietnamese
W sandWich
o Number of entrŽe choicesÐthe number of different entrees available.
o Highest entrŽe costÐ the highest price for an entrŽe on the menu.
o Lowest entrŽe costÐ the lowest price for an entrŽe on the menu.
o Distance in milesÐthe distance in miles from UTA Nedderman Hall to restaurant.
o ChildrenÕs menu availableÐa value indicating whether or not a childrenÕs menu is available.
o SeniorÕs menu availableÐa value indicating whether or not a seniorsÕ menu is available.
o Age of the restaurantÐthe age in months of that particular restaurant.
o Hours of operationÐfour values : the first daily opening time and first closing time of the restaurant and the second opening and closing time (Imagine lunch hours and dinner hours). If the restaurant is open all the way from lunch through dinner then there will be values for the first times and -1 for the second opening and closing times. The time is given and must be stored as a military time (a 24 hour clock instead of 12 hours AM and 12 hours PM) Ex: 10:00am would be 1000military time while 10:15pm would be 2215 military time.
o Days open during the weekÐ a string of char max length 7 with one letter for each day open using the following code:
M Monday
T Tuesday
W Wednesday
R Thursday
F Friday
S Saturday
N Sunday
In addition to the pieces of information above that will be read from the input file, the struct for each restaurant should also include the following pieces of data:
o Average wait timeÐthis value will be calculated and stored in the struct
o Average entrŽe cost Ð the average cost of an entrŽe which will be calculated and stored in the struct
o Family restaurant Ða value indicating whether this restaurant is family-friendly and reasonably priced. This value will be determined by a formula.
¬ Create one array of the class type above to store the restaurant data in and then populate the array with data from a file.
For Lab #4, the restaurant data will all be stored in one array of objects with at least fifty objects as are described above. Declare an array to hold all the restaurant objects.
The program will read the input
from a file called ÒÒlab2inSpr07.datÓ. This is the same data file used for Lab #2 and #3.
See the Lab #3 assignment for the file format. Read either all the data in the
file or the first 50 restaurants whichever comes first. Keep a count of the
total number of restaurants stored in the array.
As part of the class definition, make sure to include methods for validating the input data. Write restaurant class mutator methods that will check for the validity of
Number of entrŽe items >= 0
Average cost of entrŽe >= 0
Distance in miles >= 0
Menu for children and for seniors has valid response
Restaurant age >= 0
Opening hour must be within 24 hour limit but closing time could be next day i.e. 1am.
Closing hours ÒafterÓ opening.
A 24 hour restaurant is open 0000 to 2359
You must use mutator functions (methods) in the object to verify the validity of each input and to store either a valid input or a default value if the input is not valid. Give the user a message for each default value that is used.
Data Calculation:
For the three remaining pieces of data in each restaurant object, Average wait time, Average entrŽe cost, and Family restaurant calculate each piece of this data as follows and store the value into the object. [Note: the union and enum are NOT required for Lab #4]
For Average wait time perform the same recursive calculation as in Lab #2.
For Average entrŽe cost, perform the same calculationfor each restaurant as in Lab #2.
For Family restaurant use the same codes and determinations as in Lab #2.
Input and calculation verification:
When the program has read in the available restaurants from the file and calculated all needed values, print out all the restaurant data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels. The methods to print the data in the objects should be accessor functions defined in the restaurant class type. These methods should format the data elements in an easily readable way. For example, if the accessor function to print the opening time is opn1prnt, then invoking this function on one of the restaurant objects in the array, rest[k], should produce a formatted time output, i.e. if the first opening time is 1500 then rest[k].opn1prnt should either give Ò15:00Ó or Ò3:00pmÓ for the output.
¬ Create and display a screen menu of choices for the user.
Once all the data is read into the list your program should give the user a screen menu with the following choices: (use any number scheme you wish)
i- Search for a restaurant
ii- Sort the restaurant data
iii- Update restaurant data
iv- End the program
The search, sort and update options should take the user to a second screen to allow them to specify which search or sort or piece of data to update.
All of the search options should call search functions on the array of data. You may search using either linear or binary search as preferred. Note that there are FEWER searches than in previous labs. When the search is complete your program should print the search result(s) and then show the user the menu again. In case of ties, print all results.
Sort options may use bubble sort, merge sort, or other algorithms.
See search, sort, and update descriptions from Lab #3. After each sort or update be sure to print the array contents to display the modifications that have been made.
The data to be compared and returned must be acquired through the use of accessor functions.
For any change the user wishes to make, use the accessor and mutator functions to do the same error checking as in the original data entry section.
When the user chooses ÒEnd the programÓ from the main menu, print a concluding message and then gracefully end the program.
In addition to the task functionality your program must be contained in multiple program files. Specifically you must have:
at least one header file for each class type definition containing the description of the class and its public and private data and methods (a .h file),
for each class, you must define the methods for that class either with the class or in a second file (a .cpp file),
a file containing just your main routine (a .cpp file);
and one or more files containing the remainder of your functions (.cpp files).
These files must be linked together with #include statements and must only be compiled once. [Hint: use #ifdef to insure that header files are compiled only once.] All files with the .cpp extension must be listed on the gpp line in order to compile together.
Input data:
You should use the file on the website to test with but you should also create your own data file. To create your input data file go online and collect data for at least 40 different restaurants in DFW. You must include at least fifteen different types of restaurants, e.g. you cannot have 5 McDonaldÕs and 5 Pizza Huts in your list. Include a comment in your code or your script session telling what day you collected the data and what website(s)you used for data collection. Use maps and driving distances to get the distance values. You may reuse your data file from Lab #2.
Implementation requirements:
The program should use the following data structures:
A class type to contain all the data and functions for one restaurant
An array of objects for holding restaurant information
An input data file. (Note: no output data file is required for Lab #4)
The program should use the following control structures:
Class methods (functions) to provide data access and data change in the class
Global (file) scope functions to perform other tasks such as sorting
Input and output handled with streams and stream functions from C++
The program should use the following file structure: THIS IS NEW
One file for each class specification (.h)
One file for each set of class member function definitions (.cpp)
One file with type definitions, constants and functions prototypes for file scope functions (.h)
One file with the main routine init (.cpp)
File with main routine may not have other functions in it
File scope functions may be defined in one or more files
Your class must control all access to the data members of the restaurant object. No client function or object should be able to directly change data in an object without going through a mutator member function that does error checking and/or data validation.
Your program must be implemented in a modular object-based fashion. You must have a class defined to retrieve, hold and manage all data associated with a restaurant. The class will also include member functions. To run your program you will have a main routine and at least one function to display the menu, at least one function for searching, one for sorting, and at least one function for updating. You may have more functions than this. Each of your functions must specify any parameters it uses for input in its parameter list.
Your program should have meaningful identifiers and useful comments. It should be consistently indented and should use horizontal and vertical whitespace for readability.
The program should have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple files are used, each file should contain a similar header. See your instructorÕs website for SPECIFIC instructions about the program header.
Each programmer-defined function, i.e. each function you write, should have a function header similar to those used in the examples in the textbook. This header should include at least the function name, the purpose of the function, and its inputs and outputs.
The program should perform the following actions in the given order:
Print a welcome screen for the user that introduces the system
Declare and initialize the objects
Print the appropriate outputs
Let the user enter additional values until the user indicates that they are finished.
You must demonstrate ALL ofthe functions of your program in your output script, i.e. do all the different searches and all the different types of updates.
The program output must be recorded in a script file from OMEGA after the program has been compiled using the gpp compiler. If you do not know how to create a script file, it is your responsibility to ask the TA or OIT how to use this function. Some helpful tips are available on the class website.
The program should NOT use:
linked lists
any topic not covered in class before the lab DUE date unless approved by the instructor
See the grading scale below for other specific implementation requirements.
Grading scale:
Code: (62%)
Program header, function headers and comments for all functions (4 points)
Modularity (division of the problem into small tasks, each one assigned to its own function and called from main() or from another function when appropriate--do not code the entire program in main!) and correct function structure as required (3 points)
Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.) (3 points)
Correct definition of class for restaurant data including
All needed data members (8)
Accessor functions (6)
Mutator functions with proper input error checking and validation (10)
Constructor (and destructor as needed) functions (4)
Correct use of public and private sections (5)
Correct separation into multiple files for class specification and member function definitions (5)
Correct manipulation of array of objects (6 points)
Correct use of >> and << with C++ streams to perform I/O (5 points)
Correct use of required control structures (3 points)
Output: (38%)
User clearly understands what is being requested for input (2 points)
Correct implementation of menus (2 points)
Search (find) tasks perform correctly (3 points)
Sorting tasks perform correctly (5 points)
Input of data to objects performed securely and correctly (5 points)
Updates to objects performed securely and correctly (7 points)
List of inputs correctly printed (4 points)
Output gives clear information to explain the values to the user (4 points)
Output contains examples of all program functions (6 points)
Deductions:
Use of global variables will result in an overall grade of 0 (zero)
Use of the exit command will result in an overall grade of 0 (zero)
Use of linked lists will result in 50 (fifty) point deduction per use
Use of goto, continue or break (outside a switch) will result in 50 (fifty) point deduction per use
Late submission of softcopy to appropriate TA will result in an overall grade of 0(zero) without prior instructor approval
Use of C/C++ language elements not yet discussed in class by the lab due date will result in potential deduction of points Ð discuss with instructor before using.