Lab 05: Debugging program under Windows


Topic 1: Debug using VC++


Topic 2: Session 2 in the Lab Book.

You should remember the concepts about compiling a C++ program from the previous session. We'll use this exercise to get you used to the I/O used in C++, which is different than C. Read the section on "Reading and Writing Data of Primitive Types" on p. 15 in the lab book.

Don't write your answers in the book or on paper. Move into your subdirectory for this class using cd, and then create a file on the computer for your answers and type them into this file. For example, you could call this file "lab2". You will find it very easy to use cut-and-paste to copy program output in one window into your editing window. If you don't have a subdirectory for this class, you really should create one now: mkdir cot3002l.

For most experiments, a program name like CP02E02 is given in the book. Don't type in these programs. You can copy a version into your own directory like this: cp ~course/src/CP02E02.cpp .
This means the C++ files are in the subdirectory named 'src' in the directory of the user-name 'course'. Don't forget the final '.' after the name of the C++ file. (This means the target of the copy command is the current directory, and just use the same name as in the source directory.) Use the ls command to make sure your copy command worked. (Of course, if you were really clever, you could type cp ~cot3002l/src/CP02E*.cpp . to copy all the programs for this session in one command!)

Or you can save CP02E.tar.gz to your home directory. To uncompress the zip package, try this command: zcat CP02E.tar.gz | tar xf - We will explain how to use the UNIX compress/uncompress utilities in Lab10.

Remember the command to compile your program is:
g++ -Wall CP02E02.cpp
Always use the -Wall option with g++ to show all warnings, some of which might be errors. You could also use the -o option to rename the output file to be something other than a.out (By the way, there may be one warning for all these example programs you can safely ignore.)

Do these exercises in the lab and turn them in. (Do all steps in each Experiment unless noted.)
Last modified 05/30/2005