CSC 255 Programming and Algorithms I
Microsoft Visual C++ 6
Integrated Development Environment (IDE)

1. Introduction

 

This paper introduces the basics of the Microsoft Visual Studio 6 Integrated Development Environment (IDE); discusses the online documentation; explains how to create, save and execute a Windows console applications (i.e., an application that does not use Graphical User Interface (GUI) elements such as windows and buttons) and discusses the debugger. This paper introduces the concept of a project - a group of program files associated with an application that resides in a specific directory.

The debugger helps programmers find code that, although it does not violate C++ syntax, contains logic errors (e.g., infinite loops, division-by-zero exceptions, off-by-one errors, etc) that prevent the program from executing correctly. The debugger toolbar and menu contain the tools necessary to debug a C++ application.

2. Objectives

 

  • Learn to use Microsoft Visual C++ 6 to create, compile, and execute C++ console applications.
  • To understand and be able to use the Microsoft's Visual Studio 6 IDE.
  • To be able to use the debugger to locate program logic errors

3. Microsoft Visual C++ 6 IDE overview

 

The Microsoft Visual C++ 6 IDE is a part of the Microsoft Visual Studio suite of development tools. You can create, compile, execute, and debug C++ programs using the powerful C++ development environment - Visual C++ 6. Microsoft Visual C++ 6 has three editions: the Standard, Professional, and Enterprise Editions. The Introductory Edition software provided with some textbooks is not suitable for the heavy-duty software development requirements of professional programmers.

The MS Visual C++ IDE contains everything you need to create C++ program:

  • Editor for typing and correcting your C++ programs
  • Compiler for translating C++ programs into machine language code
  • Debugger for finding logic errors in your C++ programs after they are compiled
  • Buttons, menus and other graphics user interface (GUI) elements you will use while editing, compiling, and debugging your C++ applications.

4. On-line Visual C++ documentation

 

Visual C++ 6.0 uses the Microsoft Developer Network (MSDN) documentation, which is accessible by selecting Contents from the Help menu. Microsoft has combined the documentation for all their development tools into MSDN just as they have combined the development tools (e.g., Visual Basic, Visual C++, visual J++, etc) into one product line called Visual Studio.

The Visual C++ documentation is also available via the World Wide Web at the Microsoft Developer Network Web site.

http://msdn.microsoft.com/library

5. Creating and executing a C++ application

 

For this course, you will create Win32 console applications. When executed, Win32 console applications get input from an MS-DOS window (a text-only display that predates windows) and display data to an MS-DOS window. This type of application is used for the example and exercise programs in the textbook.

Program files in visual C++ are grouped into projects. A project is a text file that contains the names and locations of all its program files. Project file names end with the .dsp (describe project) extension

Before writing any C++ code, you should create a project.

Clicking the File menu's New…  menu item displays the New dialog. The New dialog lists the available Visual C++ project types. When you create a project, you can create a new workspace (a folder and control file that act as a container for project files) or combine multiple projects in a workspace. A workspace is represented by a .dsw (describe workspace) file. In this course, each application will have one project per workspace.

Starting with the New window, a series of dialog windows guides you through the process of creating a project and adding files to the project. The IDE creates the folders and control files necessary to present the project.

From the list of project files, select Win32 Console Application. The Project name field (in the upper-right corner of the dialog) is where you specify the name of the project. Click in the Project name field and type name for the project, in this example First is the project name.

The Location field is where you specify the location on disk where you want your project to be saved. If you click in the Location field and scroll through it using the right arrow key, you will notice that the project name you typed (First) is at the end of the directory path. If you do not modify this directory path, Visual C++ stores your project in this directory. You can select a different path and location. You can do this by pressing the browse button (i.e., a button with dots at the right of Location input text box) and navigating to the desired location. For instance, F:\network-user-name\ can be chosen to be a location on your folder of the F: network drive. [Replace network-user-name with your user name such as F:\lilliec] Click the Create new workspace radio button. CheckWin32 check box in the Platforms: box. Pressing OK closes the New dialog and displays the Win32 Console Application - Step 1 of 1 dialog.

The Win32 Console Application - Step 1 of 1 dialog displays four choices. Selecting An empty project creates a project that does not contain any file. The programmer must add source code files to the project.

A simple application creates a .cpp file (i.e., a file - called a C++ source file into which the programmer writes C++ code) and a few support files.

Selecting A "Hello, World" application creates a .cpp file (which contains the code to print Hello World) and a few support files.

Selecting An application that supports MFC creates several files, which add support for Visual C++'s Window's programming library called MFC.

At this point, you should select An empty project and click Finish to display the New Project Information dialog. If you selected the wrong project type (ie., a type other than Win32 Console Application) in the New dialog, click <Back to view the New dialog.

The New Project Information dialog provides a summary of the project about to be created. For your Win32 Console Application, the dialog specifies that the project is empty (i.e., no additional files were created.) This dialog also specifies in the lower-left corner the location on disk for this project. Clicking OK closes the dialog and creates the project. If you created the wrong project type, click Cancel to go back to the Win32 Console Application - Step 1 of 1 dialog.

After creating an empty Win32 Console Application, the Visual C++ IDE appears. The IDE displays the project name (i.e., First) in the title bar, and shows the workspace pane and the output pane. The workspace pane appears on the left side of the middle area of the IDE window. The output pane appears below the workspace pane. If the output pane is not visible, select Output from the View menu to display the output pane. The output pane displays various information, such as the status of you compilation and compiler error messages when they occur.

At the bottom of the workspace pane are two tabs: ClassView and FileView. Clicking ClassView displays classes and class members and functions in your project. FileView displays the names of the files that make up the project.

FileView initially displays the project name followed by the word files (e.g., First files).  Clicking the plus sign, +, to the left of file name First files displays three empty folders: Source Files, Header Files, and Resource Files. Source Files displays C++ source files (i.e., .cpp files), Header Files displays header files (i.e., .h files) and Resource Files displays resource files (i.e., .rc files that define window layout). For this application, you only use the Source Files folder.

The next step is to add a C++ file to the project. Selecting New... from the File menu displays the New dialog. When a project is already open, the New dialog displays the Files tab containing a list of file types

Select C++ Source File for a C++ file. The File Name field is where you specify the name of the C++ file. Enter First in the File Name field. You do not have to enter the file name suffix ".cpp" because it is implied when you select the file type. Do not modify the Location text box. When checked, Add to Project adds the file to the project. If Add to Project is not checked, check it, Click OK to close the dialog. The C++ file is now saved to disk and added to the project. In your application, the file is saved to the location F:\network-user-name (the combination of the Location field and the project name). Click the + character next to Source Files to see that the C++ source file is indeed part of the project. The plus + becomes a minus -, and vice versa, when clicked.

You are now ready to write a C++ program
Type the following sample program into the source code window

//CSC 255 Programming and Algorithms I, Fall 2004

//Program Name: First

//Author Name: student name

//Due Date: 8/27/04

//Program Description: This program illustrates how to create a simple C++ program

#include <iostream>

#include <string>

using namespace std;

int main()

{

            cout <<"This is my first C++ program."<<endl;

            return 0;

}

 

After you have typed the program click Save (in the File menu) or click the save button (the one that resembles a floppy disk icon) on the tool bar to save the file.

Before executing a program, you must eliminate all syntax errors (also called compilation errors) and create an executable file. A syntax error indicates that the code in the program violates the syntax (i.e., the grammatical rules) of C++.

To compile the C++ file into an executable, click the Build menu's Build First.exe command or press the F7 key. Compiler message and errors appear in the output pane's Build tab. If there are no errors when compilation is complete, First.exe - 0 error(s), 0 warning(s) should appear at the bottom of the output pane's Build tab.

If en error message appears in the output pane's Build tab, double-clicking anywhere on the error message displays the source file and places a blue arrow marker in the margin indicator bar (i.e., the gray strip to the left of the source code), indicating the offending line.

Error messages are often longer than the output pane's width. The complete error message can be viewed either by using the horizontal scrollbar to the right of the tabs at the bottom of the screen or by reading the status pane. The status pane displays only the selected error message.

If you do not understand the error message, highlight the error message number by dragging the mouse over the number, then pressing the F1 key. This displays a help file that provides information about the error and some helpful hints as to the cause of the error. Please keep in mind that C++ compilers may mark a line as having an error when, in fact, the error occurs on a previous line of code.

After fixing the error(s), recompile the program. C++ compilers often list more errors than actually occur in the program. For example, a C++ compiler may locate a syntax error in your program (e.g., a missing semicolon). That error may cause the compiler to report other errors in the program when, in fact, there may not be any other errors.

Once the program compiles without errors, you can execute the program by clicking Execute First.exe in the Build menu. The program is executed in an MS-DOS window. Pressing any key closes the MS-DOS window.

To create another application, you follow the same steps outlined in this lab using a different project name and directory. Before starting a new project you should close the current project by selecting the File menu's Close Workspace option. If a dialog appears asking if all document windows should be closed or if a file should be saved, click Yes. You are now ready to create a new project for your next application or open an existing project. To open an existing project, in the File menu you can select the Recent Workspaces option to select a recent workspace or you can select Open... to see an Open Workspace dialog and select a workspace (.dsw file) to open.

6. Procedure

 

Read carefully and understand all the steps explained in the section 5

Follow all the steps in the section 5, and create, compile, and execute first.cpp C++ program.

Have first.cpp source code printed out.

Close your current workspace.

Turn in a printout of the first.cpp program at the next class period.

Create another C++ program sname.cpp in the project Sname of the workspace Sname. 

Enter the following program;

  //CSC 255 Programming and Algorithms I, Fall 2004

  //Program Name: Sname

  //Author Name: student name

  //Date Due: 8/27/04

  //Program Description: Introduce the student to simple input and output

  //for C++ program.  This program will demonstrate the use of cin and cout.

  #include <iostream>

  #include <string>

  using namespace std;

  int main() {

            // Prompt for and read student name

            cout << "Enter your first and last name followed by two enter keys.  \n"

                        << "Seperate names with a blank space:"

                        << "e.g., First Last \n"

                        << "Enter Names: ";

            string name1;

            getline (cin, name1);

            // Display the names that were input.

            cout << "The names input are: " << name1 << endl;

            return 0;

  }

Compile and execute sname.cpp.

Turn in a printout of the sname.cpp program at the next class period.