Lab00, CISC105 Summer 2005

Welcome

Welcome to CISC105! The purpose of this first lab, "lab zero", is to familiarize you with some of the knowledge and skills you will need to complete the remaining labs in this course. In particular, this lab will introduce you to the Sun Rays.

The Sun Rays are computer workstations that you can use to access the machine called strauss. Strauss is where you will do your actual programming in this course. In lab, you'll access strauss via the Sun Rays. The SunRays are a specific brand name for a type of system called an "X Terminal".

Note: Outside of lab, you may access strauss from any computer connected to the Internet, provided you have the right access software, e.g., a secure shell client program. Some work for this course you can do from any computer, provided you can use that computer to access strauss. Other work you might have to do directly on the Sun Rays.

Goals for Lab Zero

This lab is a "warm up" for the semester. We want to make sure that you are comfortable with the environment as you start to program.

AFTER the lab:

  1. Make sure you know how to log in and out of the Sun Rays, and set up your account for this course.
  2. Make sure you know how to access the web on the Sun Rays.
  3. Make sure you can find the CISC105 home page.
  4. Make sure you know how to create a text file with the text editor known as emacs.
    Chapter 15 in your Andersen textbook covers emacs, and there is also some material below. In this lab, you'll create a text file and submit it on paper.
  5. Make sure you can create a C program, compile it, run it, script the results, and submit it to your TA on paper and via email.
  6. Make sure you understand the lab policies.

If you can do all those things, you are all set for next week. You can start on reading Chapters 1 and 2 in your Tan and D'Orazio text.

Reference Materials for Lab 00

In your Andersen textbook (Just Enough Unix, 5th Edition), Chapters 1,2,3,15,32,33, (pages 3-34, 181-194, 363-382). These are short chapters, but you are not expected to know all this material off the top of your head; instead, find what you need to know to accomplish the task at hand.

Goals 1 and 2: Login/Logout and Web on the Sun Rays and account setup

Info on logging in and out and accessing the web on the Sun Rays is at the following link: http://copland.udel.edu/~pconrad/UnixAtUD/SunRay.html

That link also has information on what to do if you don't yet have a UDelNet Id. Finally, there is also information on that page that will help you pull up an "XTerm on Strauss"; you'll need that when you get to Goals 5 and 6.

In addition, you should do the following steps:

Goal 3: CISC105 homepage

Once you've logged on to the SunRay system, and you've found the Web Browser, use a search engine to find the course web page if you have not already done so. All of your assignments will be posted on the course web page.

Goal 4: Creating a text file with emacs

Open an XTerm on strauss (If you don't know how and/or are not sure what "Xterm on Strauss" means, follow this link to the Sun Ray documentation: http://copland.udel.edu/~pconrad/UnixAtUD/SunRay.html).

Now it's time to start learning emacs. Emacs is a "text editor", that is, a program that helps you create files on strauss. Go to an xterm on strauss, and type emacs &. If you get a "command not found" message, you may have to type "/opt/bin/emacs &" until you correct your path variable.

The "&" is a special command to let Strauss know that you want emacs to open in a new window and let you keep using the old xterm window, too.

When you see Emacs, the paragraph of text will tell you how to start running a self-directed tutorial. Go through the tutorial and fill in the table with useful Emacs shortcuts. Add other shortcuts that you find useful. You can edit this file electronically or on paper. You can use this file as a quick reference throughout the semester. Before you leave the lab, show the TA that you learned some useful Emacs shortcuts.

Once you are comfortable using emacs, use emacs to create a text file called "lab00.dat" containing the following, each on a separate line: your name, your hometown, a favorite non-school activity, and your UNIX userid. For example, Sara Sprenkle's file would look like this:

Sara Sprenkle

Dallastown, PA

ultimate

sprenks

When you are finished, send the file to the printer with the following Unix command typed into an xterm:

lpr lab00.dat

Goal 5: C programming on Strauss

  1. Create a file lab00.c that contains the following (except substitute your name and Unix user id for those of Jane Doe, and use today's date.)

    DO NOT include your student number. (NEVER include that number in anything you submit in this class!)
    // lab00.c Jane Doe doej@udel.edu 6/1/06
    // traditional first program (hello.c from Andersen, p. 369)

    #include <stdio.h>
    int main(void)
    {
    printf("Hello, world!\n");
    return 0;
    }
  2. Once you've created this program, determine which, if any, compiler you have available.
  3. If neither is found, consult your TA for how to set up your .localenv file so that you can use a compiler.

    Use the following command typed into an xterm to compile it (compile means: translate from C into machine language, or if it cannot be translated because of errors, report the errors) with one of the following commands. At this point in the semester, you may use either one (later on, I may tell you to use one or the other.)

    The first command (cc) is a commercial compiler, supplied by Sun Microsystems. The second command gcc is an open source compiler, supplied by the GNU project, which is staffed by volunteer programmers. From time to time, we may discover differences, but for now, I don't care which one you use. Sometimes if you have a tricky syntax error it is useful to try both, because sometimes one gives you more useful error messages than the other.

  4. In both cases, the compiler generates a file called "a.out". To execute this file (run your program), type the following:
  5. ./a.out

    You might be able to get away with just typing a.out without the leading ./, or you might not; it all depends on how your account is set up. (It has to do with the Unix concept of the "path"; you'll read about that in the Andersen text later on.)

    If all goes well, you should see something like the following:

    > cc lab00.c
    > ./a.out
    Hello, world!
    >
  6. You are now ready to use the "script" command to make a record of your work.
  7. Now, write some more programs, each in their own text file. Name the files lab00.1.c through lab00.5.c.
    1. (5) Declare an integer variable i, assign it a value of 23, and print a message and the value as we did in class.
    2. (5) Copy the first program using the shell command "cp". Instructions on how to use "cp" are in Anderson. In the new copy, change the name of the variable i to i21. Be sure to change the name everywhere the variable is used. Compile and run to show it works. Now edit the file again and change the name to 21i. What error message do you get? Record in comments the error message. Revert your program back to the correct variable name.
    3. (10) Declare three integer variables (i, j, and result) and assign them values to calculate and display result = i² + 3j - 5 for the case where i=7 and j=2. Use only the arithmetic operators covered in class (+, -, *, /)! Your code will not look exactly like this formula; think, and test your ideas.
    4. (5) Copy the previous program into a new file. Change the value of i to 987 and the value of j to -3214. Show that it works. Verify your results.
    5. (5) Copy the first program using the shell command ``cp''. In the new copy, change the value you assign to i to 34.6 (which is not an integer). What does the program print? What do you think happened? (Explain in comments.)
    6. (10) Declare a variable named my_num of type double instead of integer. Assign it the value 567.123. Print it out with a nice message, using the appropriate format specifier. You should see the complete number when you compile and run. Now, add a similar print statement but change to the format specifier for an integer. What gets printed when you compile and run? (As always, explain in comments. I won't always remind you of that throughout the semester.)
    7. (15) Declare integer variables i and j, and double variables x, y, and result (five variables total). Set i to 9, j to 2, x to 9 and y to 2. Now write a series of six pairs of assignment and print statements as follows (be sure you use the correct format specifier for what you are printing):
      1. Set result to i/j; print result;
      2. Set result to j/i; print result;
      3. Set result to x/y; print result;
      4. Set result to y/x; print result;
      5. Set result to i/y; print result;
      6. Set result to (double)i/j; print result;
      Explain your results for each of the six in your program's comments. If you can't figure out what is happening, re-read section 3.3 and 3.4 of your text.
  8. Now, run script lab00.txt again. You will cat, compile, and execute each program (0 through 7), repeating the steps outlined above. Remember to run exit to end your script file.
  9. Now, use "cat lab00.txt" to make sure your script looks ok, and use the following command to print your .txt file.
  10. lpr lab00.txt 

Goal 6: Understanding Lab Policies

First, let's get this out of the way: Lab attendance is mandatory.

Attendance will be recorded. Be sure you are on time so the TA does not miss you.

Your lab has two components: paper submission and email submission. Paper is due at the start of lab the following week (not two minutes after lab starts!). Hint: The printer at the lab is often overcrowded just before a lab starts, so print your lab somewhere else that morning or the night before.

Late penalties apply as noted on the class web page.

Finishing up: What to turn in for this lab

  1. Be sure that you have a printed copy of your two files: lab00.dat and lab00.txt (script file).
  2. Create a directory for lab00 and move your files into this directory.
    To make a directory, run the command
    mkdir lab00
    Then, move your files into the lab00 directory using the mv command.
  3. Email a tar file of your assignment directory to Gang (situ at cis.udel.edu) before next Wednesday at midnight. A tar file is simply a "bundle" or "archive" of your directory in one file. To make a tar file, run the command:
    tar cf lab00.tar lab00

    If you don't have a preferred email client for this system, use pine to email the tar file.

    1. Run pine
    2. Enter your username and password, if requested.
    3. Type "c" to compose a message. You will not be able to use a mouse to type in the window, so use the arrow keys to get around.
    4. Type your TA's email address in the "To" field.
    5. To attach the file, go to the "Attchmnt" line. Type "Control-T" to list your files. Then, select your tar file.
    6. Put "[Your Name] CISC105-12: Lab00 Assignment Submission" as your subject.
    7. Type an appropriate message and send the message to your TA using "Control-X" and then type "y" to confirm sending the message.

    Ask well before the deadline if you need help emailing your assignment!

Grading:



Adapted from Phill Conrad and Terry Harvey