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.
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.
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).
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.
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.
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.
tar -cvf lab08.tar lab08| 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.