In CS70, you will often be working with code supplied by the professor as part of the assignments. Only code provided by the professor, or written by yourself and your pair-programming partner, may be used to complete assignments. Even if you think a particular bit of code is not central to the essence of the assignment, you may not use code written by anyone other than the professor or yourself. This includes code from the book.
If you have any questions about this policy, ASK FIRST. In the past, students have gotten into serious trouble because they assumed something was OK without asking first.
More information on the honor code can be found on the administrivia page.
The program for this assignment, and everything else except the README file, is due at 9 PM on Wednesday, January 28th, 2004. The README file is due at midnight on the same day (i.e., the moment Thursday begins). Refer to the homework policies page for general homework guidelines.
This assignment has several purposes:
You have been hired by a small company that develops Web sites. Your first job will be to make modifications to a system developed by the firm's star programmer, who was recently killed in a tragic unicycling accident.
The system that the programmer developed is large and complex, but the programmer did a good job of dividing it up into small pieces. He even wrote special test programs that exercise the fundamental classes that the system uses. You have determined that you will need to modify one of those classes, which performs arithmetic on rational numbers.
Unfortunately, when you look at the code for the class and its test program you are dismayed, for it seems that the star programmer was far more concerned with whether the code worked than whether it was maintainable. In fact, it seems that he religiously followed the unmaintainability rules. After a few minutes, you go to your boss and tell her that it will be quicker to first spend time cleaning up the programming style, and only make the necessary modifications after the program has been made readable. Your boss agrees, and because the original code is so bad, she will even allow you to do a bit of renaming that will have effects elsewhere (see Tricky Stuff).
Your task for homework #1 is to clean up the style of the rational-number class and its associated test program. There are no known bugs in the program, so you can concentrate on simply cleaning it up without changing the output produced by the test program.
The program is composed of three files:
In addition, there is a so-called Makefile,
which makes it easy to compile the program on Turing by simply typing
make at the command prompt.
CS70 uses a CVS-based submission system to make it easy for you to work with your partner. To get started, go to wherever you plan to keep your CS70 assignments and type:
cs70checkout hw01This will create a directory named
hw01, containing the four files listed above. (NOTE: You can't use
cs70checkoutuntil the professor has created a group for you and your partner. A message will be sent to the class list when all groups have been created.)
When you have done some work, type
cs70submit to submit
what you've done so far. See the submissions documention for more information.
(NOTE: If you decide that some of the file names are
bad, and rename the files, you must use:
cs70submit new-nameonce after you change the name.
Your final submission should consist of five files:
rat.hh), you must make corresponding changes in the Makefile. It is up to you to decide whether to rename these files. If you do so, be sure to modify all places in the Makefile where they are mentioned.
Your Makefile must work correctly, and
must produce an executable named
assign_01. The graders will be using
make to compile your program.
rat.hh. You are allowed to choose any name you like, so long as:
rat.cc. You are allowed to choose any name you like, so long as:
.ccsuffix (or another extension accepted by g++,
makestill works with the name and suffix you choose.
cs70submitabout the file (you only need to do that once).
cs70submit to submit your solution.
submit early and
If you discover a mistake in your program, you can resubmit it using
the same command. You can submit as many times as you like; only the
last version will be used.
Since the README file is due later than the rest of the assignment,
you must submit it separately (unless you have it done before the
deadline). You can do this with the
cs70submit READMEIf you have changed any of your other files, DO NOT use
cs70submitwithout arguments to submit the README file, or it will appear that you missed the deadline even though you were really on time. It's safest to use the command above.
The class defined by
implements a simple rational-number package. Rational numbers are
represented as a pair of integers, the numerator and denominator. For
convenience, the class ignores the fact that any real-life computer
imposes a maximum value on integers.
The code you have been given is, to the best of our knowledge, correct and bug-free. However, it is written with very bad style. Your sole task is to improve the style, not to fix bugs. If you find any bugs, you should note them in the README file but should not fix them. (If you find no bugs, the README should mention that there are no known bugs.)
The requirement of no bug fixing is, perhaps surprisingly, very realistic. As a general rule, when you are correcting style in the real world, you should not fix bugs at the same time. If you follow this rule, it will be much easier to find out what happened after the fact, especially when you use a source-code control system (a subject you will study later, in CS121).
The revised class and test program must produce output identical to
that from the
original. You can check that the output is correct using the
diff command. Before you start editing the program, do a
test run and save the output, as follows (% represents your
shell prompt, which will almost certainly be different on Turing):
% make % ./assign_01 > original.out
The above commands will compile the program (
./assign_01), and save the output into a file named
> original.out). You can
use that file later to make sure the output
There are a lot of things wrong with the program in this assignment. Here are some hints about what you might want to play with:
As mentioned above, you can compile the program by
make at the command prompt. One of the
many advantages of using
make is that it will run the
compiler with switches that check for all sorts of simple errors.
Your program must compile without any warning messages when
the compiler is invoked with the
-Wall -pedantic switches
(as happens when you use
If you are new to Unix, you may be wondering how you can test your program.
To run your program, simply type "
the quotes). Since this program requires no input, you should
immediately see the output on your terminal. If the program
misbehaves badly, you can abort it by typing control-C.
You can look at the output of the original version by typing
original.out. Alternatively, you can use the
diff command to compare the output of the original with
the output of the new version:
% ./assign_01 | diff original.out -If the two versions produce identical results, you will see no output on your screen. For example, if you changed "yup" to "yessss!", you would see something like:
9c9 < yup --- > yessss!
Every assignment in CS70 must be
accompanied by a
README file. The file
must be named
README in all uppercase
letters. A detailed specification of the
README file can
be found on the homework
policies page. For this assignment, make sure the
README file contains:
For the most part, you should be able to complete this assignment without knowing anything special about C++. However, it will help to know a few things:
RationalNumberthat is implemented in a pair of files named
classdeclaration. However, for this assignment you are allowed to leave the code where it is. Just make it pretty.
constkeyword and the
&symbol. Just trust that they are correct.
a = b;).
a += b;).
a++). There are two versions of this operator, one with and one without an
intargument. The first version implements
++aand the second handles
a + b).
a - b).
a * b).
a / b).
a < b).
a == b).
With every assignment, there are parts that can surprise you. Some of the "gotchas" in this assignment include:
make clean" followed by "
make". That will usually reveal any problems that might have been masked by an incorrect Makefile. (This will become important on later assignments.)
/* * I'm not yet sure what the next three lines do. I think they have * something to do with handling end-of-file. GHK 1/19/00 */
There is more information on using C++ on Turing available in the departmental quick-reference guide and the C++ quick reference guide.
© 2004, Geoff Kuenning
This page is maintained by Geoff Kuenning.