CIS Logo SVC Logo

   Computing & Information Systems


Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++

A Practice Lab on Using the Visual Studio 2008 Debugger

The purpose of this lab is to acquaint you with setting up a solution (workspace) and projects in Visual Studio 2008 as well as to try out the debugger.

Starting Out

Start your PC. When you have successfully logged in, start up Visual Studio 2008.

Create a Solution / Project

If you don't already have an appropriate solution (workspace), create one on your M drive, perhaps named using the name of the course. Create a Win32 Console Application project in the given solution. For instructions on how to set up a solution / project, click here.

Create a Source File

Create a new C++ source file for this project and name the file reverse.cpp. Also set the reverse project to be the currently active project (the so-called Startup Project).

Copy Existing Code

We will insert code into the reverse.cpp file from the Web. The code to insert is in the file bad.cpp. Follow the link just shown. Then use Edit, Select All and Edit, Copy to copy the code that is in your browser. Click on the editor window for your reverse.cpp file in Visual Studio and do Edit, Paste. (You can also right click and select Paste, of course.) Click on the reverse project name in the Solution Explorer and then do File, Save reverse to save your project.

Compile the Program

Use Build, Build reverse to try to compile the program. If you get a syntax error, double click on the error message to find the location in the code where the problem was detected. Fix the syntax error and try build again. Keep at this until you have succeeded in building the program.

Run and Debug the Program

Once the program compiles without errors, run the program. The output will be incorrect. Use the debugger to step through the program line by line to find the problem. (Remember to use Step Into if you want to go inside of a function. Use Step Over if you do not want to go inside of a function when stepping through a line that has a function call. Use Step Out if you need to get out of a function that you have gotten into.) Check the Autos, Locals, and Watch windows as needed to see the values in your variables. You might have to restart debugging and go through it again until you find where things are going wrong. Once you locate the logic error(s) in the program, fix them. (Check with the instructor to see if your fix is a good one. Some possible fixes are good and some are not so good.) Run the program to be sure that the output is now correct.

Save Your Work

Be sure that you have saved your corrected reverse.cpp file. If you have time you could also fill in the missing documentation in the program.

Check Your Solution

You can check your solution by comparing it with the file better.cpp, a working version of the bad.cpp program.

Finish Up

Be sure to exit from Visual C++ and to properly shut down your computer when you are finished. (Use Start, Shutdown, OK under Windows 2000.)

Related Items

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: August 27, 2009