Previous
[ ../lab02/ ]
Next
[ ../lab04/ ]
In this lab you will test two programs based on the book and
then design and code a program that draws some kind of
smiley face.
This laboratory should be done on our lab computers and physically in the laboratory.
It needs some special libraries on our machines. They do graphics. It is non-trivial
to get graphics like these to work through the internet.
This is just like the last lab. Use the "Files" application (in Activities) to find
your "cs201" folder and
to make a "lab03" folder. Also start up a terminal/command window in this directory.
Download these files
- A program like that on page 72
[ circle.cpp ]
- A program different to that on page 72
[ circle2.cpp ]
- A program using strings and Messages
[ corners.cpp ]
- A program that draws a stickman
[ stickman.cpp ]
- A blank program to get you started on P2.22 (draw a face)
[ face.cpp ]
Open a terminal window and change directory/folder to the lab
cd cs201/lab03
then enter this command to test the "circle" and "corners" programs
Q circle.cpp
Q corners.cpp
These will compile and run the two programs for you. Notice the complex
commands needed to include the graphics libraries.
The corners program will ask for 4 characters to be type in the graphic
window.
You have to close the pop-up graphic window to get the
next program to run.
You can click circle.cpp and corners.cpp to see how they work.
Take a little time, and perhaps using the book, see what you can guess/figure
out about the code.
Compare the code in circle.cpp and circle2.cpp. What has changed?
How does this change the picture they draw?
What does this teach you about Point and Circle?
You can use
Q stickman.cpp
to compile and run this program.
Study the stickman.cpp file and use
gedit stickman.cpp &
(or by right clicking the image of the file in Files)
to give the figure a skirt instead of legs. You can use
Q stickman.cpp
to compile it and run it.
If you get this far before the end of the lab session you have earned an
B.
First think about how a "smiley" face is made out of parts that
you know how to program: lines and circles.
Look at the example in P2.22 in the text.
The real problem is the set of steps "// 1.", "// 2. " and so on
that you need to draw a face. So start by writing them as
comments in English. This is your algorithm.
The next problem is getting the parts of the face in the right place.
It helps if you have a piece of paper with the coordinates on it
and a pencil to do a rough sketch of what you want.
You need to fill
in the blanks in the "face.cpp" file (downloaded above).
gedit face.cpp &
Your first step should be to
put your name as the author.
You may look at "circle2.cpp" by opening it in "gedit"
and copy/paste code from it to "face.cpp"
When you are ready fill in the blanks in the face.cpp program
and test the result:
Q face.cpp
Does the compiler object to your code? If you can't guess why
call us over...
Fix the error and try again until the program runs...
If you don't like the look of your graphic.... think
about what has gone wrong and fix it.
. . . . . . . . . ( end of section Drawing a face) <<Contents | End>>