CSCI 201 Lab 2 -- Compiling with Visual C++

Starting

Start Visual C++ 6.0 by going through the following sequence of menu selections from the Start button At this point, you should see the Microsoft C++ window.

Visual C++ main window

By the way, Visual C++ 6.0 may have a slightly different look when installed on your home PC.

Creating a workspace and projects

In Visual C++, software is developed in projects which are contained in workspaces. Select File from the menu bar and then choose New. A dialog window will be displayed. If necessary, select the Projects tab.

In the left hand panel, select Win32 Console Application. On the right hand side, give lab02 as your Project name and c:\files\lab02 as your project Location.

Your dialog window should look like the following graphic before you confirm your selection with the OK button.

project selection dialog

Select An empty project and then hit the the Finish button on this screen.

project selection dialog

hit the OK button on this screen.

project selection dialog

The sub-panel in the upper-left hand corner of your Visual C++ window displays information about your workspace. It should now look like:


classes subpanel

Creating a C++ file

Again select File followed by New from the menu bar. This time make sure the Files tab is selected. Now select C/C++ Source File as your file type and type lab02 as your File name.
Creating the C++ file
Note that by default this file is added to your Lab02 Visual C++ project.

Click on the File View tab at the bottom of the left window. The tab is just to the left of the Class View tab. Once you are in the FileView window, click on the + at the start of the lab02 files line. Notice that three more "folders" appear. Click on the folder labeled Source Files. At this point, the File View window should list the folders and files of your program. To its right there should be a window labeled lab02.cpp. This is where you will type your C++ code.
After the program is added

Move your mouse into the upper-right panel and start typing the following program:
C++ program
but with your name, lab section and the current date. Notice all the pretty colors Visual C++ uses to display your program. Be sure to include your name in a comment at the beginning of all C++ programs you write for CSCI 201!

Building your program

Somewhere near the top right of your Visual C++ window, you should see the following row of six icons.
Visual C++ tools
Slowly move your mouse over these icons to see their function. Go ahead and press the second icon. It should Build your program.

If you didn't make any typing mistakes, you should see the following displayed at the bottom of the window.
lab02.exe - 0 error(s), 0 warnings(s)
If you did make a mistake, correct it and keep building until you get the message

Running your program

Now press on the Execute Program tool. It's the big exclamation mark. You should see a screen similar to:
Program output
Press the space bar and the window will disappear.

Lab Checkoff 1

Whenever you see the section heading Lab Checkoff you must get the attention of your instructor and have she/he verify that you have completed some activity---this is how you get credit for the lab.

Ask your lab instructor to verify that your C++ program runs.

Syntax Errors

Modify the program that you typed above to introduce two syntax errors:

Now build your program again and notice the error messages that appear in the output window at the bottom of the application window.

Double-click on the first error message and notice that, in the code window, an arrow appears at the left of the line containing the first syntax error. This is where the compiler first detects the missing semi-colon.
error

Lab Checkoff 2

Ask your lab instructor to verify that you have located the first error.

Saving your program on a floppy

The files Visual C++ has generated in building your programs are much too large to copy into a floppy disk to take home. You must "clean up" your workspace to make it fit on a floppy.

Move your mouse over to the Project Workspace window and mash the FileView tab. Use your mouse to select the project. Click on the right mouse button. A pulldown menu should appear. Select the item

Your window should resemble:
FileView window
This will delete the executable version of your program as well many Visual C++ generated "intermediate" files from your workspace. Next close the workspace: Click File to get the drop down menu then Close Workspace.

Copy your workspace onto your floppy by performing the following steps. (Alternatively, you can use Windows Explorer to display the necessary files and directories as you were shown in Section 2 of Lab01.)

  1. Double-click the My Computer icon on the desktop.
    My Computer window
  2. Double-click the C: drive in the My Computer.
  3. Double-click the files folder.
    C:\files window
  4. Press on the lab02 file folder icon and drag it to the icon for the A: drive.

Lab Checkoff 3

Ask your lab instructor to verify that your program is stored on your floppy disk.


Return to CSCI 201 page
CSCI logo Return to the UNCA Computer Science home page