Laboratory 1: Compiling, running and debugging C++ programs
- Download the following files into an empty directory.
- Example 1: Project name "small"
File: first.cpp
- Example 2: Project name "inches"
File: inches.cpp
- Example 3: Project name "intstack"
Files: main.cpp
, intstack.h
, intstack.cpp
- Compile and run the programs above using Microsoft Visual
Studio
.NET
1. Start up Microsoft Visual
Studio
.NET
2. Create a project.
File>New
Project
Select "Visual C++
Projects"
in "Project Types".
Select "Win32 Project"
in
"Templates".
Choose a project name
(as
indicated in each examples).
Choose the project
location (directory). (OK.)
Click on "Application
Settings"
Select "Console application"
and
"Empty project" option. (Finish.)
3. Add files to project.
For each file that
belongs to this project, do:
Project>Add
Existing Item
Select
file (browse to select the downloaded file). (Open).
4. Check that everything has
been
added.
Click on
View>Solution
Explorer.
Double click on each of
its
folders to check contents.
The *.cpp files should
be
under "Source Files" and the *.h files should be under
"Header Files".
5. Compile and link all
programs
within the project.
Select menu:
Build>Build
6. Run the program.
Select menu:
Debug>Start
Without Debugging
Your program will be
executed
and a console will pop up.
- Study and play with each program.
Look at the files for this program (starting from main()), and try to
guess
the behaviour of the program.
Check your guess by running the program.
Study the program and the meaning of various "elements" of the language
(ask
your TA at the lab or check at a book later on to understand these
"elements").
Fell free to play, modify and experiment with small changes to the
program.
Play with the debugging tool by:
- Adding a breakpoint (Click the right button of
the
mouse. Click on "Insert BreakPoint".) .
- Running the program step-by-step (Debug>Start.
Then F10 or F11.)
- Checking the status of the local variables in the
Locals
tag.