CPSC230
Project Scrabble
Part 2: done.cc
Due: 9:00PM Wednesday, February 18, 2004

Note: Remember that you must have a partner for every programming assignment that you turn in. The comments should indicate who typed for every session that you met your partner and worked on the project. You and your partner should both turn in the project, and your submissions should be identical.
  1. Goals

    The goal of this assignment is that you:
    1. become familiar with classes
    2. get practice testing and compiling larger programs
    3. get practice writing functions

  2. Assignment

    For this part of the assignment, you will write a function done that returns true if all the letters in the box are used and false otherwise. This function is part of the letterbox class, so the prototype is already written for you in letters.h You will write the function definition.

    The function body should check to see if nbrleftinbox is 0. If it is, return true; otherwise, return false. You should not declare nbrleftinbox; it is declared in letters.h.

    The function header looks similar to the function prototypes, but there are a few details to discuss.

    Classes and member functions

    We will talk about classes in more detail later, but we have already mentioned them in class and you have used them in your rover program (you used strings). In this program, you will write a function definition for a function that is part of a class; that is called a member function. To make a function a member function, there is only one change to make from other functions: before the name of the function, put the name of the class, then the scope resolution operator (::). For example, the board class has a function at which returns the letter at a location on the board. The source code for this is:
    char board::at(int row, int col) const
    {
        if ((row > DOWN) || (col > ACROSS))
        {
    	return OUT_OF_BOUNDS;
        }
        return contents[row][col];
    }
    
    Don't worry too much about how the function is accomplished; just look at the header. Notice the board:: before the function name at. You will need to put the name of the class (letterbox) and the scope resolution operator (::) before your function name (done) as well. This tells the compiler that this function is the function definition for the done prototyped in letters.h.

    I have put the file board.cc in my Public directory so you can view the source code. board.o is board.cc compiled (using the command g++ -c board.cc). Remember the "-c" tells the compiler to compile only, not to link. The compile only step makes an object file, but not an executable file because, among other reasons, there is no main function, so you would receive an error if you tried to compile board.cc into an executable file. If you are having trouble with the function header for done, look at board.h and the prototype for at, and board.cc with the function definition for at to try to figure out how to do done. Otherwise, unless you're interested in the source code for board.cc, just ignore it. You do not need it for this project.

    const

    When we talked about constant variables (e.g., const double mypi=3.14159;), I mentioned that const is used in several different ways. The done function (and the at function of the board class) is a const function. That means that nothing in the class is modified; this function only uses information. We'll go into more detail about that later. For now, just put the word const at the end of your done function header since the prototype (in letters.h) must match the function header. Look at the at function definition and prototype in board.h and board.cc if you have questions.

  3. Compiling

    1. To compile your done.cc, compile it using the "-c" option described above and in the first project assignment.
    2. Recopy board.h and letters.h into your directory because I have modified them both slighly (added comments).
    3. Then, compile done.o with all of the other object files you used for the first part of your project: your instr.o and /home/lambert/Public/board.o, /home/lambert/Public/letters.o and /home/lambert/Public/project.o to make an executable file.
    4. I have made a make file for you just like last time which you can use to do the compiling for you. Copy Makefile (capital 'M') from my Public directory into your directory. Type make (lowercase 'M', just like in the last project) in the directory where done.cc is. Makefile will automatically find the objects in my directory. If you using the same directory as you did for instr.cc, you will need to remove your previous makefile. Makefile will compile your done.cc file and create an executable for you named game (assuming you have no syntax errors). The file automatically finds my files that you need.

      The make command will automatically do the compilation for you. If you want to recreate your game file and your done.o file, type make clean

      If you want to use the board with darker colors, substitute board2.o for board.o in your

    5. Testing your program will be tricky; you must test that it can return true (that there are no more letters left), and false (that there are still letters left) correctly. Write in a comment how you tested both true and false cases.
    6. Submit your done.cc file.

  4. Documentation and Grading

    Your program should conform to the documentation standards described in my programming style guide. You should have one comment describing what the function does. Do not worry about preconditions and postconditions yet. You must have one comment describing how you tested your program to make done return true and to make done return false

    You will receive a maximum of a 50 for a program that has syntax errors. You will receive a maximum of 75 for a program that compiles, but does not execute correctly. You will receive a maximum of 87 for a program that runs correctly, but does not have a comment indicating how you tested the true and false cases for done. Additional points off will come from not following the program style guide, and from other errors.

  5. Turning in the second part of your project

    This part of your project should be contained in a single source code file called instr.cc

    You should submit this program with the command

    /home/lambert/cpsc230/handin230 2 2 

    because this is the second part of the second assignment that you are turning in using the handin program. (Refer to submission web page.)