CS 1005, C Term 2000
Techniques of Programming
Lab 2 (Jan. 26)

Instructions

In today's lab session you will use and modify a C++ program that uses conditional control and iteration constructs.

  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. Change the working directory to your CS1005 directory. This assumes you have previously created a CS1005 directory; otherwise, create one now. Refer to Lab 1 for examples of basic directory commands.

  2. A C++ program for Lab2 is available in a text file named factors.cxx located in the directory named /cs/cs1005/samples/lab2/. Copy the file factors.cxx to your current working directory. Edit the file and study the program contained in it. This program is intended to factor a user-supplied positive integer into a product of powers of prime numbers. However, the program contains both syntactical and semantical errors that you will need to fix before it will work correctly.

  3. Attempt to compile the program in factors.cxx using the command:
       g++ -o lab2prog factors.cxx
    
    The compiler will report at least one syntax error. Read the compiler error messages carefully, and fix the error(s) reported by the compiler. Recompile the program. When you've successfully corrected all syntax errors, the compiler will generate an executable file named lab2prog as specified on the command line shown above.

  4. Run the executable file lab2prog. To do this, just type
       lab2prog (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
       ./lab2prog (enter)
    
    Try the program out using different input values, for example 2, 3, 4, 5, 6, 15. Does the program work correctly?

  5. Fix the program in factors.cxx so that it behaves according to the informal description given in the function FYI(). Test the program on several input values as above after each change.

  6. Modify factors.cxx so that a while loop is used instead of the for loop, without changing the external behavior of the program.

  7. Use any remaining time to continue studying for tomorrow's test.