Lab01, CISC105, Fall 2004
Goals for Lab 01
In this lab, you will accomplish several things:
- 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:
~/cisc105
~/cisc105/lab00
~/cisc105/lab01
You will also learn how move the files you created in lab00 (including lab00.dat,
lab00.c and lab00.txt) into your ~/cisc105/lab00 subdirectory, and how to
put yourself
in your ~/cisc105/lab01 subdirectory before creating any files for this lab.
This way, you can keep your directory nice and tidy: everything for cisc105
is all in one subdirectory (folder) called cisc105, and under that subdirectory
(folder), there will be a folder for each lab (one for lab00, one for lab01,
etc.)
- You'll learn how to change directory into your ~/cisc105/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
Celsius to Farenheit. You'll then use emacs (or vi) to change
that program
into a C program that converts Farenheit into Celsius. 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 ~/cisc105/lab01.
- 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.
- You'll also create a CISC105 homepage for the semester. This will go into
~/public_html/cisc105/index.html. This lab will teach you how to do that
as well.
- Finally, we'll return to the ~/cisc105/lab01 directory for an exercise
in debugging.
Goal 1: Managing files and directories
- 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.
- 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".
- Now type "ls" to list the files in your home directory. Notice
what files are listed.
- Next, we will create a directory for your cisc105 files. Type in
mkdir cisc105
This will create a directory called cisc105, 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.
-
To move into this subdirectory, type "cd cisc105". If you then
type "pwd", you will see that you have moved into the cisc105
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.
- 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
cisc105" 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 cisc105 subdirectory as well. (In Unix, a subdirectory is just a
special kind of file).
- Now, type the following two commands:
mkdir lab00
mkdir lab01
These
two commands will create two new subdirectories under the cisc105 subdirectory.
We call these subdirectories "cisc105/lab00" and "cisc105/lab01".
These subdirectories are "under" cisc105, 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 ~/cisc105/lab00.
(The ~ is sometimes called "squiggle", though the proper name for
it is "tilde", prounounced "till-duh")
- 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 cisc105" changes to the cisc105 directory under the "current" working
directory, however cd "~/cisc105" will change to cisc105 under your
home directory (regardless of what the current working directory happens to be).
- During last weeks lab, you created files called lab00.dat, lab00.c and
lab00.txt. You probably created these in your top level home directory. We
are now going to move them into your newly created ~/cisc105/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 ~/cisc105/lab00, you can use the following
sequence of commands ("mv" stands for "move"):
mv lab00.dat ~/cisc105/lab00
mv lab00.c ~/cisc105/lab00
mv lab00.txt ~/cisc105/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.)
- 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.
- 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
cisc105" command, to create the directory "~/public_html/cisc105".
This directory will store your "CISC105 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 "CISC105 web page" goes into the folder "~/public_html/cisc105",
and will be accessed with the URL http://udel.edu/~userid/cisc105.
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
- Now, change directory into ~/cisc105/lab01 with the command:
cd ~/cisc105/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 ~/cisc105/lab02" to
create the directory, and "cd ~/cisc105/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.
- Do a "pwd" command to be sure that you are in the ~/cisc105/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.c" 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/cisc105/04F/labs/lab01/lab01a.c .
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 ~/cisc105/lab01, we could also have done the same copy command using the
following:
cp ~pconrad/public_html/cisc105/04F/labs/lab01/lab01a.c ~/cisc105/lab01
but the command was already pretty long, so using the "." is a nice shortcut.
- Now, do an "ls" command, and you should see the lab01a.c 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.c
cc lab01a.c
./a.out
Did you get it right? Note: you could also have done "more lab01a.c"
in the first step (if the file is too large to fit on the screen all at once),
and "gcc lab01a.c" 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.
- Run
the program a few times with different values, and look it over to see how
it works.
- Now, the actual thinking work starts. This program, implements
the algorithm discussed in lecture to convert from Celsius to Farenheit.
Your job is to edit the program (e.g. using "emacs lab01a.c" or "vi lab01a.c")
so that it converts, instead, from Farenheit to Celsius.
You will need to modify (at least) the following:
- The comments that explain the purpose of the program, the name of the
programmer, and the date
- The name of CelsiusToFarenheit function. Give it a different name,
as appropriate, one that indicates that the conversion goes the other way.
- The formula in the CelsiusToFarenheit function
- The prompts in the main program that tell the user what to type in,
and the labels that explain the output.
- 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.
- 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
- 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 CISC105 web page.) Otherwise, cd into
your ~/public_html directory with the command:
cd ~/public_html
- 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/cisc105"> CISC105 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 CISC105
class. Right now it is pretty lame, but I hope to make it better
later. |
- 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).
- 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 CISC105 web page
- Now, cd into ~/public_html ("cd ~/public_html") and create a
subdirectory called "~/public_html/cisc105". You accomplish this
in one of two ways: either by typing "mkdir ~/public_html/cisc105",
or by just typing "mkdir cisc105". (The second way works because
you are already in ~/public_html).
- cd into ~/public_html/cisc105. Now, create an index.html file in this directory
containing html code similar to the following:
<html>
<head>
<title>Joe Sample's CISC105 Web page</title>
</head>
<body>
<h1>Joe Sample's CISC105 Web page</h1>
<p>I had to do this <b>web page</b> for my
<a href="http://udel.edu/~pconrad/cisc105"> CISC105 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 CISC105 Web page
I had to do this web page for my CISC105
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/cisc105/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.
- 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/cisc105/04F/studentImages/jsample.jpg ~/public_html/cisc105
- Once you have created the index.html file, and/or copied your image file
into your public_html/cisc105 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/cisc105 (remember
also to subsitute your own UDelNet ID in place of jsample).
Goal 5: C debugging (Chapter 2, Exercise 6 from Tan and D'Orazio)
- Now, cd again back to ~/cisc105/lab01
- Copy the file lab01b.c into your ~/cisc105/lab01 directory with the following
command. Again, watch the spaces, and the final "period" (.) which indicates
that the target of the copy command is the "current directory":
cp ~pconrad/public_html/cisc105/04F/labs/lab01/lab01b.c .
This file is an exact copy of exercise 6 on page 73 in Chapter 2 of your Tan and D'Orazio textbook.
- Try compiling this file. You should see a number of compiler errors.
- Now, edit the file (with emacs or vi) and start to correct the errors so
that the program compiles correctly, and produces the following output (exactly
as shown in your text on page 73). Note that the spacing of your output should
be exactly as shown below (if I coded this web page right,
this should match p. 73 exactly). For example, the first "\" should be over
the letter "e" the word "be", and the third "\" should be
over the "a" in able. In order to get full credit, every other character should
be just as precise in its placement when you are done.
/// This is a program to help you practice "debugging".\\\
///There are a few errors in this program. You should be able
to fix them.\\\
Make your output neat and orderly.
|
Finishing up: What to turn in for this lab
- Change to the ~/cisc105/lab01 subdirectory. Make a script called lab01.txt
that contains all of the following steps.
cd ~/cisc105/lab01
pwd
ls
cat lab01a.c
cc lab01a.c
./a.out repeat this step with several different inputs
cat lab01b.c
cc lab01b.c
./a.out one run is sufficient here
exit to end the script
- Once you have created this script, print it out with:
qpr -q whlps lab01.txt
- Then, upload your lab01.txt file, your lab01a.c and your lab01b.c files
to WebCT, and submit.
- You do not have to submit anything for your web pages; the TA can use the
set of links at
- Grading:
- correctness of the lab01a.c algorithm and C code (temperature conversion)
is worth 20 points
- formatting and style of lab01a.c is worth 10 points
- correctness of the lab01b.c file (debugging) is worth 20 points
- formatting and style of lab01 is worth 10 points
- correctness and neatness of the script file is worth 20 points
- having a correct home page (your main page) is worth 10 points
There is nothing to submit; your TA will just check to see if your web
page is there. To be sure it is there, go to
http://udel.edu/~pconrad/cisc105/04F/class.html,
find your name, and make sure when you click on your userid, that your
web page comes up. You should also
click on the "cisc105" link next to your name to see if your
CISC105 web page is there, and links sucessfully to the next page in the
web ring
(see next
item).
- having a correct CISC105 home page is another 10 points. To get full
credit you need to successfully link to the "next" person
in the web ring, so you have a vested interest in cooperating with
your "next" person to make sure he/she does her/his work
correctly also! (His/her page doesn't have to be 100% correct for you
to get full credit, but it at least needs to be there.) You
are not required to have an image on your CISC105 web page, but if
you have one, it should come up (not produce an error).
Next Steps:
Check your reading assignment in WebCT and catch up on your reading. By now
you should have read chapter 1 in Tan and Dorazio, and be starting on reading
Chapter 2.
Be sure to check out the reading notes at: http://udel.edu/~pconrad/cisc105/td99
Phillip T Conrad