CS 2005 Techniques of Programming WPI, B Term 1996
Craig E. Wills Lab 1
Assigned: Wednesday, October 30, 1996

Registration

You must register information about yourself in the online database for the course. As part of registration, you will be asked about your availability outside of class for working in groups and some of your background coming into this class. To register you should run the following command at your prompt (shown as >) and answer the questions. If you have any questions ask your TA.

> /usr9/cew/cs2005/takesurvey

Description

The main part of the lab is designed to review basic concepts for editing and compiling files in the Unix Operating System. At the end of this lab you should be able to: log onto a workstation and start up an editor, write, compile and run a C++ program, create a typescript file, and submit a lab using the turnin program. You will also need to send and receive electronic mail. Documentation on editors, mailers and Unix is available from your TA.

Logging on to a Workstation

Because the workstations in the labs are part of the CCC computer system you log onto them using your CCC username and password. If you do not remember your username or password notify your TA.

Using Email

Because electronic communication is essential in this class you must be familiar with sending and receiving mail. Use your favorite mailer to send and receive mail from two of your neighbors in the lab.

Writing a C Program

Rather than write a program from scratch, you are to modify a program that we will be discussing in class dealing with the representation of polynomials. A copy of the partial program is available in /cs/cs2005/pub/labs/lab1.C (the capital C extension indicates a C++ file). You should first copy this file to your directory using the Unix command cp:

> cp /cs/cs2005/pub/labs/lab1.C lab1.C

After copying the file you should use an editor to edit the file and insert the following lines as indicated in your lab1.C file. The code below will actually print out the polynomial.

    cout << "f(x) =";
    for (i = wDegree; i >= 0; i--) {
        cout << " + " << rgCoeff[i] << "x^" << i;
    }
    cout << "\n";

You may use emacs or vi as your editor. The emacs editor is powerful, but can be at first confusing to use. It is the most common editor used by upper-level students. The vi editor is standard on any Unix system. Its use of modes can be confusing to new users.

Compiling and Running a C++ Program

The straightforward approach to compile is from the command line as shown below. It is also possible to compile from within emacs. Ask your TA for details.

> g++ -o lab1 lab1.C

If the program was entered without any errors the C compiler will simply return to the Unix prompt without displaying any messages (in Unix silence is golden!). If there were errors in the C program the compiler will generate a multitude of error messages. Ask your TA for help if you cannot understand and fix the error messages you receive.

When the compiler successfully runs it creates the executable file called lab1. To run this program type lab1. An example run of the program is shown in the script below.

Creating a Typescript File

A typescript file contains a transcript of a session at the computer. The program that allows you to create typescript files is called script. To use script simply type

> script lab1.script

This command will cause all text that appears on the screen after the script is started to be stored in the file lab1.script until the command exit is entered.

We require that all labs be submitted with a typescript file that contains a transcript of the lab being compiled and run. To create a typescript file for this lab type:

> script lab1.script
Script started, file is lab1.script
> g++ -o lab1 lab1.C
> lab1
What is the degree of your polynomial? 
3
Enter the coefficient for the degree 3 term: 2
Enter the coefficient for the degree 2 term: 1
Enter the coefficient for the degree 1 term: 3
Enter the coefficient for the degree 0 term: 4
f(x) = + 2x^3 + 1x^2 + 3x^1 + 4x^0
> exit
Script done, file is lab1.script

Using the turnin Program

The turnin program is used to submit work that you do for grading. All individual work is turned in in this manner. The program accepts any number of files and copies them to a special directory where they are examined for grading. The date and time of the turned in files are retained. You may re-submit the same files, which will have the effect of overwriting the previous version. To use turnin for the two files created during this lab type:

> /cs/cs2005/bin/turnin lab1 lab1.C lab1.script

A message stating that the files were successfully turned in should appear. If no success message appears or the information presented by turnin is wrong notify your TA. You will be held responsible for files incorrectly submitted.