Lab 1 - Statistician Class


Due Date: Midnight, Wednesday June 2

This lab will give you hands on experience in implementing a class, demonstrating many of the concepts covered in chapter 2 of the text.

  1. Create a lab1 directory in your 2440 directory. Keep all of your files for this lab in that directory.

  2. Copy the files stats.h, stats.o, stattest.C, statexam.C, and makefile from the directory /usr/local/apache2/htdocs/u/cs/rt/cs2440_sm04/labs/lab1/ to your lab1 subdirectory. For example, if you are in your lab1 subdirectory,
       % cp /usr/local/apache2/htdocs/u/cs/rt/cs2440_sm04/labs/lab1/stat*.* .
    
    will copy stats.h and stats.o to your lab1 directory where stats.o is the pre-compiled object code for a functioning version of the statistician class and makefile is a file you can use to help build your programs.

  3. Compile the statexam program by doing the following:
       % g++ -Wall statexam.C stats.o -o statexam
    
    Run the program to see what it does. After you write your own version of stats.C, this is the output you want to see.

  4. Compile the stattest program by doing the following:
       % g++ -Wall stattest.C stats.o -o stattest
    
    Run the program to see what it does. Do some of the commands given in the menu to see how the statistician is supposed to work. You will use your version of stats.C with this program to help in debugging your version. Answer the following questions using the program (these will help you understand the behavior of a statistician object):

  5. Write a short program in a file named main.C that will declare a statistician object, read 5 numbers from the user, giving each number to the statistician, and then print out all of the statistics provided by the statistician object for the numbers entered. To compile the program use the following command:
       % g++ -Wall main.C stats.o -o main
    
    Note that to use the statistician class, you just need the following in main.C
        #include "stats.h" 
    
        using namespace main_savitch_2C;
    

  6. You are now ready to start developing your version of the implementation file, stats.C. Make a copy of stats.h to stats.C.
       % cp stats.h stats.C
    
    To begin transforming stats.C into the implementation file, edit it by deleting the class definition, and put stubs in for each member function. Use the documentation already provided as the documentation for each function. At this stage you should have a stats.C file that will compile and run with any of the programs compiled earlier (statexam, stattest, or main). Of course, with stubs nothing will work correctly yet. Implement one member function at a time, compiling and testing each one before moving on to the next one.

    For more discussion of the statistician class, click here

  7. Once you begin working with your version of stats.C you may find it helpful to start using the makefile provided.

    To build either your statexam, stattest, main, you can type:

        make stattest
        make statexam
        make main

    You are not required to use the makefile or understand what it is doing. We'll be using makefiles more extensively in the future, however. For more reading on makefiles, see a make tutorial

  8. Have your main.C, stats.h, and stats.C by the due date in your lab1 directory. Leave a readme file fi you need to explain something on compilation.