Lab07, CISC181, Spring 2006

Introduction

In this lab, you will do test driven development of a class Rational_C that represents a rational number. A rational number is one that can be represented as a fraction, with an integer numerator and an integer denominator.

Typically, rational numbers are presented in reduced form. That is, the numbers 50/100, 5/10, 2/4, and 3/6 should all be reduced to 1/2.

One advantage of representing rational numbers as a fraction of two integers is that this is an exact representation. The rational number 2/3 has no exact representation in a finite number of decimal or binary digits. However, it can be represented exactly as the ratio of two integers.

Getting started—files and directories

The files for this lab are in the lab07 directory in the usual place—a lab07 subdirectory on the web site. See previous labs for examples of how to copy these files into your directory. And remember, of course, to make a new lab07 subdirectory before you get started.

Step-by-Step Instructions

  1. Copy the files into your lab07 directory

  2. Type "make clean", "make". Note that the tests all list "failed".

  3. Look at the code in the files testRational.cc, rational.h, and rational.cc (I would suggest looking at them in that order). Understand what is happening there. Make sure that all the tests are correct.

    Note also that some "correct behavior" is defined by the tests. For example, if the rational number is negative, the numerator should be the negative integer, not the denominator.

    The getDenom() function should always return a positive value. If you think the tests are incorrect, check with your instructor or TA before changing them.

  4. Fill in code in rational.h and rational.cc so that all the tests pass. Remove any comment lines containing @@@; either delete them entirely, or replace them with appropriate comment lines of your own.

  5. Add at least three tests of your own in the testRational.cc file. These can be functions calls to existing tests, or new tests.

  6. When finished, make a script lab07.txt containing your source code, your Makefile, and results of doing make clean, make all, and running the test program.

  7. Then, do a make clean, and create a tar file lab07.tar with only your source code, and Makefile. Nothing else should be inside the Makefile (except possibly the lab07.txt script—including that is optional, not required.)

    The tar file should be created from "above" the lab07 directory so that when you expand it, all the code is created inside a lab07 subdirectory. That is, cd into the directory "above" the lab07 directory before you run the command to create the tar file.

Finishing up and Submitting

  1. Print the lab07.txt script file and give to your TA
  2. Upload the lab07.txt script file, and your lab07.tar file to WebCT and submit.

Grading: 100 points total


Valid XHTML 1.1 Valid CSS!