The following files should be in the lab04 subdirectory. To find and copy these files into your account, see the detailed instructions below.
The files for this lab are at http://udel.edu/~pconrad/cisc181h/04F/labs/lab04.
They can also be copied directly from ~pconrad/public_html/cisc181h/04F/labs/lab04.
From this point on in the semester, if I tell you the files for the lab are in the "lab04 directory in the usual place", you'll be expected to know from experience where to look.
If you forget where to look: Note that my website, http://udel.edu/~pconrad, has links to guide you to the web location of the files. You can "right click" in many web browsers to bring up the lab04 directory in its own window, so that you can see the full URL for the directory (the use of "frames" on my web page might "hide" that URL unless you do this.)
To convert a full URL into a filename or directory name on strauss:
(This is something you need to know for the exams.)
To convert "http://udel.edu/cisc181h/04F/labs/lab04"
to a directory name:
Hopefully the following commands are familiar to you. If not, you should be doing more reading in your Anderson textbook!
The command "cp -r ~pconrad/public_html/cisc181h/04F/labs/lab04 ." (don't forget the final dot and the space before it) will copy the entire directory into a lab04 subdirectory under your "current directory". Typically, that directory should be ~/cisc181 for a command of this form.
The command "ls ~pconrad/public_html/cisc181h/04F/labs/lab04" will give you a directory listing of that directory.
The command "cp ~pconrad/public_html/cisc181/04F/labs/lab04/file.foo ~/cisc181/lab04" will copy a single file from that directory into the directory ~/cisc181/lab04. If the target directory is your current directory, you can put "." in place of "~/cisc181/lab04"..
In this part of the lab, you will work with some simple nested loops in C++ that draw little boxes.
Please allow me to acknowledge right up front: these little "box drawing" programs are not particularly useful in and of themselves. In fact these programs are rather silly. So why are we doing them?
Consider that these programs are like "layup drills" in basketball, or "playing your scales" on a musical instrument; they re-enforce basic skills that will be useful later. Trust me: you are learning something valuable. Questions such as these also tend to show up on exams, so doing a few in lab is probably good practice. Finally, this is a warm up for an assignment that is definitely more useful: producing a table of wind chill factors.
CC -o boxOfStars boxOfStars.cppNote that we use the
-o boxOfStars flag to name the executable boxOfStars instead of a.out
./boxOfStars
cat boxOfStars.cpp or use the text editor to look at
the source code for this program and understand how it works. Look at the nesting
of the for loops, and compare the for loops that start at 0 vs. those that
start at 1. Also, compare the use of <= vs. the use of < in
the tests on the for loops. Finally, look at the use of the mod 2 operations
(%2) in the last loop in order to alternate between printing x and o.starField that writes a square pattern
on cout like
the one in the table below alternating between stars and spaces. The
function should take one integer parameter called width,
and return void.
Here are sample outputs for various values of width (Note
that your function should be prepared to take any integer as input; I'm
just showing several examples to give you the idea of the pattern.).outlineBox that returns void and
takes height and width as integer parameters, and
c as a character (char) parameter.. This function produces
the outline of a box similar to those in the table of example
output shown below.| width | output |
| any number <= 0 | (no output at all) |
| 1 | * |
| 2 | * * * * |
| 3 | * * * * * * * * * |
| 4 | * * * * * * * * * * * * * * * * |
| etc... | |
| 8 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
| etc... |
| parameters (height, width, c) | |
| 3,4,'x' | xxxx x x xxxx |
| 5,3,'x' | xxx x x x x x x xxx |
| 3,3,'o' | ooo o o ooo |
| 7,7,'*' | ******* * * * * * * * * * * ******* |
| 2,7,'*' | ******* ******* |
| 7,2,'*' | ** ** ** ** ** ** ** |
| 7,1,'*' | * * * * * * * |
| 1,7,'x' | xxxxxxx |
| 1,1,'x' | x |
| 1,2,'x' | xx |
| 1,3,'o' | ooo |
| Any input where height or width is less than or equal to zero (or both are less than or equal to zero) | no output |
In this part of the lab, you'll learn how to read from cin (standard input)
until the "end of file" is detected. From the keyboard, you signal
end of file by typing "CTRL/D".
Later, you'll learn how to "redirect" standard input so that it comes
from a file on the disk; at that point, the end of the file itself will mark
the end of input.
readUsernames.cpp from the lab04 directory
into your current directory.
./readUsernames < usernames.txtmakeHTML.cpp from the lab04 subdirectory.
Edit it, and look over the source code. In this program, I've taken out all
the prompts for input, and replaced all the output with "cout <<" statements
that will produce HTML code. The result is that when you run the program
with ./makeHTML < usernames.txt./makeHTML < usernames.txt > usernames.html
> usernames.html" part of the command line
is a shell feature that says "take the standard output (the cout stuff)
and put it into a file called usernames.html". Use "cat usernames.html" to
look at the contents of the usernames.html file.
A "grading rubric" explains how an assignment will be graded. This is a "general" rubric. After reviewing your submissinons, your TA might develop a more specific rubric that explains individual deductions. You can get an idea in advance of what those deductions might look like by examing past rubrics; ask your TA for details.
Total: 100 points.