Appendix K Introduction to Microsoft Visual C++ 6.0



Similar documents
Appendix M: Introduction to Microsoft Visual C Express Edition

Creating a Simple Visual C++ Program

Visual Studio 2008 Express Editions

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

How to Compile, Link, and Execute C or C++ Codes Using Microsoft Visual C++

Visual C Tutorial

3 IDE (Integrated Development Environment)

Introduction to the use of the environment of Microsoft Visual Studio 2008

William Paterson University Department of Computer Science. Microsoft Visual C++.NET Tutorial Spring 2006 Release 1.0

Microsoft Visual Studio 2010 Instructions For C Programs

Appendix A How to create a data-sharing lab

Lab: Data Backup and Recovery in Windows XP

How to test and debug an ASP.NET application

Basics. a. Click the arrow to the right of the Options button, and then click Bcc.

Sample Table. Columns. Column 1 Column 2 Column 3 Row 1 Cell 1 Cell 2 Cell 3 Row 2 Cell 4 Cell 5 Cell 6 Row 3 Cell 7 Cell 8 Cell 9.

Using Microsoft Visual Studio API Reference

Windows XP Managing Your Files

Lab - Data Backup and Recovery in Windows XP

MS WORD 2007 (PC) Macros and Track Changes Please note the latest Macintosh version of MS Word does not have Macros.

Setting up Auto Import/Export for Version 7

ITCS QUICK REFERENCE GUIDE: EXPRESSION WEB SITE

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

Managing Contacts in Outlook

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Converting Microsoft Access 2002 to Pipe-Delimited ASCII Text Files

ACCESS Importing and Exporting Data Files. Information Technology. MS Access 2007 Users Guide. IT Training & Development (818)

Eclipse installation, configuration and operation

How To Use Query Console

UF Health SharePoint 2010 Introduction to Content Administration

Outlook Web App. in Office 365. The Outlook Window. Signing In. (Outlook Exchange Faculty & Staff) Getting Started

How to create pop-up menus

Create a New Database in Access 2010

Composite.Community.Newsletter - User Guide

Add page numbers and headers and footers by using the gallery, or create a custom page number, header, or footer.

Working with sections in Word

Company Setup 401k Tab

Introduction to Microsoft Access 2013

Learn how to create web enabled (browser) forms in InfoPath 2013 and publish them in SharePoint InfoPath 2013 Web Enabled (Browser) forms

Creating tables of contents and figures in Word 2013

Deitel Dive-Into Series: Dive Into Microsoft Visual C++ 6

Word 2010: Mail Merge to with Attachments

DEPLOYING A VISUAL BASIC.NET APPLICATION

CNC Transfer. Operating Manual

- Hour 1 - Introducing Visual C++ 5

Installing a Browser Security Certificate for PowerChute Business Edition Agent

Introduction to Microsoft Access 2010

Desktop, Web and Mobile Testing Tutorials

BCSD WebMail Documentation

Table of Contents. 1. Content Approval...1 EVALUATION COPY

owncloud Configuration and Usage Guide

Qlik REST Connector Installation and User Guide

HOW TO USE OIT VIA THE WEB

Outlook 2010 Desk Reference Guide

Baylor Secure Messaging. For Non-Baylor Users

ECA IIS Instructions. January 2005

How To Create A Hyperlink In Publisher On Pc Or Macbookpress.Com (Windows) On Pc/Apple) On A Pc Or Apple Powerbook (Windows 7) On Macbook Pressbook (Apple) Or Macintosh (Windows 8

HIRSCH Velocity Web Console Guide

Running your first Linux Program

STATISTICA VERSION 10 STATISTICA ENTERPRISE SERVER INSTALLATION INSTRUCTIONS

Creating a table of contents quickly in Word

Archiving. Follow these steps to archive your

Laptop Backup - User Guide (Windows)

HOW TO BURN A CD/DVD IN WINDOWS XP. Data Projects

The first thing to do is choose if you are creating a mail merge for printing or an merge for distribution over .

USER GUIDE. Unit 2: Synergy. Chapter 2: Using Schoolwires Synergy

The Application Getting Started Screen is display when the Recruiting Matrix 2008 Application is Started.

Before you can use the Duke Ambient environment to start working on your projects or

Database Forms and Reports Tutorial

MICROSOFT ACCESS 2007 BOOK 2

How To Manage Your Storage In Outlook On A Pc Or Macintosh Outlook On Pc Or Pc Or Ipa On A Macintosh Or Ipad On A Computer Or Ipo On A Laptop Or Ipod On A Desktop Or Ipoo On A

Downloading Driver Files

Hands-On Lab. Building a Data-Driven Master/Detail Business Form using Visual Studio Lab version: Last updated: 12/10/2010.

How To Use Outlook On A Pc Or Macbook With A Pc (For A Pc) Or Macintosh (For An Ipo) With A Macbook Or Ipo With A Ipo (For Pc) With An Outlook (For Macbook

Creating a Distribution List from an Excel Spreadsheet

The LSUHSC N.O. Archive

Remedy ITSM Service Request Management Quick Start Guide

Windows XP Pro: Basics 1

INTRODUCTION TO COMPUTER CONCEPTS CSIT 100 LAB: MICROSOFT POWERPOINT

Outlook Live Basics. for Students

How to create and personalize a PDF portfolio

Context-sensitive Help Guide

Deposit Direct. Getting Started Guide

Cascade Server CMS Quick Start Guide

About SharePoint Server 2007 My Sites

CS106B Handout #5P Winter January 14, 2008

Working with Windows Handout

SharePoint 2007 Get started User Guide. Team Sites

Recreate your Newsletter Content and Layout within Informz (Workshop) Monica Capogna and Dan Reade. Exercise: Creating two types of Story Layouts

Outlook 2007: Managing your mailbox

Creating and Using Databases with Microsoft Access

Wavecrest Certificate

Managing Mailbox Space and Personal Folders

Microsoft FrontPage 2003

Creating Personal Web Sites Using SharePoint Designer 2007

Terminal 4 Site Manager User Guide. Need help? Call the ITD Lab, x7471

OUTLOOK WEB APP (OWA): MAIL

Getting started with 2c8 plugin for Microsoft Sharepoint Server 2010

What is a Mail Merge?

Adobe Dreamweaver CC 14 Tutorial

Transcription:

Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE): Starting a new project and entering code Saving a project to disk Compiling and executing a project Opening an existing project Creating multi-file projects Starting a New Project The first step in creating a program with Visual C++ is to start a project. A project is a group of one or more files that make up a software application. (Even if your program consists of no more than a single source code file, it still must belong to a project.) To start a project: 1. Launch Microsoft Visual C++. The IDE window opens, as shown in Figure K-1. 1284

Introduction to Microsoft Visual C++ 6.0 1285 Figure K-1 2. Click File on the menu bar. On the File menu, click New. You see the dialog box shown in Figure K-2. Figure K-2 3. All of the programs in this book are console programs, so click WIN32 Console Application in the list of project types.

1286 Introduction to Microsoft Visual C++ 6.0 4. Enter the name of the project (such as lab6, or program5) in the Project name text box. (Do not enter an extension.) 5. When you create a project, Visual C++ creates a folder where all the project files are normally stored. The folder is called the project folder and it has the same name as the project. The Location text box lets you type in or browse to a location on your system where the project folder will be created. If you do not want to keep the default location, click the ellipses (...) button to select a different one. Once you have selected a folder the dialog box should appear similar to Figure K-3. Figure K-3 6. Click the OK button. You now see the dialog shown in Figure K-4. Figure K-4 7. Make sure An empty project is selected and click the Finish button. You see the dialog box shown in Figure K-5.

Introduction to Microsoft Visual C++ 6.0 1287 Figure K-5 8. Click the OK button. You return to the IDE, as shown in Figure K-6. Figure K-6 9. Now you must insert a new C++ source file into the project. Click Project on the menu bar. On the Project menu, click Add To Project, then click New You see the dialog box shown in Figure K-7.

1288 Introduction to Microsoft Visual C++ 6.0 Figure K-7 10. In the list of file types, click C++ Source File. 11. In the File name text box, enter the name of the source file. (This can be the same as the project name, if you wish.) Be sure to type the.cpp extension. Your screen should look similar to Figure K-8. Figure K-8 12. Click the OK button. You will return to the IDE. The right pane is now a text editor. This is where you type your C++ source code, as shown in Figure K-9.

Introduction to Microsoft Visual C++ 6.0 1289 Figure K-9 Saving Your Project to Disk It is important to periodically save your work. To do so, click File on the menu bar, then click Save Workspace on the File menu. Opening an Existing Project To open an existing project, click File on the menu bar, then click on Open Workspace Use the resulting dialog box to browse to the location of your project. When you have located your project, double-click it. Compiling and Executing Once you have entered a program s source code, you may compile and execute it by any of the following methods: By clicking the button By pressing Ctrl+F5 By clicking Build on the menu bar, and then clicking Execute.

1290 Introduction to Microsoft Visual C++ 6.0 The window at the bottom of the screen shows status messages as the program is compiled. Error messages are also displayed there. If you see an error message, double-click it and the editor will move the text cursor to the line of code where the error was encountered. For example, look at the program in Figure K-10. The first cout statement is missing a semicolon. When you double-click the error message, the text cursor moves to the line with the error. (Actually, in this case the cursor appears on the line after the statement with the missing semicolon. The compiler did not detect that the semicolon was missing until it encountered the beginning of the next line. Finding errors is not always straightforward.) Figure K-10 If the program compiles successfully, an MS-DOS window appears and the program runs. This is illustrated in Figure K-11. Creating a Multi-File Project Many of your programs consist of more than one file. For example, consider the following program: // Filename: RectData.cpp // This program uses multiple files #include <iostream> #include "rectang.h" // contains Rectangle class declaration using namespace std;

Introduction to Microsoft Visual C++ 6.0 1291 Figure K-11 // Don't forget to link this program with rectang.cpp! int main() { Rectangle box; float wide, long; } cout << "This program will calculate the area of a\n"; cout << "rectangle. What is the width? "; cin >> wide; cout << "What is the length? "; cin >> long; box.setdata(wide, Long); box.calcarea(); cout << "Here rectangle's data:\n"; cout << "Width: " << box.getwidth() << endl; cout << "Length: " << box.getlength() << endl; cout << "Area: " << box.getarea() << endl; return 0; This program relies on two other files: rectang.h and rectang.cpp. Before compiling this program, Rectang.h and Rectang.cpp must be added to the project. The steps listed here show you how to set the project up with all three of the existing files as members. 1. Start a new project by following steps 1 through 8 under the section Starting a New Project, at the beginning of this appendix. Name the project RectData. 2. Insert the main C++ source file into the project. Click Project on the menu bar. On the Project menu, click Add To Project, then click Files You see the Insert Files into Project dialog box. Use the dialog box to find the file RectData.cpp on the student disk, under the Appendix K folder. When you locate the file, click it and then click the OK button. The file RectData.cpp is now a member of the project.

1292 Introduction to Microsoft Visual C++ 6.0 3. Now insert the Rectang.cpp source file into the project. Click Project on the menu bar. On the Project menu, click Add To Project, then click Files Again, you see the Insert Files into Project dialog box. Use the dialog box to find the file Rectang.cpp on the student disk. When you locate the file, click it and then click the OK button. The file Rectang.cpp is now a member of the project. 4. Now insert the Rectang.h header file into the project. Click Project on the menu bar. On the Project menu, click Add To Project, then click Files As before, you see the Insert Files into Project dialog box. Use the dialog box to find the file Rectang.h on the student disk. When you locate the file, click it and then click the OK button. The file Rectang.h is now a member of the project. 5. At this point, RectData.cpp, Rectang.cpp, and Rectang.h are members of the project. The left pane of the IDE, which is called the workspace window, is shown in Figure K-12. This window allows you to navigate among all the files in the project. Figure K-12 The two tabs at the bottom of the workspace window allow you to switch between Class View and File View. Click on the File View tab. You should see a display similar to Figure K-13. Figure K-13 6. Click the small + sign that appears next to RectData files. The display expands, as shown in Figure K-14, to show folders labeled Source Files, Header Files, and Resource Files. These folders organize the names of the files that are members of the project. Figure K-14

Introduction to Microsoft Visual C++ 6.0 1293 7. Notice that the Source Files and Header Files folders have small + signs next to them. This indicates the folders hold filenames. Click on the small + sign next to the Source Files and Header Files folders. The filenames RectData.cpp, Rectang.cpp, and Rectang.h are listed, as shown in Figure K-15. Figure K-15 8. Double-click on the name RectData.cpp. The file is displayed in the editor. (You may display any of the files in the editor by double-clicking its name.) 9. You may compile and execute the project by following the steps listed under the section Compiling and Executing. Creating a New Multi-File Project If you are creating a new multi-file project (not from existing files), follow steps 1 through 12 under the section Starting a New Project. Type the code for the main source file into the editor. When you are ready to create another source file (such as a header file for a class declaration, or a.cpp file to contain class member function definitions), follow these steps. 1. Click Project on the menu bar, click Add to Project, then click New. 2. In the New dialog box, click C++ Source File if you are creating a new.cpp file, or C/C++ Header File if you are creating a new header file. 3. In the File Name text box, enter the name of the file. Be sure to include the proper extension. 4. Click the OK button. You will return to the text editor. Enter the code for the new file. 5. Repeat the steps above for each new file you wish to add to the project. Removing a File from a Project To remove a file from a project, simply select the file s name in the project browser window and press the Delete key. This operation removes the file from the project, but does not delete it from the disk.

1294 Introduction to Microsoft Visual C++ 6.0 Where Files are Created When you create a new project, Visual C++ creates a project folder with the same name as the project. This is where all of the files associated with the project are normally stored. You can specify the location of the folder when you create the project. (See step 5 of the Starting a New Project section.) For example, suppose we ve created a project named Lab5, and its project folder is at C:\MyProjects\Lab5. All of the C++ source files that you have created for this project will be stored in that folder. In addition, Visual C++ will create another folder named Debug, under the C:\MyProjects\Lab5 folder. The Debug folder will contain the project s executable file and its object file(s). It s important to know the location of the project folder when writing code that opens files for input or output. When running a program from the Visual C++ IDE, the project folder is the default location for all data files. For example, suppose our Lab5 project creates a file with the following code: ofstream outputfile("names.txt"); Because we have not specified a path with the file name, the file will be created in the C:\MyProjects\Lab5 project folder. Similarly, if our program attempts to open an existing file for reading, it will look in the project folder by default. For example, suppose our Lab5 program attempts to open a file with the following statement: ifstream inputfile("names.txt"); Because we have not specified a path, the program will look for the file in the project folder, C:\MyProjects\Lab5. If we want to open a file in a location other than the project folder, we must provide a path as well as a file name. For example, the following statement opens a file named data.txt in the C:\Data folder. ofstream outputfile("c:\\data\\data.txt"); Notice that we ve used two backslashes in the path where you normally use only one. Remember, in a literal string, the compiler interprets the backslash character as the beginning of an escape sequence. In order to represent a backslash as a character in a literal string, you must use two backslashes. Here s another example: ifstream inputfile("a:\\names.txt"); This statement attempts to open the names.txt file in the root folder of drive A.