Lab01, CISC181, Fall 2004

Goals for Lab 01

In this lab, you will accomplish several things:

  1. You'll start to learn about subdirectories and file management in Unix. (Chapters 6, 7 and 8 in Anderson will be helpful here, so you may want to read over those before coming to lab, if you have time, and have been able to purchase the book). In particular, under your home directory, you will learn how to create the following subdirectories:

    ~/cisc181
    ~/cisc181/lab00
    ~/cisc181/lab01

    You will also learn how move the files you created in lab00 (including lab00.dat, lab00.cc and lab00.txt) into your ~/cisc181/lab00 subdirectory, and how to put yourself in your ~/cisc181/lab01 subdirectory before creating any files for this lab.

    This way, you can keep your directory nice and tidy: everything for cisc181 is all in one subdirectory (folder) called cisc181, and under that subdirectory (folder), there will be a folder for each lab (one for lab00, one for lab01, etc.)



  2. You'll learn how to change directory into your ~/cisc181/lab01 directory, copy a C program from Prof. Conrad's web site, compile it, and run it. The program you copy will be one that converts Farenheit to Celsius. You'll then use emacs (or vi) to change that program into a C program that converts Celsius to Farenheit. You'll script the results, and submit them to your TA via WebCT and on paper. All the files you create in this step will be stored in your newly created ~/cisc181/lab01.


  3. You'll learn how to create a personal home page on strauss (if you don't already have one; if you do, you can skip over this step).

    This home page can be anything you like, but you'll need to have one. This lab will show you how to create a very simple web page. If you want to get more elaborate, that's something you can learn on your own.

    This web page content will go into ~/public_html/index.html. So, in the process, you'll create the new subdirectory ~/public_html.


  4. You'll also create a CISC181 homepage for the semester. This will go into ~/public_html/cisc181/index.html. This lab will teach you how to do that as well.


 

Goal 1: Managing files and directories

  1. Just as we organize documents in a "real world" filing cabinet into folders, when we create files on a computer disk, we organize them into files and folders. You may be familiar with the idea of "files" and "folders" from using Windows or Macintosh. On Unix, folders are called "directories". Chapters 6, 7, and 8 of your Anderson text ("Just Enough Unix") contain details about files and directories under Unix, and I recommend that you look over those chapters soon. You may find them to be a useful reference for this step.


  2. On the unix command line, type "cd" by itself. "cd" stands for "change directory". If you type "cd" by itself, this command will always return you to what is called your "home directory". When you type in the command, there will not be any output; it will appear that "nothing happened". But if you now type "pwd" on the command line (which stands for "print working directory"), you will see the name of your home directory. On the composers (strauss, copland, etc.) the name of your home directory will be some series of letters and numbers, such as "/home/usra/d9/55560".


  3. Now type "ls" to list the files in your home directory. Notice what files are listed.


  4. Next, we will create a directory for your cisc181 files. Type in

    mkdir cisc181

    This will create a directory called cisc181, in which you can store your files for this course. If you type "ls" immediately after doing this, you will see the new directory listed among your files. Since this directory is "under" the home directory, we call it a "subdirectory" of your home directory.



  5. To move into this subdirectory, type "cd cisc181". If you then type "pwd", you will see that you have moved into the cisc181 subdirectory. If you now type "ls", you will see no files at all. This is because when you create a subdirectory, it is initally empty.


  6. Now type "cd" again, and then "pwd", and "ls". You will see that you have moved back up to your home directory. Then, type "cd cisc181" to again move down into your new subdirectory, and type "pwd" and "ls". You should see the same files you saw back at step 3 above, except now you see the cisc181 subdirectory as well. (In Unix, a subdirectory is just a special kind of file).


  7. Now, type the following two commands:

    mkdir lab00
    mkdir lab01

    These two commands will create two new subdirectories under the cisc181 subdirectory. We call these subdirectories "cisc181/lab00" and "cisc181/lab01". These subdirectories are "under" cisc181, which is in turn, is "under" your home directory.

    To show more specifically that it is under your home directory, we can use the symbol ~ to stand for your home directory. So, your new directory would be referred to as ~/cisc181/lab00. (The ~ is sometimes called "squiggle", though the proper name for it is "tilde", prounounced "till-duh")


  8. You can use the tilde in cd commands. "cd ~" will change to your home directory (though in this case the ~ is redundant, since "cd" all by itself does the same thing.)

    The command "cd cisc181" changes to the cisc181 directory under the "current" working directory, however cd "~/cisc181" will change to cisc181 under your home directory (regardless of what the current working directory happens to be).


  9. During last weeks lab, you created files called lab00.dat, lab00.cc and lab00.txt. You probably created these in your top level home directory. We are now going to move them into your newly created ~/cisc181/lab00 directory.

    Type "cd" all by itself, to change to the directory where you created this file (probably your home directory). Then, to move each file into the directory ~/cisc181/lab00, you can use the following sequence of commands ("mv" stands for "move"):

    mv lab00.dat ~/cisc181/lab00
    mv lab00.cc ~/cisc181/lab00
    mv lab00.txt ~/cisc181/lab00

    (Note that there are several shorter ways to accomplish this same task that involve less typing. After reading over Chapters 6, 7 and 8 in Anderson, you may be able to come up with some of these.)



  10. A special directory is the one called ~/public_html. Any and all files that you put into this directory become available on your web page. (If your user id is foobar, your web page is http://udel.edu/~foobar).

    To see if you have this directory, change your working directory to your home directory (use either "cd" or "cd ~") and then use "ls" to see if the directory "public_html" is listed. If you don't have this directory already, use "mkdir ~/public_html" to create it.


  11. Use "cd ~/public_html" to move into this directory. Type the command "pwd" to ensure that you are "inside" "~/public_html".

    Then, do another "mkdir cisc181" command, to create the directory "~/public_html/cisc181". This directory will store your "CISC181 web page". In a later step in this lab, you will create a personal web page (unless you already have one), and a web page specifically for this course.

    The files for your personal web page goes into the directory "~/public_html", and will be accessed via the URL http://udel.edu/~userid (where userid is your UDelNet ID).

    The "CISC181 web page" goes into the folder "~/public_html/cisc181", and will be accessed with the URL http://udel.edu/~userid/cisc181. You can use this same technique to create as many web pages as you like under your main web page, just by creating new subdirectories to store the content. We'll add content (HTML files) to the web page, and do the commands to make it available (the "chmod" commands) in a later step.


Goal 2: More C programming on Strauss

  1. Now, change directory into ~/cisc181/lab01 with the command:

    cd ~/cisc181/lab01

    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. For example, next week, we'll do "mkdir ~/cisc181/lab02" to create the directory, and "cd ~/cisc181/lab02" to change directory into it before we start work. However, eventually, you'll just be expected to know to do that on your own.


  2. Do a "pwd" command to be sure that you are in the ~/cisc181/lab01 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 "lab01a.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/lab01/lab01a.cc .

    The "cp" command in Unix is used to copy a file. The file is copied from a directory under Prof. Conrad's home directory. Note that ~ by itself refers to "your home directory", but "~pconrad" refers to "pconrad's home directory". Similar, you can refer to any user's home directory on strauss if you know that user's login name; e.g. jsample's home directory can be accessed via "ls ~jsample".

    The period by itself at the end is the "target" of the copy command, i.e. the place we are copying the file "to". A period, all by itself, refers to the "current working directory", the same one that comes up when you type "pwd" (print working directory). So, since the current working directory is ~/cisc181/lab01, we could also have done the same copy command using the following:

    cp ~pconrad/public_html/cisc181/04F/labs/lab01/lab01a.cc ~/cisc181/lab01

    but the command was already pretty long, so using the "." is a nice shortcut.


  3. Now, do an "ls" command, and you should see the lab01a.cc file in your directory. Your next step is to list the contents of the file, then compile the program, and run the program. Before you look at the list of commands below (which do those three steps), see if you can figure out what you would type to accomplish this. Then scroll down and see if you were right.

    scroll down for the answer

    keep scrolling down for the answer

    still further

    almost there

    ok here's the answer:

    cat lab01a.cc
    g++ lab01a.cc
    ./a.out

    Did you get it right? Note: you could also have done "more lab01a.cc" in the first step (if the file is too large to fit on the screen all at once), and "CC lab01a.cc" for the second step.

    An aside about the "more" program: note that you should never use "more" inside a script file; only use "cat" inside a script file. The "more" program is only for when you are looking at the file in "real time", not for scripts that you are going to print or submit electronically.


  4. Run the program a few times with different values, and look it over to see how it works.


  5. Now, the actual thinking work starts. This program, implements the algorithm discussed in lecture to convert from Farenheit to Celsius. Your job is to edit the program (e.g. using "emacs lab01a.cc" or "vi lab01a.cc") so that it converts, instead, from Celsius to Farenheit.

    You will need to modify (at least) the following:


  6. Once you have finished editing, try compiling and running again. Test your program with several different values to be sure the conversion is working properly.

  7. You don't need to script your program yet; you'll do that at the very last step of this lab.

Goal 3: Creating a personal web page

  1. If you already have a personal web page on strauss (one that comes up when you type http://udel.edu/~userid, where userid is your UDelNet ID), then skip to the next goal (creating your CISC181 web page.) Otherwise, cd into your ~/public_html directory with the command:

    cd ~/public_html

  2. Use emacs (or vi) to create a file called "index.html". The contents of that file should be something like the following:
    
    <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>.  Right now it is
        pretty lame, but I hope to make it better later.
    
    
      </body>
    </html>
        

    Here's what that looks like once it is formatted by a web browser:

    Joe Sample's web page

    I had to do this web page for my CISC181 class. Right now it is pretty lame, but I hope to make it better later.



  3. After you save the file, you need to type in the following command:
    chmod -R a+rx ~/public_html

    This command makes all files and directories under your public_html directory accessible to all users on strauss, as well as all users on the World Wide Web. You need to repeat this command each time you add new files under public_html that you want users of the Web to be able to access. (Actually, this command is usually "overkill"; we'll talk about more targetted commands later on. But when you are just starting out, this is a safe bet).
  4. To see that it works, type into a web browser:
    http://copland.udel.edu/~userid

    If it doesn't come up, make sure you set all your file permissions correctly. The most common problem is not doing the "chmod -R a+rx ~/public_html" command. If you did that, and it still doesn't work, check with your TA or with a classmate for help.

Goal 4: Creating a CISC181 web page

  1. Now, cd into ~/public_html ("cd ~/public_html") and create a subdirectory called "~/public_html/cisc181". You accomplish this in one of two ways: either by typing "mkdir ~/public_html/cisc181", or by just typing "mkdir cisc181". (The second way works because you are already in ~/public_html).

  2. cd into ~/public_html/cisc181. Now, create an index.html file in this directory containing html code similar to the following:
    
    <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">Jane Smith</a>. </p> <p>Here is a picture of me: <img src="jsample.jpg"></p>
    </body> </html>

    Here's what that looks like once 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:



    To assist you in creating the web ring, there is a list of the students in this class and their userids at the following link: http://udel.edu/~pconrad/cisc181/04F/class.html. You should find your name in the list, and link to the student whose name and id are listed immediately after yours. If your name is the last one in the list, then link back to the student who's name is first on the list. Note that the list is sorted first by section, then by last name, then by first name.


  3. If you don't want a picture on your web page, that's fine; just omit the part in the HTML code that says "<p>Here is a picture of me: <img src="jsample.jpg"></p>". If you would like a picture, then you can upload a picture of yourself in .jpg or .gif format to your account on strauss, and move it into the same directory as the index.html file that refers to it. Change the name "jsample.jpg" to be whatever the name of your image file is. Alternatively, your instructor or TA may make a digital camera available during class, lab or office hours for you to take a picture. If so, he/she will tell you where to copy the file from. For example the command might be something such as:

    cp ~pconrad/public_html/cisc181/04F/studentImages/jsample.jpg ~/public_html/cisc181

  4. Once you have created the index.html file, and/or copied your image file into your public_html/cisc181 subdirectory, you may need to repeat the "chmod -R a+rx ~/public_html" command in order to get the web page to come up when you use the URL http://udel.edu/~jsample/cisc181 (remember also to subsitute your own UDelNet ID in place of jsample).

Finishing up: What to turn in for this lab

  1. Change to the ~/cisc181/lab01 subdirectory. Make a script called lab01.txt that contains all of the following steps.


    cd ~/cisc181/lab01
    pwd
    ls
    cat lab01a.cc
    cc lab01a.cc
    ./a.out 
       repeat this step with several different inputs
    exit  to end the script


  2. Once you have created this script, print it out with:

    qpr -q whlps lab01.txt

  3. Then, upload your lab01.txt file and your lab01a.cc to WebCT, and submit.

  4. You do not have to submit anything for your web pages; the TA can use the set of links at
  5. http://udel.edu/~pconrad/cisc181/04F/class.html to check the correctness here.
  6. Grading:

Next Steps:

Check your reading assignment in WebCT and catch up on your reading. Also, complete pre-lab exercises listed at http://udel.edu/~pconrad/cisc181/04F/hwk/ple02.html and be prepared to turn them in at the beginning of next week's lab.


Phillip T Conrad