In this lab, you will do the following:
Turn to page 61 in your lab manual, and look over pages 61-64. Completing the exercises described here is the first part of your lab this week. To get started, you will copy a file into your account that looks like the "template" code on page 62.
cp ~pconrad/public_html/cisc181/04F/labs/lab02/lab02a.cc .
In this part of the lab, you will work with some sample code called lab02b.cc.
Where to find the sample code: Use the same command I gave
you above for copying lab02a.cc,
but
substitute
lab02b.cc
in
place of
lab02a.cc. Copy this file into your ~/cisc181/lab02 subdirectory. Ask your
TA if you need help.
This C++ program contains the outline of a program that determines whether two circles overlap. There is a function that takes 6 parameters: (the x,y coordinates of the center and radius of a circle, and the same three values for a second circle). Both circles are assumed to lie in the same plane; "overlap" is defined as sharing one or more points on that plane.
The sample code contains the outline of a circle overlap function. However
that function currently always returns 0 (i.e., "false" , indicating that the
circles do not overlap. It is your job to add a correct algorithm to the function.
Note also that function currently computes the square root of the radius
of the
sum of
the two
radii (plural of radius), and stores this in a variable called "sampleSquareRoot".
As it turns out, that calculation is probably not very useful in a correct
algorithm
for
determining
whether
the
circles
overlap.
The purpose of putting that in the sample code is to give you an idea of how
to calculate a square root in C++, using the built in cmath library (cmath
stands for "C Math", i.e. the math library built into the C programming language.
In many cases, C++ sort of rides of the coattails of the C programming language;
rather than developing a whole new math library for C++, C++ just borrows the
math library developed for C.)
You may decide you want to declare a different variable inside the circleOverlap function as an intermediate result, or you may decide that you don't need any such variables. In any case, in your final program, you should remove any variable declarations for variables that you are not using in your calculation.
Remember that you are actually creating two web pages for your lab01 assignment.
The first is a personal web page, which have any content you like (I gave
you some sample content in the lab01 assignment, in case you are not feeling
especially creative, and/or don't know HTML.) This web page is accessed
with the URL http://udel.edu/~jsample (assume for the remainder
of these instructions that your userid is jsample) and the
file you access to create it is ~/public_html/index.html
http://udel.edu/~jsample/cisc181 and needs to have
some specific content on it. Specifically, it should have a link to the web
page of the "next student in the web ring".Unfortunately, I wasn't clear on one subtle, but crucial point in the original lab01 instructions. To make the web ring "work", you need to link your CISC181 web page to the next student's CISC181 web page, not to the next student's personal page. The original example actually shows you linking to the next student's personal page, but this is incorrect. Here is a corrected example of what the ~/public_html/cisc181/index.html file should look like (the changed part is in bold):
<html>
<head>
<title>Joe Sample's CISC181 Web page</title>
</head>
<body>
<h1>Joe Sample's CISC181 Web page</h1>
<p>I had to do this <b>web page</b> for my
<a href="http://udel.edu/~pconrad/cisc181"> CISC181 class</a>.
</p>
|
The text still looks the same after it is formatted by a web browser:
Joe Sample's CISC181 Web pageI had to do this web page for my CISC181 class. Part of this page is to make a web ring. Here is a picture of me: |
However, when you hover over the link to jsmith's web page, it should now
show that the link is to jsmith's cisc181 web page, rather than her personal
web page. That way, we will truly have a web ring.
By the way, your Deitel/Deitel text has a whole chapter on HTML, so if you want to learn more about interesting stuff you can do on your web page, take a look at that chapter. (Deitel/Deitel actually describe something called XHTML; technically, this is subtly different from HTML, but we won't worry too much about the distinction in this course. Anything you find in the XHTML chapter should work just fine on your web pages.)
When you have completed all the steps above (or decided you have come as close as you can to completing them), take the following steps:
pwd
cat lab02a.cc This lists out the content of the C++ source file
CC lab02a.cc This compiles with the Sun C++ compiler
g++ lab02a.cc This shows that it also compiles with the GNU C++ Compiler
./a.out This executes the program.
Supply whatever input is required for the program, then run the program several more times, as needed to show that the program works properly.
cat lab02b.cc Now repeat the steps above for this program
...
exit When done with all three programs, this finishes the script
Note that at some point this semester you might just be told to "script, print, and submit your work" At that point, you will be expected to follow a similar pattern as listed above, without being told in detail what to do at every step. That will certainly be the case more and more as you move into more advanced CISC courses. As you gain more knowledge and confidence with using Unix, and what the expectations are in a college-level programming course, I'll gradually try to wean you of the details of how to do every little step.
Grading of lab02:
Total: 100 points
Next Steps:
*** end of lab02 ***