Lab #3 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:   Linked list

                              String manipulation

                              Unions and enums

                              File output

 

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 second lab we changed the data representation, added some calculations and speeded things up. Now we are going to make our data representation more flexible, add some union and enumerated type values (really), play with strings a little more, and print output to a file as well as to the screen. 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 “iterated prototype” lab assignment will be:

 

¨              Introduce the restaurant recommendation system to a new user.

¨              Create a linked list of structs to store all of the restaurant data in by reading data from a file and creating the structs in the list as needed.

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

1) Using the data in the list, 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

x.   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

      i.    Manipulate strings to change list data

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 #3:

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 linked list of structs to store all of the restaurant data in by reading data from a file and creating the structs in the list as needed.

For lab #3 as 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 will dynamically allocate space for each new restaurant struct and link the struct into a list with the other 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. 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 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.

o      Meals available – this will be an enumerated type value indicating one of the following things: (Hint: declare an enumerated type that has one value to represent each of the choices below)

                  Breakfast only,

                  Breakfast and lunch only

                  Breakfast, lunch, and dinner

                  Lunch only

                  Lunch and dinner

                  Dinner only

                  All day

                  24 hours

                  Other

o      Meal info –this value will contain specific data about meals based on the meals that are available above. This value will be a union with the following information:

If the restaurant serves breakfast, is open all day, or open 24 hours, then the meal info will contain an integer representing the predicted minimum number of seats in the restaurant (to be calculated)

If the restaurant serves lunch only or lunch and dinner, then the meal info will contain a floating point number representing the expected cost for two people to have lunch. (to be calculated)

If the restaurant serves dinner only, then the meal info will contain a percentage of likelihood of getting a dinner reservation on the same day (to be calculated)

 

The program must read data from an input file named “lab3inSpr07.dat”, store each restaurant in a newly allocated struct, and link the structs in a list. If desired, the program may create the list in sorted order but this is not required. There will be a sample data file posted on the website which your program must run with. You will not know ahead of time how many restaurants are in the input file. The program should read input until it has run out of data (reached EOF).

 

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 linked list as specified above.

 

To read the data from the file, your program should read the elements from each line and store the data in a struct. 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 five remaining pieces of information in each struct, Average wait time, Average entrée cost, Family restaurant, Meals available and Meal Info calculate each piece of this data as follows and store the value into the struct.

 

For Average wait time perform the same recursive calculation as in Lab #2. 

 

For Average entrée cost, perform the same calculation for each restaurant as in Lab #2.       

 

For Family restaurant use the same codes and determinations as in Lab #2.

 

For Meals available determine the correct enumerated value to store by using the following algorithm:

1.   If the restaurant opening time 1 is midnight (0000) and closing time 1 is one minute to midnight (2359) then the enumerated value should represent 24 hours

2.   If the restaurant opening time 1 is before 10am and closing time 1 is after 7pm then the enumerated value should represent all day

3.   If the restaurant opening time 1 is before 10am and closing time 1 is before 1pm and opening 2 and closing 2 are -1 then the enumerated value should represent breakfast only

4a. If the restaurant opening time 1 is before 10am and closing time 1 is after 1pm but before 5pm and opening 2 and closing 2 are -1 then the enumerated value should represent breakfast and lunch

4b. If the restaurant opening time 1 is before 10am and closing time 2 is before 5pm then the enumerated value should represent breakfast and lunch

5a. If the restaurant opening time 1 is before 10am and closing time 1 is after 7pm and opening 2 and closing 2 are -1 then the enumerated value should represent breakfast, lunch, and dinner

5b. If the restaurant opening time 1 is before 10am and closing time 2 is after 7pm then the enumerated value should represent breakfast, lunch, and dinner

6.   If the restaurant opening time 1 is 10am to 11am and closing time 1 is before 5pm and opening 2 and closing 2 are -1 then the enumerated value should represent lunch only

7a. If the restaurant opening time 1 is 10am to 11am and closing time 1 is after 7pm and opening 2 and closing 2 are -1 then the enumerated value should represent lunch and dinner

7b. If the restaurant opening time 1 is 10am to 11am and closing time 2 is after 7pm then the enumerated value should represent lunch and dinner

8.   If the restaurant opening time 1 is after 3pm and closing time 1 is after 7pm and opening 2 and closing 2 are -1 then the enumerated value should represent dinner only

9.   For any other time combinations then the enumerated value should represent other

 

For Meal info determine the correct union value to store by using the following algorithm:

If the restaurant serves breakfast, is open all day, or open 24 hours, then the meal info will contain an integer representing the predicted minimum number of seats in the restaurant. The calculation for the number of seats is as follows:

·     If there are no children’s or seniors’ menus then the union value is number_of_entrees times 2.

·     If there is a children’s menu but no seniors’ menu then the union value is number_of_entrees times 0.5.

·     If there is no children’s menu but there is a seniors’ menu then the union value is number_of_entrees times 1.5.

·     If there is both a children’s and a seniors’ menu then the union value is number_of_entrees.

If the restaurant serves lunch only or lunch and dinner, then the meal info will contain a floating point number representing the expected cost for two people to have lunch calculated as:the average entrée cost plus the lowest entrée cost.

If the restaurant serves dinner only, then the meal info will contain a percentage of likelihood of getting a dinner reservation on the same day calculated as (100 - (average wait time * 3)) with this number being used as a percentage. (E.g. if average wait time is 30 minutes then the percentage likelihood of getting a same day reservation is 100 – (30 *3) = 100 – 90 = 10 so 10%. Any percentage that comes out negative should be recorded as 0)

 

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. Print this data to the screen and to an output file which your program should create. Only create one output file and use it for all the file output in the program.

 

 

¨              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.

 

i-   Search for a restaurant

All search options (1. – 10.) should call search functions that perform linear search on the appropriate members of the linked list of structs. Allow the user to enter a value(s) to search for. Where possible, these search functions should first call the appropriate sorting function and then search on the sorted linked list.

 

When the search is complete your program should print the search result(s) to the screen and to an output file 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 linked list for the restaurant name sort, the average entrée cost sort, 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 list. 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, give the user a menu of the following options:

 

o               Change Restaurant name

o               Change Restaurant code

o               Change Type of food

o               Change Number of entrée choices

o               Change High entrée cost

o               Change Low entrée cost

o               Change Distance in miles

o               Change Children’s menu available

o               Change Seniors’ menu available

o               Change Age of the restaurant

o               Change First hours of operation– opening time of that particular restaurant

o               Change First hours of operation– closing time of that particular restaurant

o               Change Second hours of operation– opening time of that particular restaurant

o               Change Second hours of operation– closing time of that particular restaurant

o               Change Days open in the week

o               Return to main menu

 

If the user wishes to change a restaurant name, give them the option of modifying the existing name or of entering a new name. If the user chooses to modify the name, specify the ways in which it can be modified (change letters, change words, etc.). Use string functions to accomplish these modifications.

 

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, meals available, and meal info). After each change (and any recalculation) is made, print all of the restaurant info for the updated restaurant to the screen and to an output file.

 

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. You may reuse your data file from Lab #2.

 

Implementation requirements:

The program should use the following data structures:

A struct type for recording restaurant data

A linked list of structs for storing restaurant data from file

Input data file

Output 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 and buld the linked list

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

Bubble sort, linear 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 use 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:   (64%)

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

Correct use of output data file (2 points)

Correct manipulation of the linked list (12 points)

Correct definition and use of struct type (3 points)

Correct use of enumerated type (3 points)

Correct use of union (3 points)

Correct use of required control structures (3 points)

Correct use of string functions for name updates (3 points)

Correct function structure as required (3 points)

            Bubble sort implemented on linked list (5 points)

            Linear search implemented on linked list (4 points)

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

Output:      (36%)

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

            Search (find) tasks perform correctly (5 points)

            Calculations for union performed correctly (4 points)

            Enumerated type value determined correctly (3 points)

            Sort tasks perform correctly (7 points)

            List of inputs correctly printed (4 points)

            Output correctly recorded in output file (3 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) Types may be declared globally.

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

            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.