CS 1005, C Term 2000
Techniques of Programming
Lab 1 (Jan. 19)

Instructions

The objective of this first lab session is for you to practice some basic commands of the Unix operating system, and to use the g++ compiler to translate a C++ source file into a machine language file that the computer can actually run.

  1. Sign in with the TA. You should both print your name and sign the sheet.
  2. Listen to the TA's mini-lecture.
  3. Do the problems listed below. Feel free to ask the TA questions about the problems. Don't worry if you can't finish all of the problems before the lab session is over. You can finish afterwards. However, actively working on the lab assignment during the lab session is required.


Problems

  1. Log onto your CCC Unix account. Once you've logged on, you should see the Unix prompt, which is typically displayed on your screen as the symbol >. If you haven't done so already, create a directory named CS1005 by typing
       mkdir CS1005 
    
    at the Unix prompt.

  2. Change the working directory to CS1005 by typing
       cd CS1005 (press enter)
    
    To double check that you're in the right place, print the name of the current working directory by typing
       pwd (press enter)
    
    This should display a long string of characters ending in CS1005. The characters preceding CS1005 constitute a "pathname", meaning a sequence of nested directory names that specify the location of the CS1005 directory within the global Unix directory structure.

  3. A program for Lab1 written in the C++ language is available in a text file named lab1.cxx located in the directory named /cs/cs1005/samples/lab1/. Copy the file lab1.cxx to your current working directory by typing the following at the Unix prompt:
       cp /cs/cs1005/samples/lab1/lab1.cxx ./ (press enter)
    
    Note the full pathname for lab1.cxx. The period+slash at the end is shorthand for the current working directory.

  4. List the contents of the current directory by typing
       ls (enter)
    
    at the Unix prompt. The listing should show the newly copied file lab1.cxx. For a more informative listing, use the -l option:
      ls -l (enter)
    
    This will display file sizes, the date/time when each file was last modified, as well as other file information. To explore the ls command further, look at the relevant manual pages by typing
       man ls (enter)
    

  5. Examine the contents of lab1.cxx by typing
       more lab1.cxx (enter)
    
    Notice that the C++ program in lab1.cxx is made up of a main() function plus two other functions: ReadNumber() and NextNumber(int). Study the program to understand what it is intended to do.

  6. Compile the program in lab1.cxx by typing
       g++ -o lab1prog lab1.cxx (enter)
    
    at the Unix prompt. This produces an executable machine language file named lab1prog. If you're curious, type
       man g++ (enter)
    
    at the Unix prompt for information about other compiler options and details.

  7. Run the executable file lab1prog. To do this, just type
       lab1prog (enter)
    
    If this doesn't run the program, you may have to explicitly tell the operating system to look for the program in the current working directory, by typing
       ./lab1prog (enter)
    
    Try the program out using different input values. Is it clear to you how the output values are related to the input values?

  8. Use a text editor like emacs to modify the program in lab1.cxx so that the rule used to compute the next number based on the input value multiplies the input value by 2 (follow the Unix help links on the CS1005 homepage to links with help on emacs). How many of the functions in lab1.cxx must be modified in order to accomplish this? Compile, run, and modify the program until you're confident that it works correctly.

  9. Use any remaining time to work on HW1.