make (actually gmake) utility, and to
give you some more practice writing C++ programs.
We are providing the following auxiliary document which you should peruse before doing the corresponding part of the lab:
gmake.
mc38 directory, create a new subdirectory
called graphics-fun, and then copy the following file
into the graphics-fun directory:
cp ~mc38/labs/graphics-fun/triangle.cc graphics-fun
The program triangle.cc is the shell of the program you
are going to expand into a solution to exercise P3.2. We are providing
it since it includes the correct files and provides a starting point
for you to write the Makefile you need in order to use
gmake.
Now go to the graphics-fun directory and open up
triangle.cc in emacs.
triangle.cc from emacs
using the following command, which I will have explained in class:
g++ -I ~mc38/lib/cccfiles\
-o triangle triangle.cc\
-Wall -g\
~mc38/lib/cccfiles/ccc_x11.cpp\
~mc38/lib/cccfiles/ccc_shap.cpp\
-L /usr/X11R6/lib\
-lX11
I have purposely put this command on multiple lines in order that you
can more easilly see its parts. The back-slashes (\) at the end of
the lines indicate that the line continues, so that these six lines
amount to one command. If you copy and paste this into the shell, it
will function as one command. If you want to type it on a single
line, remove the back-slashes.
Makefile that will
cause the exact same compilation to occur when you execute the
following command:
make -k
Note that this is the default command when you do M-x
compile in emacs. This implies that you will no longer have to
remember what compile/link command to issue from one emacs session to
the next; the Makefile remembers it for you.
In order to correctly write Makefile, you will need to
read the online notes on Using gmake, at least
through (and including) the section Basic Operation and Syntax.
triangle.cc so that
it solves programming exercise P3.2.
Makefile
and demonstrate that it causes the correct compilation to occur.
Makefile so that it will
simultaneously maintain both this program and the one you just wrote.
clock.cc in
the same directory as triangle.cc and
Makefile. Note that you will have to include
ccc_time.cpp in addition to ccc_win.cpp.
You also need to link in the math library by tacking -lm
onto the end of your compile/link command.
Makefile so that it simultaneously
maintains the two programs. The easiest way for
you do this is to create a new .PHONY dependency called
(for example) all that depends on the two executables
you are maintaining. Then make sure that you have separate
dependencies for each of them. (You don't need an action for this
.PHONY dependency.)
clock.cc so that it
solves programming exercise P3.16. Be sure that you don't use magic
numbers in your code; use constants instead. Note that
it's easiest to measure all angles clockwise from midnight.
Makefile
and demonstrate that it causes the correct compilations to occur.
Makefile so that it will
simultaneously maintain both this program and the one you just wrote.
better-clock.cc
the add twelve ``tick-marks'' around the clock you drew in the
previous part corresponding to the twelve hours. Be sure to update
Makefile so that it maintains all three programs.
You are free to use a for loop even though you haven't
read about it in the book yet. The following piece of C++ code
outputs the numbers from 1 to 12:
for (int i = 1; i <= 12; i++) {
cout << i << endl;
}
Makefile.
Makefile
and demonstrate that it causes the correct compilations to occur.
Makefile (1 point)Makefile so that it defines and uses the following
variables.
(These variables names, though seemingly obscure, are
standard.)
CXX should be the g++ compiler.
CC should also be the g++ compiler.
CPPFLAGS should be arguments related to include files
(-I)
LDFLAGS should be arguments related to linking
(-L and -l)
CXXFLAGS should be other flags (debugging, warnings)
Once you've defined these variables, a typical rule will be:
triangle: triangle.cc
$(CXX) ... triangle.cc -o triangle ...
where you'll need to fill in the ... with appropriate
variables. You won't need to use the $(CC) variable.
Makefile and
demonstrate that it causes the correct compilations to occur.