Lab02, CISC181
Spring 2005, 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. Create a cisc181 web page (required)
  4. (Optional) Create a personal web page.

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.


Part 1: 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/05S/work/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.

Part 2: 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.

Part 3. Creating a CISC181 web page

  1. In lab01, goal 1, steps 10 and 11, you were asked to create a public_html directory (if you didn't already have one) under your home directory, and also a cisc181 subdirectory under that. If you did this correctly, you should be able to do the following sequence of commands (the part you type is in this font). Note that the part that says "/home/usra/d9/55560" will be different for you; it will be the number associated with your home directory.

    > cd ~/public_html/cisc181
    > pwd
    /home/usra/d9/55560/public_html/cisc181
    >

    If this gave you an error message, then you need to create your public_html and cisc181 subdirectories. Try this command, then repeat the commands above. If you have trouble, ask your TA for help.
    > mkdir -p ~/public_html/cisc181
    > 
    
  2. Your next step is to create an index.html file in your ~/public_html/cisc181 directory. You do that by typing:
    > emacs index.html

    If you are on a SunRay, you might want to use the following instead; this puts emacs in the background so that you get a new emacs window, and you also get your cursor back to type in more commands.

    > emacs index.html &

    If you prefer to use vi, you may use that instead of emacs, either at home or in the lab. In that case, leave off the ampersand.
  3. Once inside emacs or vi, type in the following, except substitute your own section number and name:
    <html>
      <head>
        <title>Joe Sample's Web page</title>
      </head>
    
      <body>
        <h1>Joe Sample's Web page</h1>
    
        I had to do this <b>web page</b> for my 
       <a href="http://udel.edu/~pconrad/cisc181"> CISC181 class,</a> Section 012.  Right now it is
        pretty lame, but I hope to make it better later.
    
    
      </body>
    </html>
          

  4. Once you are finished, save your file, then type in the following commands to make that file readable on the web:
    > chmod 711 ~
    
    > chmod -R 755 ~/public_html

    The first command is one that you should only have to type in once the whole semester; it opens up the security on your directory just a tiny "crack" so that the web server can find your public_html folder. The second command says that your public_html folder and everything in it should be publically accessible to anyone on the system, and anyone on the Internet. So be careful what you put in that folder! Don't EVER put your C++ program code in there unless you are specifically told to do so; putting your source code under public_html makes it available to the entire world, and could lead to others being academically dishonest.
  5. Once you have typed in the commands above, open a web browser, and navigate to http://udel.edu/~jsample/cisc181 (but substitute your own username in place of jsample.)

    If you did everything correctly, you should see your cisc181 home page.

    If you don't, review all of the steps above. If you still can't figure out what is wrong, ask your TA or instructor for help.
  6. (OPTIONAL) Your CISC181 web page is required, and I will assign you specific content to put on that page through the semester. However, you are also permitted to keep a personal web page on strauss with whatever content you want (provided it does not violate any criminal laws or University policies). If you want to make a personal web page, repeat the steps above, but instead of starting in the ~/public_html/cisc181 directory, just start inside ~/public_html.

    To review:
  7. By the way, your Deitel/Deitel text has a whole chapter on HTML (Appendix E), 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.)
  8. There is nothing to script or submit for this part of the lab; but complete it before you submit your lab02 work to WebCT. We'll check your web page as soon as you've submitted it by just going to your web link and making sure the content is there.

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"). We'll just make one script called lab02.txt that covers both lab02a.cc and lab02b.cc.
  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 -o lab02a lab02a.cc This compiles with the Sun C++ compiler;as an alternative you are permitted to use "make lab02a"
    ./lab02a 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 (compile and run) for this program

    ...
    exit When done with all programs, this finishes the script

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

    qpr -q whlps lab02.txt

    (Change whlps to prsps if you are working Pearson hall, or smips if you are working in Smith Hall.)
  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 (i.e., "following instructions"): 20 points
  2. Correctness of lab02a.cc (Department Store, while loop with sentinel): 20 points
  3. Correctness of lab02b.cc (Circle Overlap): 20 points
  4. Overall programming style (comments, formatting, neatness of code, appropriate variable names, clarity of code, etc.): 20 points
  5. Correctness of web page: 20 points

Total: 100 points

Next Steps:

 

*** end of lab02 ***