CISC105, Project 3, Fall 2004

Introduction

This project is a short and sweet project to give you some practice with strings and with building on previous code.

You will build on either the tables.c program from your lab06 or your project 2. You will add three options for servers:

  1. an A option to allow the manager to assign servers to tables (by number),
  2. an N option to allow the manager to assign server names to correspond to the server numbers (e.g. server 0 is Fred, server 1 is Nancy, etc.,
  3. an F option to allow users to choose their favorite server.

If you were successful at least up through stage 4 of project 2, then build on project 2. That will allow you to earn up to 100% of the points for project 3.

If you had significant difficulty with project 2, and want a fresh start, you may build on lab06 instead. That will only allow you to earn up to 90% of the points for project 3, but it will be an easier task, since you won't have to make the new A, N and F options interact with the tableCapacities array.

A note for those who included merge/unmerge in Project 2: It is acceptable to build on a project 2 that is complete only up through stage 4; it is not necessary to include the merge/unmerge option in your project 3. (Note that if you do include it, it should interact successfully with the new N and F options, and there is no extra credit for including it, so you are strongly encouraged to work from your Stage 4 "snapshot" from Project 2.)

Reminders about academic honesty

Develop your program in stages

See the project two description for details about how to work in stages. Several students ignored this advice duirng project 2 and discovered (the hard way) why they should have followed it.

Assignment Description

Stage 1: Preliminaries (0%)

Create a proj3 directory, and copy either

into a file called proj3.c in this directory. This file is your starting point for project 3.

Stage 2: The "A" option (Assigning Server Numbers) (65%)
(55% if built on lab06 instead of project 2).

In this stage you'll add a feature that allows the manager to keep track of a number of servers (waiters and/or waitresses), and which table each one is assigned to. Each table will be assigned a server. An array called tableToServer will "map" table number to server number; that is, the index of the array will be the table number, and the value in the array will be the server number.

Here are step-by-step instructions:

  1. The maximum number of servers that the program will be able to handle will be 10, but this number should be specified in a #define so that it can change. As your first task in this stage, add a #define to indicate this (choose an appproriate name.)

  2. Now add a variable called "numServers". This variable should always be less than or equal to the maximum number of servers specified in your #define.
  3. By default, the number of servers will be four. However, you should add a command line parameter so that the the number of servers can be changed to some other number.

    If you are building on lab 6, your program will have only one command line parameter. That parameter will be the number of servers. If that parameter is not included (i.e, if argc is equal to 1), then use the default number of servers (i.e. 4). If that parameter is included (i.e. if argc is equal to 2) use the atoi() function to convert argv[1] to an integer, and use that as the number of servers (provided the value is between 1 and the maximum number of servers permitted). If it is outside that range, print an error message and exit the program. You should also exit the program is argc is not either 1 or 2.

    If you are building on project 2, your program may have either 0, 1 or 2 command line arguments. If it exists, argv[1] will be the number of servers. If it exists, argv[2] will be the name of the data file for table capacities. You can test the value of argc to see whether argv[1] and/or argv[2] exist. Use default values for any missing command line arguments. Print an error message for any values that are not legal (e.g. number of servers out of the legal range, a filename that can't be opened, or if argc is not 1, 2, or 3)

    Here are example command lines for the program:

    > ./proj2
    > ./proj2 2
    > ./proj2 6 HarveysDiner.dat 
    > ./proj2 2 HarveysDiner.dat 
    > ./proj2 3 ChezPhillipe.dat

    The first line indicates that the default table capacities and the default number of servers (4) should be used. The second line indicates that you are using 2 servers instead of 4 (and if building on project 2, the default table capacities of 2, 2, 4, 4, 6, 6 should be used for 6 tables.) The remaining command lines are appropriate for building on project 2, and indicate both the number of servers, and the name of the file to take the table capacities from.

  4. Now that we have a way to get the "number of servers" into the program, we need to do something with that information. Assume that each server on duty is assigned a number between 0 and numServers - 1.

    Define an array as follows to keep track of which server is assigned to cover
    each table.

    int tableToServer[TABLE_MAX];

    If tableToServer[i] = s, that means that server s is the server covering table i. Values in the tableToServer array that refer to tables that are not "in use" in the restaurant are assigned the value -2; the value -1 indicates that the table is "in use" in the restaurant, but has not yet been assigned a server.
  5. It will be up to the manager to assign servers to tables. You'll need to initialize the tableToServer array to all -2 values at the start of the program, and then initialize the values from 0 to (number of tables - 1) to -1.

    Then, add an "A" option into the program to "assign" servers to tables. That A option should cycle through all the tables starting with table 0, up to the end, and for each table, print out:

    1. the table number,
    2. the capacity (note: if building on lab06, this is a fixed number)
    3. number of guests currently at that table (if any)
    4. the server number already assigned to that table (if any).

    After printing each table assignment, permit the manager to change the server assignment if either (a) there is no server assigned currently, or (b) if the table is currently empty (no guests). To keep the dialog short, if the manager wants to keep the assignment the same, he/she should type in the same server number as the one already assigned. (Otherwise, you'd have to ask "do you want to make a change" each time, and the dialog will get really tedious.)

    For tables where there are guests, just print the information, and move on to the next table (it's bad form to change the server at a table that already has guests at it; typically this is not done.)

    If no server is assigned yet, don't print "server=-1;" instead print a message such as "no server assigned".

    Do permit the manager to enter -1 to indicate that a table has no server assigned. (That allows the manager to put a table out of service, if, for example, there is a leaky roof or some other problem that makes a certain table unusable).

    After each change that is made, echo the "new" information back to the user (e.g. print out table number, capacity, number of guests and the new server). It would be appropriate to create a function to print out this information, and call it whenever you need to print out those values.


  6. Now, change the P option to also print out server numbers along with the table number, capacity, and number of guests. Here's an opportunity to call that function we were just talking about and make your coding simpler.
  7. Now, change the options that assign guests to tables to check whether a table has a server assigned; don't permit either the S or R options to reserve tables that have no server assigned.

Stage 3: Adding the "N" option (entering server names) (80%)
(70% if built on lab06 instead of project 2).

Now add an option that permits the manager to assign names to each server. That is, the manager can enter information that identifies that server 0 is "John", server 1 is "Mary", etc.

You will add an array such as the following:

#define SERVER_NAME_MAX 20

char serverNames[10][SERVER_NAME_MAX];

In my example code above, I used "10", but this is just to illustrate the idea: you should actually use the #define that you created in the previous stage that indicates the maximum number of servers.

This declaration of serverNames indicates that is is an array that can hold up to 10 strings, each of which can be up to 19 characters in length (remember one extra char is needed for the '\0').

The N option will ask the user of the program to enter a server number. If the server number entered is -1, the N option is finished, and you go back to the main menu. Otherwise, if the server number is in the valid range (0 to 9), the program prompts for the server name. If the server number is outside the valid range, and isn't -1, print an error message, and prompt the user again for the server number.

Initially, each server name should be the empty string (i.e. "").

Now, modify the P option: When you are finished adding the N option, modify the P option so that it prints the server name for each table in addition to the server number, table number, and current number of guests (and, if building on project 2, the table capacity as well.) If you used a function to print out each line of "table information", then adding the printing of "server name" into the function makes it work with the A option as well (a nice plus!).

Stage 4: Adding the "F" option (choose table by favorite server) (100%)
(90% if built on lab06 instead of project 2).

Now, add a new option F that allows a customer to specifiy the name of their favorite server and size of their party. The F option will search through the list of tables for either the first fit or best fit table that has that server, will fit their party, and is available, and will assign the party to that table. If no such table is available, the F option will indicate this, and go back to the main menu.

As in Project 2, the choice to do first-fit, or best-fit is up to you (see project 2 for more description of the two options.) However, you'll earn 5 more points for doing best-fit (which is only slightly harder) vs. doing first fit (which is only slightly easier), so try to use a "best fit" approach.

Submission Instructions

Scripting your project: make a test plan

You need to create a script called "proj2.txt" showing that all of the features of your program work correctly. As with project 2, you are not required to "turn in" a formal test plan, however you should think through a test plan before you script your project, and most likely, you should write this test plan down before you start your script.

Your testing needs to be as complete as possible, covering both legal and illegal inputs. If your program is capable of performing an action, your test plan should cover that action. if your program is capable of detecting an error condition and printing an appropriate message, your test plan should include those cases as well.

As always, your script should include a listing of your program, a listing of each input file that you use, followed by a clean compile, and your sample runs. Putting the items in that specific order will make it easier for your TA to grade your project. Making things easier for your TA tends to result in higher marks.

What to submit

Style Issues

Review the style issues from project 2 regarding programmer-defined global variables, and full function prototypes, and make sure you follow those guidelines for this project as well. Also review the rubrics on your TAs web site to familiarize yourself with other style issues that he/she is emphasizing.

Grading

The following table indicates, in general, the amount of credit assigned to each portion of the assignment. Your TA might (at his/her discretion, and under supervision of the instructor) further refine each of these items into a more detailed grading rubric. Consult with your TA for more details.

Also note that while 20 points are assigned "overall" to "following instructions" and "coding style", the TAs have the discretion to deduct additional points from the individual portions of the assignment for these issues as appropriate. Deductions may also be made from individual portions of the assignment for "incomplete testing".

Stage Explanation Percent Cumulative Total
All Following submission instructions 10 10
All Overall coding style 10 20
All Building on project 2 rather than lab06 (i.e. making all new options interact correctly with the table capacities features introduced in project 2) 10 30
2 Adding the A option to indicate server numbers. 10 50
Adding server numbers to output of P option 5 55
Modifying the S and R options to only assign tables that have been assigned server numbers. 10 65
3 Adding the N option for adding server names to the program. 10 75
Adding names into the P option 5 80
4 Adding the F option for choosing favorite server by name. 20 100
Note: 5 out of the 20 points are reserved for making your F option pick the "best" fit and not the "first fit" table for the favorite server indicated.

Penalties (this penalty are like a "tax" applied to your grade after deductions taken above)


Credits: Professors Terry Harvey and Phill Conrad contributed text to the description above, and collaborated on the source code provided. Some of the ideas for features were contributed by CISC105 students from Fall 2004 as part of their lab06 submissions. TA Sara Sprenkle also made many helpful suggestions.

*** end of project 3 description ***