Lab08, CISC181 honors, Fall 2004

Note: This lab is a preparation for projects 2 and 3.

Lab08 introduces an "Object Oriented" version of the same program you worked with in lab06. Later, you'll take the code you produce in Lab08 and use it as the basis for projects 2 and 3.

The "restaurantManager.cpp" program: working with classes

In the lab08 directory, there is a program called "restaurantManager.cpp". This program contains a main method that looks very similar to the original restaurant program in lab06. You will also see several other .cpp and .h files in the lab08 directory. All of these files together represent an object-oriented approach to the original restaurant program.

Look over the code for each of these files and notice that each of the original options has been placed in its own member function of the Restaurant class. Also see that the manager program has a copy of a Restaurant that has pointers to Table objects. Make sure you are comfortable with them before continuing. If not, ask your instructor or TA any questions you have.

Once you are comfortable with the code that is there, copy the files from the lab08 directory into your own lab08 directory so that you can make modifications.

First task: Create a Makefile

Your first job is to create a Makefile for the lab. A Makefile has been provided for you, but it contains only comments. As a result, if you type "make", you'll get the following error:

make: Fatal error: No arguments to build

To fix this, you need to add rules to the Makefile. There is a comment for each of the rules that you need to create that guides you as to exactly what you need to do, but not how to do it.

For the how part, consult your lecture notes on Makefiles, example Makefiles from previous labs, and Appendix G in your Anderson Just Enough Unix text.

Once your Makefile is correct, typing "make", "make clean", and "make all" should work properly to compile the code in the directory, and the executable "restman" should be a working version of the restaurant manager program (with only the R, C, P, and Q menu options).

Now add the S and T options

Your next job is to add the S and T options just like you did in lab06, but this time in the context of adding "member functions to classes". (Don't add server numbers yet though; we are going to add those as part of project 2, and we'll handle it a bit differently from the way we did it in lab06).

You already know "how" to make the S and T options work (supposedly). You just have to figure out how all the class stuff works.

Setting the constructor parameters from the command line arguments

Now, modify your main program so that it takes the number of tables in the resaturant and the maximum number of guests per table from the command line arguments. Call the constructor for the Restaurant using some appropriate parameters. You will need to use the atoi function as in previous labs (with the appropriate #include and using statements as needed) to convert the command line parameters to type int. You'll also need to check argc, and print an appropriate error message if the number of command line arguments isn't correct.

Modify all methods that can be const so that they are const.

One more thing: We said in lecture that a good principle of design with classes is that any time a member function CAN be a const member function, it SHOULD be. For example, constructors and destructors can never be const.

Class foo {
  public:
    foo(); // constructors: never const
    ~foo(); // destructors: never const
    void setBar(int x); // set functions: never const 
                   //(they set the value of a data member)
    int getBar() const; // get functions: nearly always const 
                        // (they only read the value of a data member)
    void print() const; // print functions: nearly always const 
	                    // (they only read the values of data members)
  private:
    int bar;
};

For each member function in all of the classes, determine whether it can and should be const, and if so, make it const. Some of these functions may already be const, but there may be some member functions that should be const that are NOT now const.

Finishing up and Submitting

  1. Update your test plan from lab06 if need be. Note that for this lab we aren't testing server numbers. Store your revised test plan as ~/public_html/cisc181/lab008/lab008_test.txt.

    As before, your test plan may be a joint effort of up to four students, but your other work on this lab must be independent.

    You do NOT need to have your test plan approved in advance this time; you should use your own judgement and the feedback from your TA of your original test plan to determine if your test plan is reasonable. (Of course, you may ask your TA in lab or during office hours if your test plan is reasonable, but don't expect her/him to write your test plan for you.)
  2. Make a script called lab08.txt that follows your test plan. Your script should also include a "cat" of your test plan, all your .cpp and .h files, as well as your Makefile.
  3. Upload lab08.txt to WebCT (but don't submit yet) and print a copy for your TA.
  4. Now, do a "make clean", cd to the directory above your lab08 directory, and make a tar file with the command:

    tar -cvf lab08.tar lab08

    Then do the command "ls -lh" (l as in long, h as in human) to check the size of your tar file in KB; it should be no larger than 200KB if you did it right (probably a lot less.)
  5. Upload your lab08.tar files to WebCT and submit it along with your lab08.txt file.

Grading: 100 points total

What How many points Cumulative Points
Correctly editing the Makefile 10 10
Modifying .cpp and .h files correctly for new features S and T. 20 30
Initializing from command line parameters 10 40
Correctly identifying which functions should be const 10 50
Revised test plan and correct testing 20 70
General style issues 15 85
Generally "following instructions" 15 100

*** end lab08 ***

Acknowledgments: James Atlas and Phill Conrad both contributed material to the construction of this lab.