CMSC 10600 Fundamentals of Computer Programming 2
Winter 2002 --- N. Russo and S. Salveter
Homework 5 -- 1000 Files
Due Friday 15 February 2002
In the last assignment, you created a few classes representing
points and various shapes which were made up of points. This time
you'll be modifying your code to be more scalable, more readable,
and more functional.
Turn in your program in the usual way, as described in
Instructions for Handing in Assignments.
Introduction
Until now, we've kept all our code in one file. As we begin to
write larger programs, that will make things more and more difficult.
Our code will be hard to read, and will take a long time to compile.
If we separate related code into separate files, we will effectively
increase the level of data and procedural abstraction, reduce
re-compilation time and improve readability. If our code is easy
to read, it will be easy to update, debug, and expand.
Assignment
- Start with your solution to hw04, making sure you fix any lingering
problems.
- Make all your class types into abstract data types. This means
all member variables should be private. It also means
that code like this should work:
Point X(35,40), Y(90,105);
Point Z = X + Y;
That is, you should overload whatever operators you think would
be helpful for the users of your classes.
- Overload operator<< for all your shapes, so that we don't
need the draw functions anymore. Something like this should work
in your main function:
Triangle A(X,Y,Z);
cout << A << endl;
- Add translate member functions to each shape. Both of these code
fragments should work in your main function, and should have the
same effect:
Triangle A(X,Y,Z);
A.translate(Point(30,40));
|
Triangle A(X+Point(30,40),
Y+Point(30,40),
Z+Point(30,40));
|
In both cases I'm using a Point like a vector. If this is unfamiliar,
talk to a TA or instructor.
I can add in some text like this:
gsave
0.8 setgray
/Helvetica-Bold findfont 64 scalefont setfont
60 400 translate 3.2 rotate 0 0 moveto
(Nick Russo) show
grestore
Add another shape called Text which contains a Point as a starting location,
and a c-string or c++ string to print out when it's draw function is called.
- Use while or for in your main function to create a sequence of similar
objects. Each iteration of the loop might change the position, size,
or even linewidth of the object. Be sure to output the object you create
each time, as the variable that holds it will be local to the loop.
- Separate the code into .cpp and .h files.
- Write or generate a makefile which describes the relationships
between the various files in your project.
(example makefiles)
- Turn in several files: makefile, main.cpp, point.cpp, point.h and cpp
and h files for each shape you define. Also turn in a text version
of your Postscript output as well as the interpretted version.
Extra Credit
- Use rotate and loops to draw an object moving through a parabola,
or other curve. Or have it bounce off the edge of the page.
- Write classes for 3D objects and come up with reasonable 2D
representations for printing out.
- Get carried away and represent a viewing angle so the same 3D
objects look different depending on our angle.
- Write a rendering engine for Quake which outputs Postscript.
This assignment was inspired by a similar one given by Todd Dupont in 1998 for CS116.