The main purpose of this lab is to get you ready to do project 1. In fact, when you finish this lab, you'll be already part of the way done with project 1.
By the time you finish (lab04 + proj1) you'll have demonstrated your ability to:
cout
, and to external files using ofstream
objects.int
and double
(passed by value), and call these functions where appropriate. ostream
(by reference).for
loops, nested for
loops and if
/else
.You'll also acquire the following skills.
gnuplot
to create graphics.gnuplot
files and data file for gnuplot
from a C++ program.Go to the web page http://www.udel.edu/CIS/181/pconrad/06S/pngFiles/proj1 and look at the .png files you see there. Each is a picture that you will draw as part of project 1. You'll draw these pictures by making some changes to a C++ library stored in a pair of files called drawings.cpp/drawings.h, and then writing some C++ programs that utilize this library.
In each case, you'll draw a picture that looks just like the one shown—with one exception: the file called drawPhillsPicture.png will be called drawXXXXsPicture.png in your directory, where XXXX is your own first name. The figure drawXXXXsPicture.png will be different from mine; it will be an expression of your own creativity. You'll read more about that when you look at the instructions for project1. For now, I just wanted you to start by looking at these files; lab04 is a warm-up for project 1, and I wanted you to have an idea of where this lab is headed.
Now look at the files in each of two web links below. They show a set of .png files produced by the code that you can copy from the lab04 subdirectory on the course web page (under the labs link.) The "before" pictures show the .png files that are produced when you run the programs as they are right now. The "after" pictures show what the png files should look like after you are finished with some changes to the C++ code.
Before your changes | http://www.udel.edu/CIS/181/pconrad/06S/pngFiles/lab04.before |
After your changes | http://www.udel.edu/CIS/181/pconrad/06S/pngFiles/lab04.after |
You should notice several differences. The following tables explains the differences, and where you will be making changes in the C++ code that result in the "after" pictures instead of the "before" pictures.
.png file | before | after | what you need to do | notes (see below) |
drawTexasFlag.png | blank rectangle | Texas flag | change the drawTexasFlag function in drawings.cpp | 1 |
drawNightFlags.png | headless snowman | snowman has a head | change the drawSnowMan function in drawings.cpp | |
3 stars in sky | 6 stars in sky | add some more calls to drawStar in the drawNightFlags.cpp file | 2 | |
2 flags | 3 flags | add the French flag (see details below) | 3 |
Notes on this table:
Note that this step is just "understanding what you are supposed to do". Before you actually dive in, look over steps 3 and 4.
To get started, create a directory for lab04, with the command:
mkdir ~/cisc181/lab04
Then use the following command to copy all the files you'll need for this lab into your lab04 directory:
cp -r /www/htdocs/CIS/181/pconrad/06S/work/labs/lab04/* ~/cisc181/lab04
Then change your working directory to the lab04 directory, and list the files in the directory.
cd ~/cisc181/lab04 ls
You'll see a file with the name "Makefile". This file helps to "customize" the actions of the "make" command to help you complete the project more efficiently. To see how this work, first, try typing the following command:
make all
This will compile all the routines, and then run shell scripts that create each of the .png files.
Then, try typing the following:
make install
That will create your ~/public_html/cisc181/lab04
directory, copy all your .png
files into that web directory, and set the permissions correctly. As you can see, the Makefile file automates a lot of the tedious work of maintaining a complex software project.
Look at the contents of the Makefile, and try to understand the "make install" rule. The -p flag on the mkdir command makes sure that in case the directory already exists, no error message is created. the "-m 755" option builds a "chmod" for the directory into the mkdir command. Make sure you are familar with both of those Unix commands for the next exam (ask your TA and/or your instructor for help if you are not sure.) Ask your instructor to explain the contents of the Makefile in lecture.
You won't need to modify the Makefile for this lab. However, you'll need to modify it for project 1, so try to understand all the steps in the Makefile and what they do. Ask your TA for help during lab, and your instructor for help during lecture if you have questions. Your Anderson textbook also has information about Makefiles.
Make the changes in drawings.h, drawings.cpp, drawNightFlags.cpp.
Use the "make clean", "make all", and "make install" commands as needed to see the necessary changes take place in the .png files. You can use a web browser to check the contents of those files as you work.
Note that you can just type "make" instead of "make all".
A side note: note that in the drawings.cpp file, I used "#include <iomanip>", "using std::setiosflags" and "setiosflags(ios::fixed)". This is apparently what you have to do to get around the problem that some older version of g++ don't support the "fixed" keyword properly.
Once you have finished this, and all of your drawings look right, and your code is ready to turn in, you have two more things to do for this lab: update some links on your web page, and create a "tar file" to submit. The remaining steps in this lab will walk you through all of that.
You'll be adding a "link" to your lab04 directory on your web page. This section explains how to do that.
Note: Even if you already know a lot about HTML, read this section. It contains terminology that might be on the next two exams.
First, as background, let's clarify the difference between your personal web page, which is controlled by the file ~/public_html/index.html, and your CISC181 web page, which is controlled by the file ~/public_html/cisc181/index.html. If I direct you to add something to your CISC181 web page, you should use emacs (or vi) to change the file ~/public_html/cisc181/index.html.
Next, let's understand how to "add a link" to a web page. Up until now, you've added links by following examples. Here's the "theory" behind adding a link.
In HTML (the language used to describe web pages), an "element" is anything in the following form:
<foo>
... </foo>
In this case, foo
is the name of the element. The element is tagged with a start tag such as <foo>, and a close tag such as </foo>. The name of the tag is surrounded in with the less than (<) and greater than (>) signs, i.e. < >. These symbols are often called "angle brackets" in this context, since they are not being used to signify less than or greater than.
Some elements are defined with tags that contain attributes. An attribute is listed as part of the opening tag. For example, to make the words my lab04 files link to the directory ~/public_html/cisc181/lab04, one would include the following text in the HTML file:
Here is a link to |
Note that the <a>
open tag includes the text href="http://udel.edu/~userid/cisc181/lab04"
. This is called the href
attribute of the <a>
tag (a stands for anchor). The href attribute lists the URL of the target of a link. The </a> close tag show where the link ends. This form of link is called an "absolute" link becaues it links directly to a specific absolute location. You could move this HTML code to any location on the web and it would still point to the same place.
Another way to specify this link is with a so-called "relative" URL. The relative URL is shorter to type because it relies on the fact that you know something about where the HTML file is located. For example, suppose you know that your HTML code is stored in the following file on strauss: ~/public_html/cisc181/index.html. In that case, you can specify a link to the files in ~/public_html/cisc181/lab04 with the following HTML code:
Here is a link to |
Note that the "dot slash" (.
) refers to the "current directory", just like it does in Unix commands. So, ./lab04
refers to the lab04 subdirectory of the current working directory, i.e. the one where this index.html files is located, i.e. ~/public_html/cisc181. This way of specifying the directory is shorter, and it can also be more efficient. An key difference with this technique is that if the HTML file is moved, the link it contains doesn't point to the same place anymore; it will point to the ./lab04 subdirectory of whatever directory that html file is moved to. (So, that's one more thing you need to know for your next exam: the difference between an "absolute" link and an "relative" link.)
In this step, you will add a link to on your CISC181 web page that helps your TA find your lab04 files. By this point in the lab, the subdirectory ~/public_html/cisc181/lab04 should already exist, it should contain your two .png files, and those files should be readable on the web.
So now, make a link to that directory (which is accessible by the URL http://copland.udel.edu/~userid/cisc181/lab04) on your CISC181 web page.
As a reminder, your CISC181 web page is the file ~/public_html/cisc181/index.html, and is referred to by the URL http://copland.udel.edu/~userid/cisc181.
Don't start this step until you have finished all your programming, and are ready to submit your work. However, don't wait until this last minute; you may need some time to figure this part out.
A "tar" file is a file that allows an entire collection of files to wrapped up into a single file.
You may be familiar with "zip" files, which are often used to distribute software packages on Windows PCs, or "sit" files which are used to distribute files on Macintosh computers. The files known as "tar" files are similar.
(A bit of history: "tar" originally stood for "tape archive". It's still the format sometimes used to store backup files on tape drives.)
To create a tar file from your lab04 files, follow these steps:
tar -cvf lab04.tar lab04This command says "create a new tar file named lab04.tar"
-cvf lab04.tar
part) and put all the files from the subdirectory lab04 into it.tar -xvf lab04.tarThis command should expand the lab04.tar file, and leave you with a new subdirectory ~/cisc181/test/lab04 that contains all of the files from your lab04 directory. Change your working directory into that directory and use the "ls" command to list your files. Then, try the "make clean", "make all" and "make install" commands and make sure that everything still works properly. If so, then you can now submit "lab04.tar" as your submission to WebCT.
ls -lh
to see how large each file is in bytes, KB, MB, or GB.)Points | What/Where | Issues |
15 | CISC181 web page | Make a link to your lab04 subdirectory. |
10 | drawNightFlags.cpp | Adding code for 3 new stars, and drawing the French Flag |
30 | drawing.cpp | Adding a drawFrenchFlag routine, adding a head to the snowman, and fixing the Texas Flag. |
5 | drawing.h | Adding a function prototype for the drawFrenchFlag routine. |
20 | lab04.tar | Correctly creating the tar file. (-10 points if you didn't do a make clean before you created it; the tar ball should not contain any .o files, .dat files, .png files, .gnuplot files, or executables.) |
10 | style | style issues throughout all C++ code (.cc or .cpp and .h files) in the code that is the part YOU modified. |
10 | following instructions | completing all steps per instructions on this web page and general course policies. |
You will soon find the description of Project 1 in the project directory of the course web site.
(If you are finished with lab04, and Project 1 isn't "available" yet, email your instructor.)