The main purpose of this lab is to get you ready to do project 1a. In fact, when you finish this lab, you'll be already part of the way done with project 1a.
There are two alternatives for project 1:
| proj1a.html | drawingMaker | simple line drawings for the web from C++ code |
| proj1b.html | wavMaker | make sound files from C++ code |
Before starting this lab, you should look over the descriptions of both projects and decide which one you want to complete.
Completing one or the the other does not "lock you in"; you are permitted to change your mind, and you are permitted to "mix and match".
But if you change your mind, or "mix and match", you'll end up doing more work, and not getting any extra credit. Once you've completed either lab4a or lab4b, you are half-way done with the corresponding project. Switching horses in mid-stream will cause you to have to start over from square one, and not earn you any extra credit. So, choose wisely.
By the time you finish either verson (lab04a + proj1a, or lab04b + proj1b), you'll have demonstrated your ability to:
If you choose lab04a + proj1a, the drawingMaker project, you'll also acquire the following skills.
Folks with some background (or interest in) drawing and visual art may find this project particularly interesting, but it is not necessary to have that background to be successful.
If you choose lab04a + proj1a, the wavMaker project, you'll also acquire the following skills:
Folks with a background (or interest in) music may find project1b particularly interesting, but it is not necessary to have that background to be successful.
| Files you will copy from my web page: | none (you might find A.dat and A.gnuplot files from lab03 helpful as models, though) |
|---|---|
| Files you will create and submit via WebCT (also print ones in bold) | lab04pent.cc, lab04star.cc, lab04s0.txt |
| Files you will create and make available on the web | ~/public_html/cisc181/lab04a/pentagon.png, ~/public_html/cisc181/lab04a/star.png |
In a previous lab, you have seen how to use gnuplot to plot points that you entered by hand using emacs or vi to create a data file (e.g. initials.dat).
Now, you will write two programs, lab04pent.cc and lab04star.cc. lab04pent.cc will draw a pentagon, while lab04star.cc will draw a five pointed star.
Both the pentagon and the star will be contained within a circle centered at the origin, with a radius of r units. (Prompt the user to enter a value for r at the beginning of the main function). You won't be drawing that circle of radius r, but you will be using that circle as a "reference" for plotting the points.
In both cases, you need to locate five points on the x,y plane. The first point will be at (0,r). On the unit circle (remember trigonmetry?) this point is at 90 degrees (or
/2 radians). The other four points will be at angles of 360/5 degrees around the circle from this point (or 2
/5).. You can use trigonmetry to determine the x,y coordinates of these points (sin(), cos(), etc.... .remember SOHCAHTOA?). Consult your Deitel/Deitel text on details of using #include <cmath> to access the sin() and cos() functions (remembering to use radians rather than degrees).
In both lab04pent.cc and lab04star.cc, you'll open an external file inside the C++ program (with ofstream). For lab04pent.cc, call this file "pentagon.dat". Write out the five points to this file, in order, and then write the first point at the end again (to close up the pentagon). Then, close the pentagon.dat file, and open another external file (you'll need a second ofstream object) called "pentagon.gnuplot". Use the A.gnuplot and CIS.gnuplot from lab03 as a model. Write out the contents of pentagon.gnuplot using C++ stream insertion operators. Set the xrange and yrange appropriately so that the entire pentagon is visible in the output file.
Then, create a shell script file penatgon.sh, similar to the following:
#!/bin/sh #pentagon.sh (your name here, date here, section number here) TARGET=$HOME/public_html/cisc181/lab04 gnuplot pentagon.gnuplot mkdir -m 755 -p $TARGET cp pentagon.png $TARGET chmod -R 755 $TARGET |
After you create this script (with a text editor), use this command to make it executable:
chmod u+x pentagon.sh
For lab04star.cc, you'll be writing out the points in a way that draws a star. Call your output file "star.dat". Define two functions called:
double xStarPoint(int pointNum, double radius);
double yStarPoint(int pointNum, double radius);
The function xStarPoint() will take a point number on the star (where point 0 is the first point, point 1, is the second point, etc. through point 4) and the radius of a circle, and then calculate a point on that circle (using trig functions). The function yStarPoint() does the same thing for the y coordinate.
(Note that when we write "xStarPoint()" with the empty set of parentheses as part of standard english text, this is a convention understood among C, C++ and Java programmers as a way of indicating in text that "xStarPoint" is the name of a function. It doesn't mean that xStarPoint() it is a function that takes no parameters. If we wrote "xStarPoint();" with an empty set of parentheses and a semicolon after it in a program, however, as a function call, that would mean that xStarPoint() takes no parameters.)
For the star, you need to connect point 0 to point 2, point 1 to point 3, point 2 to point 4, etc., all the way around the circle. You may find that the % operator is useful for doing this in a loop (mod, or "remainder after division").
You should write the program in such a way that the number of points in the star can be changed by only changing a #define, or a constant.
When you have finished writing the points, close the output file. Then, n generate the gnuplot script (star.gnuplot) by also opening as an output file, and writing it out with stream insertion operations. Set the xrange and yrange appropriately, e.g. if the radius r is 10, use [-10,+10] or [-11,+11] so that the entire star appears in the output.
What to turn in:
lab04s0.txt that covers both the lab04pent.cc and lab4bc.cc programs.lab04s0.txt, do the following steps:
lab04pent.cc filelab04pent.cc file, but don't run it yetpentagon.dat", "pentagon.gnuplot", and/or "pentagon.png" files from previous steps, and then do an ls commandlab04pent executablecat your pentagon.dat, pentagon.gnuplot, and pentagon.sh files pentagon.sh shell scriptls command to show that pentagon.dat, pentagon.gnuplot and pentagon.png now exist.lab04star.cc file (substituting "star.dat", "star.gnuplot", "star.png" and "star.sh" as needed)http://copland.udel.edu/~userid/cisc181/lab04For Step 0:
lab04pent.cc, lab04star.cc, lab04s0.txtlab04s0.txt file ls commands before and after running lab04pent, and lab04star. With the highlighter, circle the entire output of the ls command "before". Then highlight the command where you run the executable program (e.g. ./lab04pent or ./lab04star). Finally, find the new files that get created by your program and by your shell script (the ones that did not exist in the "before" output), and highlight each name. For example, for lab04pent, the files you highlight should be pentagon.dat, pentagon.gnuplot and pentaon.png. http://udel.edu/~userid/cisc181/lab04 (where userid is your userid) is readable and contains your pentagon.png and star.png files (which should also be readable).
Go to the web page http://udel.edu/~pconrad/cisc181/05F/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; lab04a is a warm-up for project 1a, 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 lab04a 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://udel.edu/~pconrad/cisc181/05F/pngFiles/lab04a.before |
| After your changes | http://udel.edu/~pconrad/cisc181/05F/pngFiles/lab04a.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.
The Makefile in this directory has several rules in it that will help you complete the project efficiently.
First, try typing "make all".
This will compile all the routines, and then run shell scripts that create each of the .png files.
Then, try typing "make install". That will create your ~/public_html/cisc181/lab04 directory, and copy all your .png files into that web directory, and set the permissions correctly.
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.)
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.)
You can (and should) read more about this in your Deitel/Deitel textbook in Appendix E; the section on linking is on pages 1242-1245.
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://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://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 |
| 30 | step0 (lab04star.cc, lab04pent.cc and lab04s0.txt) | 10 points for style, 10 points for correctness, and 10 points for following instructions. |
| 15 | CISC181 web page | Make a link to your lab04 subdirectory. (Note: the "next student, previous student" links are not required; they were included on the original lab04.html file by accident. Updated 04/05/05) |
| 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 (.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 find the description of Project 1 in the project directory of the course web site.