Extra Credit Pre-Lab Assignment , CSE 1320 Spring 2007

 

Due Date:          See section website for due date

(see instructions on website for how to turn this in)

 

Topic objectives:    Arithmetic and relational operators

                              Control structures

                              Functions

                              1 - dimensional arrays

                              Data types

                              Modular programming structure

                              Error checking

                              Programming style

 

The goal for this lab is to provide an opportunity for practice of the topics covered in Chapters1–4 and parts of Ch. 5 and 6 in Deitel and Deitel.  These chapters will not be covered in detail in the 1320 class and it is assumed that the student is familiar with and can use all the concepts in those chapters.  This assignment is designed to practice those concepts by creating a program.  The format of this assignment is similar to the assignments that will be required for the rest of the semester so a student who is unsure of their skills can use this assignment to refresh them and to ask the instructor or TA about any concepts they are unsure of.  Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties.  You may NOT use global variables, the exit command, goto, break (except in a switch), continue, structs, multiple dimension arrays, strings, passing by reference (except arrays), linked lists, or switch statements.

 

 

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 are considering 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.

 

To start developing your restaurant recommendation program you want to first start by creating the program structure and putting in some simple functionality. 

 

The tasks for this pre-lab assignment will be:

 

¨                  Introduce the restaurant recommendation system to a new user.

¨                  Create one-dimensional arrays to store each type of the restaurant data in and then populate the arrays with data.

¨                  Create and display a screen menu of the following choices for the user.

1) Using the data in the arrays, search for restaurants by

i.    Cost

ii.    Distance

iii.   Type of food

iv.   Number of choices

v.   Children’s and seniors’ menus availability

2) Update the data in the arrays–this will take the user to a submenu for doing updates

3) End the program

 

 

Each of these tasks is described in more detail below. There are also a number of simplifying assumptions for this pre-lab. Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for the pre-lab:

a) All distances will be calculated from Nedderman Hall at UTA.

b) All restaurants are open for the same hours so this data is not needed for this pre-lab

c) Each restaurant serves only one kind of food.

 

Task Descriptions:

 

¨                  Introduce the restaurant recommendation system to a new user.

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.

 

¨                  Create one-dimensional arrays to store each type of the restaurant data in and then populate the arrays with data.

For the pre-lab, the restaurant data will be stored in a set of seven (7) one-dimensional arrays of 10 elements each which are described below. Do NOT use multi-dimensional arrays for this pre-lab. The seven 1-dimensional arrays are as follows:

o                   Restaurant code – an integer array of ten elements that holds the numeric code associated with a particular restaurant for a total of ten restaurants.  For this lab we aren’t using strings so we will simply have a fixed set of restaurants that are coded by number (ex. McDonald’s = 009, Nizza Pizza = 125, etc.) and that list would be displayed in the output as described below.  For all the other pieces of data, the index [n] for some restaurant code will refer to the same restaurant for all other info as well.

o                   Type of food– a character array of ten elements that holds the letter code for the type of food served at the restaurant.  You must specify in your comments and in your information for the user what the meaningful character abbreviations are. Ex:‘H’ for hamburgers, ‘P’ for pizza, ‘I’ for Indian food, etc. as YOU define it.  The type of food for restaurant  [n] corresponds to restaurant code  [n].

o                   Number of entrée choices– an integer array of ten elements that holds the number of different entrees available at that particular restaurant [n].

o                   Average entrée costs– a floating point array of ten elements that holds the average cost of an entrée at restaurant  [n].  (In later labs we will calculate this.)

o                   Distance in miles– a floating point array of ten elements that holds the distance in miles from UTA Nedderman Hall to restaurant  [n].

o                   Children’s menu available– a character array of ten elements that holds a value indicating whether or not a children’s menu is available.

o                   Senior’s menu available– a character array of ten elements that holds a value indicating whether or not a seniors’ menu is available.

 

Given these seven arrays the user must enter data for at least 8 restaurants and no more than 10 restaurants. Your program must first ask the user to enter the count of how many restaurants they are storing and should check to make sure this count is between 8 and 10. [Note for development: start with a smaller number of restaurants then increase to 8 when program is working well ] If the user’s number exceeds 10, the program should inform the user that 10 is the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (index= 0, 1, …count-1) to read and store input in one of the two following ways Input Method A or Input Method B.

 

Input Method A:

a.   Ask the user for the restaurant code (don’t forget to supply a list of names and codes for them.) Read in their char, make sure it is a valid code and then store it in the Restaurant code array at [index]

b.   Ask the user for the type of food using the single character description (don’t forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the Type of food array at [index]

c.   Ask the user for the number of entrée items available at the current restaurant.  Make sure it is a valid number (are there negative entrees anywhere?) and then store it in the Number of entrée choices array at [index]

d.   Ask the user for the average cost of an entrée at the current restaurant.  Make sure it is a valid number (are there negative entrees anywhere?) and then store it in the Average entrée costs array at [index]

e.   Ask the user for the distance in miles from Nedderman Hall to the current restaurant.  Make sure it is a valid number and then store it in the Distance in miles array at [index]

f.    Ask the user if the current restaurant has a menu for children.  Store a value in the Children’s menu available array at [index] indicating if there is such a menu or not

g.   Ask the user if the current restaurant has a menu for seniors.  Store a value in the Seniors’ menu available array at [index] indicating if there is such a menu or not

 

Input Method B:

Your program may ask the user to enter all the information for one restaurant on the same line.  This data would be a restaurant code, a char for type of food, a number of entrees, an average cost per entree, the distance from Nedderman Hall, a char indicating whether a children’s menu is available, and a char indicating if a seniors’ menu is available.   You must tell the user exactly how to enter the line of data.  The data for a single restaurant will be entered by the user on one line as follows {there must be one space only between the values}:

 

>  009 H 14 3.99 0.1 Y N

 

where 009 represents the restaurant code for McDonald’s, H is the char for hamburgers food type, 14 is the number of entrees at McD’s, 3.99 is the average cost of one of these entrees, 0.1 is the distance in miles from NH to McD, Y indicates that there is a children’s menu and N indicates that there is NOT a seniors’ menu..  Your program will read the first number and store it in the restaurant code array at some location index, then read and store the char into the corresponding location index, in the food type array, then read and store the third number into location index in the number of entrees array, and so on.  Your program should read all the numbers and chars within a single input command.  Your program should read in as many lines of input for restaurants as were originally specified up to the maximum of ten lines of input (restaurants). 

 

Input verification:

When the user has entered count number of restaurants print out all the input restaurant data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels.

 

 

¨                  Create and display a screen menu of choices for the user.

Once all the data is read into the arrays your program should give the user a screen menu with the following choices:  (use any number scheme you wish)

i-    Search for a restaurant by cost

ii-   Search for a restaurant by distance – user gives a preferred range

iii-  Search for a restaurant by type of food

iv-  Search for a restaurant by number of choices available

v-   Search for a restaurant by whether it has children’s and/or seniors’ menus available

vi-  Update restaurant data

vii- End the program

 

All of the search options should call search functions that perform linear search on the appropriate array of data. If you have one or more searches that use the same type of data, you may pass in the value to look for and the array to search and use the same search function for both. 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.

For distance searches be sure to include the distance to the restaurant in the output info.

 

The update option should take the user to a second screen to allow them to update information in the arrays.  This screen should ask for a restaurant code from the user and search for that restaurant.  If multiple restaurants with that code are found, ask the user for the distance (i.e. in case two McDonald’s are in the list).  Once the correct restaurant is determined save its [index] and give the user a menu of the following options:

 

o                   Change Type of food array at [index]

o                   Change Number of entrée choices array at [index]

o                   Change Average entrée costs array at [index]

o                   Change Distance in miles array at [index]

o                   Change Children’s menu available array at [index]

o                   Change Seniors’ menu available array at [index]

o                   Return to main menu

 

For any change the user wishes to make, do the same error checking as in the original data entry section.  After each change is made, print all of the restaurant info for the restaurant at [index].  

 

When the user chooses “End the program” from the main menu, print a concluding message and then gracefully end the program.

 

Inputdata:

Go online and collect data for at least 10 different restaurants in DFW.  You must include at least five different types of restaurants, e.g. you cannot have 5 McDonald’s and 5 Pizza Huts in your list. J  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.

 

 

Implementation requirements:

The program should use the following data structures:

One dimensional integer, character, and floating point arrays for recording restaurant data

 

The program should use the following control structures:

Function calls to perform tasks

A while or for loop to read the input data

If, if-else, or nested ifs to error check the first number and implement the menu options

 

The program should NOT use:

structs

multiple dimension arrays

switch statements

global variables

exit

break

continue

pointers

            any topic not covered in class before the lab DUE date unless approved by the instructor

 

The program should be implemented as a set of functions with a main routine and at least one function for getting input from the user, one for a find function, and one for calculating total cost.  You may use more functions than this but you must use at least this many. 

 

The program should perform the following actions in the given order:

Declare and initialize the variables

Print a welcome screen for the user that introduces the system

Get the needed input value from the keyboard

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

 

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.

 

This program must be run with three different sets of data for the restaurant data.  You must create three data sets and run your program with them.  You may run it three times within a single execution or you may execute the program three different times so that you have a total of three different data sets. The sample data sets that you create must meet the guidelines given in the problem definition.

 

The program output must be recorded in a script file from OMEGA using the gcc 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.  

 

Grading scale:

Code:   (61%)

Program header and function headers for all functions    (8 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!)  (16 points)

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)  (8 points)

Correct manipulation of the 1-dimensional arrays  (9 points)

Correct use of required control structures (6 points)

Correct function structure as required (6 points)

Proper implementation of input error checking (8 points)

Output:   (39%)

            User clearly understands what is being requested for input (5 points)

            Search (find) tasks perform correctly (10 points)

            List of inputs correctly printed (4 points)

            Output gives clear information to explain the values to the user (8 points)

            Output contains all the sample data and two additional data sets  (12 points)

 

Deductions:

            Use of global variables will result in an overall grade of 0 (zero)

            Use of the exit, break, or continue command will result in an overall grade of 0 (zero)

            Use of structs, multiple dimension arrays, strings, linked lists, and/or switch statements 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 language elements not yet discussed in class by the lab due date will result in potential deduction of points – discuss with instructor before using.