Lab #2 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:   Structs

                              String manipulation

                              Unions and enums

                              Recursion

                              Searching (binary search)

                              Sorting (merge sort)

                              File input

 

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.

 

In the first lab, we developed a partial prototype for our restaurant selector. Now we are going to improve the data representation, develop more sophisticated routines for calculating wait time, and speed up our sorts and searches. The task descriptions tell what each task entails and the implementation requirements specify certain things that must be done certain ways for this lab.

 

The overall tasks for this “improved prototype” lab assignment will be:

 

¨              Introduce the restaurant recommendation system to a new user.

¨              Create a larger array of structs to store all of the restaurant data in and then populate the arrays with data through input from a file and through calculation of some values.

¨              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.    Total cost estimate for dinner for x number of guests

ii.   Distance

iii.  Type of food

iv.  Number of choices

v.   Children’s and seniors’ menus availability

vi. Newness of the restaurant

vii. Hours and days of operation

viii. Average wait time

ix.  Family friendliness

2) Sort the array by average entrée cost, restaurant name, food type, or distance

3) Update the data in the arrays–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. You might want to imagine that your program would be used by two different people, one who inputs the data and then another one who uses the data to search and sort and update. There are also still a few simplifying assumptions for this lab. Many of these simplifications will be eliminated in later labs.

 

Simplifying assumptions for lab #2:

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

b) Each restaurant serves only one kind of food using the codes given below

 

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 a larger array of structs to store all of the restaurant data in and then populate the arrays with data through input from a file and through calculation of some values.

For lab #2, all of the data for a single restaurant will be stored to together in a struct. There are some additional pieces of data to store in the struct that have not been stored before. The data elements are described below. To store all the restaurants your program should declare an array of 40 restaurant structs.

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.

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    Steak

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 1000 military 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.

 

Given the array of structs the program must read data from an input file named “lab2inSpr07.dat” and store it into the correct array. There will be a sample data file posted on the website which your program must run with. There may be more or less than 40 restaurants in the input file. The program should read input until either it has run out of data (reached EOF) or until it has read 40 lines of restaurant data into the array. Each line of the file will have the following data items in the following order each separated by a single space. Note that these data items correspond exactly in order to the list of data above:

 

restname restcode foodtype numchoices highcost lowcost dist childrens seniors age opening1 closing1 opening2 closing2 daysopen

 

So as an example, Rocco’s Pasta, coded as 072, with Italian food, 32 choices, high entrée cost of $11.50 and a low entrée cost of $4.50, 1.8 miles from Nedderman Hall, with a children’s menu but no seniors’ menu, a restaurant age of 8.5 years, and hours of operation from 11am to 3pm and then 5pm to 11pm Monday through Saturday would look like the following line in the input file:

 

Roccos_Pasta 072 I 32 11.50 4.50 1.8 Y N 102 1100 1500 1700 2300 MTWRFS

 

Your program must create a file variable and link it to the file “lab2inSpr07.dat” and open the file for reading. Then the program must read the data from the input file into the struct restaurant array as specified above.

 

This means that in the struct array restaurant[n].name will have the name of the nth restaurant and restaurant[n].code will be the restaurant code for the nth restaurant in the list, restaurant[n].food will be the type of food of the nth restaurant in the list, etc.

 

To read the data from the file, your program should read the elements from each line and store the data in the struct array. Make sure to 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

 

Data Calculation:

For the three remaining pieces of information in each struct, Average wait time, Average entrée cost, and Family restaurant, calculate each piece of this data as follows and store the value into the struct.

 

For Average wait time perform the following recursive calculation for each restaurant:        

·     If the restaurant closing time is 8:30pm (or earlier) then Average wait time = 0.

·     Otherwise if the restaurant closing time is later than 8:30pm and the club is more than three years old, Average wait time is 5 minutes + wait_time_calculation of closing time minus 30 minutes (30 minutes earlier)

·     Otherwise if the restaurant closing time is later than 8:30pm and the club is more than one year old and up to three years old, Average wait time is 10 minutes + wait_time_calculation of closing time minus 20 minutes (20 minutes earlier)

·     Otherwise if the restaurant closing time is later than 8:30pm and the club is less than one year old, Average wait time is 15 + wait_time_calculation of closing time minus 15 minutes (15 minutes earlier)

 

For Average entrée cost, perform the following calculation for each restaurant:        

·     If the restaurant number of entrees is less than 10 then Average cost = (highcost * 3 + lowcost) / 4;.

·     If the restaurant number of entrees is between 10 and 30 then Average cost = (highcost + lowcost) / 2;.

·     If the restaurant number of entrees is greater than 30 then Average cost = (highcost + lowcost * 2) / 3;.

 

For Family restaurant use the following code and determination:

      V   Very family friendly if it has a children’s menu, a seniors’ menu and an average cost less than $10.

      F    Family friendly if it has (a children’s menu OR a seniors’ menu) and an average cost less than $10

      S    Somewhat family friendly if it has (a children’s menu OR a seniors’ menu) and average cost <= $15

      U   Not family friendly if none of these combinations are met

 

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.

 

 

¨              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

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.

 

i-   Search for a restaurant

The first six search options (1. – 6.) should call search functions that perform linear search on the appropriate members of the array of structs. Allow the user to enter a value(s) to search for.

For searches 7 – 10, the search functions should use binary search. Since binary search requires a sorted array, these search functions should first call the appropriate sorting function and then search on the sorted array.

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 and/or multiple answers, print all results. If the search has no results be sure to inform the user.

The search options should be:

1-   Search for a restaurant by number of choices available

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

3-   Search by restaurant age

4-   Search by hours and days of operation

5-   Search by average wait time

6-   Search by family friendliness

 

7-   Search for a restaurant by name

8-   Search for a restaurant by the estimated cost of a meal for x number of people

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

10- Search for a restaurant by type of food

 

For hours and days search, let the user choose either times or days and then search. The day search will have to use string functions on the days_open_during_the_week member to determine if the restaurant is open on the desired days.

For the average wait time search get the user’s maximum wait time and then search the average wait times.

For family-friendliness let the user pick what level they desire (V, F, S, U) and then return all restaurants at that level or higher unless the user picks U in which case just return the U restaurants.

For the estimated meal cost search you must ask the user to enter the number of diners x and the maximum acceptable meal cost. Your program then performs the following calculation for each restaurant:                 estimated meal cost = average entrée cost * 1.5 * x

      If the estimated meal cost is less that the user’s maximum the print the restaurant and the estimated cost for the user.

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

 

ii-   Sort the restaurant data

The sort options should call sort functions that perform as follows. Perform bubble sort on the arrays for the restaurant name sort and the average entrée cost sort. Perform merge sort for the food types sort and the distance sort. Don’t forget that all members have to be swapped but also that structs can be assigned to each other. (Declare a temp struct in the swap)

 

 

iii- Update restaurant data

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 name 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 Restaurant code at [index]

o               Change Type of food at [index]

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

o               Change High entrée cost at [index]

o               Change Low entrée cost at [index]

o               Change Distance in miles at [index]

o               Change Children’s menu available at [index]

o               Change Seniors’ menu available at [index]

o               Change Age of the restaurant at [index]

o               Change First hours of operation– opening time of that particular restaurant at [index]

o               Change First hours of operation– closing time of that particular restaurant at [index]

o               Change Second hours of operation– opening time of that particular restaurant at [index]

o               Change Second hours of operation– closing time of that particular restaurant at [index]

o               Change Days open in the week 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.

Be sure to recalculate any values that are dependent on the changed values (average cost, average wait time, family friendliness). After each change (and any recalculation) is made, print all of the restaurant info for the restaurant at [index].

 

iv-  End the program

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

 

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.

 

 

Implementation requirements:

The program should use the following data structures:

A struct type for recording restaurant data

Array of structs for storing restaurant data from file

Input data file

 

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

Switch if desired

Recursion for the average wait time calculation

Merge sort, bubble sort, linear search, binary search

 

The program should NOT use:

global variables

exit

break

continue

            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 search function, one for a sort function, one for calculating wait time and one for calculating estimated 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 file

Print the appropriate outputs

Let the user enter additional choices 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:   (65%)

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

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

Correct use of input data file (6 points)

Correct manipulation of the struct array (9 points)

Correct definition and use of struct type (7 points)

Correct implementation of recursion (5)

Correct use of required control structures (3 points)

Correct function structure as required (3 points)

            Merge sort implemented (4 points)

            Binary search implemented (4 points)

Proper implementation of input and update error checking (6 points)

Output:      (35%)

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

            Search (find) tasks perform correctly (5 points)

            Calculation of estimated cost performed correctly (4 points)

            Recursive calculation of wait time performed correctly (5 points)

            Sort tasks perform 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 all the sample data and two additional data sets (2 points)

 

Deductions:

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

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

            Use of linked lists 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.