Lab02, CISC181
Fall 2004, P. Conrad

Overview

In this lab, you will do the following:

  1. Write a program that demonstrates how to read and process a sequence of data values, until a sentinel value is entered (using a while loop).
  2. Write a program that demonstrates an algorithm for determining whether two circles overlap or not.
  3. Fix up any remaining problems with access to your personal and cisc181 web pages, and the web ring links.

Preliminaries

  1. Create a new directory ~/cisc181/lab02 with the unix command that is used to create new directories. Look back at lab01 if you are not sure what the exact command should be.
  2. Now, change directory into this newly created directory (~/cisc181/lab02).

    Note that you can't just type ~/cisc181/lab02 at the command line; if you do, you'll get a "permission denied" error. You have to put the unix command to "change directory" at the start of the command line. Look back at lab01 if you are not sure what to do.

    For the next couple of labs, the instructions will remind you to create a new subdirectory for that lab, and change directory into it at the start of the lab. But eventually, you'll just be expected to do that on your own, without being told.


lab02a.cc

Lab Exercise 1 from p. 61-64 of your lab manual

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.

  1. Do a "pwd" command to be sure that you are in the ~/cisc181/lab02 subdirectory. Then, use the following command to copy a program from Prof. Conrad's directory into your current working directory. BEFORE YOU TYPE THIS COMMAND, look over it carefully. You will notice that there is a space between the "cp" and the "~". There is a space between the "lab02a.cc" and a period (.) which is at the end of the command. Those spaces are very important, and the period at the end is especially important. Be sure you type the command exactly as it appears here.

    cp ~pconrad/public_html/cisc181/04F/labs/lab02/lab02a.cc .

  2. Now, do an "ls" command, and you should see the lab02a.cc file in your directory.
  3. Your next step is to read over the directions on pages 61-63 of your lab manual, and fill in the missing code in the file lab02a.cc. You'll use the text editor to make the changes to the lab02a.cc file, then use the compiler to produce an executable file, and test your program. (For now, don't worry about the Follow-Up Questions and Activities on pp 63-64; those will be part of your pre-lab work due at the start of next week's lab. Just concentrate on writing the program.)
  4. When you are finished with the program, test it on the values shown on p. 61. If it works correctly, you should get the same output shown there.

lab02b.cc

An algorithm to determine whether two circles overlap or not

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.

3. A clarification and some hints about the web ring

Remember that you are actually creating two web pages for your lab01 assignment.

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> 
      
    <p>Part of this page is to make a web ring.
    The next student in this web ring is <a href="http://udel.edu/~jsmith/cisc181">Jane Smith</a>. </p> <p>Here is a picture of me: <img src="jsample.jpg"></p>
    </body> </html>

    The text still looks the same after it is formatted by a web browser:

    Joe Sample's CISC181 Web page

    I had to do this web page for my CISC181 class.


    Part of this page is to make a web ring.
    The next student in this web ring is Jane Smith.

    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.)

What to turn in (scripting, printing, and submitting to WebCT):

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:

  1. Start a script file called lab02.txt (cd into your ~/cisc181/lab02 subdirectory, and type "script lab02.txt").
  2. For the lab02a.cc and lab02b.cc programs that you developed in this lab, do 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

  3. Now, send your script to the printer with the following command:

    qpr -q whlps lab02.txt
  4. Finally, upload lab02.txt, lab02a.cc and lab02b.cc to WebCT, and submit.

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:

  1. Mechanics of scripting (lab02.txt), printing and submitting : 20 points
  2. Correctness of lab02a.cc (Department Store, while loop with sentinel): 30 points
  3. Correctness of lab02b.cc (Circle Overlap): 30 points
  4. Overall programming style (comments, formatting, neatness of code, appropriate variable names, clarity of code, etc.): 20 points

Total: 100 points

Next Steps:

 

 

*** end of lab02 ***