Borland C++ Builder 6.0 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22
At a glance
Powered by AI
The key takeaways are the steps to install Borland C++ Builder 6, the information needed for installation which includes a serial number and authorization key, and the default location for files created with the software which is the project folder.

The steps to install Borland C++ Builder 6 are to obtain a serial number and authorization key from the Borland website, run the Install.exe file from the accompanying CD, enter the serial number and authorization key, accept the license agreement, select the installation type and options, and save the project.

The information needed to install Borland C++ Builder 6 is a serial number and authorization key. These are obtained by setting up an account on the Borland website, where the keys will be emailed. The serial number and authorization key must be entered during installation.

APPENDIX

Introduction to Borland C++ Builder 6.0

When purchased new, this book comes with a CD containing Borland C++ Builder 6. This appendix guides you through the steps of installing C++ Builder and using it to create C++ programs.

Installing Borland C++ Builder 6


To install Borland C++ Builder 6 you must obtain a serial number and authorization key from the Borland Web site, and then install the software from the accompanying CD. The following sections lead you through the process. Obtaining a Serial Number and Authorization Key When you install C++ Builder, you will be asked to enter a serial number and an authorization key. Borland will email the serial number and authorization key to you for free after you visit the following Web site and set up an account:
http://www.borland.com/downloads/download_cbuilder.html

Near the bottom of the Web page you will see a table titled Keys Only (If you have a CD). Under the Name column you will see a link titled Personal. Click the Personal link. Follow the instructions you see next to set up a login account. Once you have set up your login account, the serial number and authorization key will be sent to you in an email message. Save or print the email message so you can refer to it during the installation process. Installing the Borland C++ Builder 6 Software 1. Run Install.exe from the accompanying CD. The window shown in Figure L-1 will appear. Click the button that reads C++ Builder 6.

L-1

L-2

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-1

Click Here

2. The installation wizard will begin, as shown in Figure L-2. Click the Next button to continue the installation. Figure L-2

Installing Borland C++ Builder 6

L-3

3. The next window, shown in Figure L-3, prompts you to enter the serial number and authorization key. This information is in the email message you received when you set up your login account on the Borland Web site. Enter the serial number and authorization key and then click the Next button. Figure L-3

4. The next screen, shown in Figure L-4, shows the license agreement. Read the license agreement, select I accept the terms in the license agreement, and click the Next button to continue. Figure L-4

L-4

Appendix L

Introduction to Borland C++ Builder 6.0

5. The next window, shown in Figure L-5, shows miscellaneous installation notes. These notes describe various installation issues that exist for some users, and describe the minimum system requirements. Briey look through these notes for any issues that might affect your installation, and then click the Next button to continue. Figure L-5

6. The next window, shown in Figure L-6, prompts you to select the type of installation you wish to perform. It is recommended that you select Typical, and then click the Next button. Figure L-6

Installing Borland C++ Builder 6

L-5

7. The next window, shown in Figure L-7, prompts you to select the version of Ofce controls to register. Click the Next button to accept the default selection. Figure L-7

8. If you see the window shown in Figure L-8, it indicates that another C++ development environment is probably installed on your computer (possibly an earlier version of C++ Builder). If you wish to automatically associate these le types with C++ Builder 6, leave all the boxes checked. (This is recommended if C++ Builder 6 is going to be your primary C++ development environment.) If you do not wish to associate these le types with C++ Builder 6, leave the boxes unchecked. Click the Next button to continue. Figure L-8

L-6

Appendix L

Introduction to Borland C++ Builder 6.0

9. The next window, shown in Figure L-9, allows you to select a destination folder for the C++ Builder les. Either use the default locations or select other folders for the les. Click the Next button to continue. Figure L-9

10. The next window, shown in Figure L-10, asks whether you wish to copy the installation database to your hard drive. Leave the box checked and click the Next button. Figure L-10

Installing Borland C++ Builder 6

L-7

11. On the next window, shown in Figure L-11, click the Install button to begin the installation. A window similar to Figure L-12 will appear with changing messages while the software is being installed. Figure L-11

Figure L-12

12. When the installation nishes, the window shown in Figure L-13 will appear. Click the Finish button. You will be prompted to restart your computer for the installation to be complete.

L-8

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-13

13. The last step is to register your software. After restarting your computer, launch Borland C++ Builder 6. You will see a registration window prompting you to select your method of registration (online, by phone, or at a later time). Select your preferred method of registration and follow the instructions.

Using Borland C++ Builder 6


The remainder of this appendix serves as a quick reference for performing the following operations using the Borland C++ Builder integrated development environment (IDE): Starting a new project and entering code Saving a project to disk Compiling and executing a project Pausing a program's output Closing a project Opening an existing project Creating a multi-file project Adding example source files to a project Determining where data files created by a program are located

Using Borland C++ Builder 6

L-9

Starting a New Project The rst step in creating a program with Borland C++ Builder is to start a project. A project is a group of one or more les that make up a software application. (Even if your program consists of no more than a single source code le, it still must belong to a project.) To start a project: 1. Launch Borland C++ Builder. The IDE windows open on the desktop, similar to what is shown in Figure L-14. Figure L-14

2. When C++ Builder starts, it automatically begins an empty project. This project is usually named Project1. This project is not set up properly for the programs in this book, however, so you will begin a new project. Click File on the menu bar. On the File menu, click New, then click Other... You see the New Items dialog box shown in Figure L-15. (Make sure the New tab at the top of the dialog box is selected.)

L-10

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-15

3. All of the programs in this book are console programs, so click Console Wizard, then click the OK button. The dialog box shown in Figure L-16 is displayed. Figure L-16

4. Make sure C++ and Console Application are selected. No other options should be selected. Click the OK button. A dialog box appears asking Save changes to Project1? (The name you see may be different from Project1.) Because the default project is empty, click the No button. Your screen now looks similar to Figure L-17.

Using Borland C++ Builder 6

L-11

Figure L-17

5. The window that is currently titled Unit1.cpp is the text editor. C++ Builder automatically creates a program skeleton for you. The skeleton contains some preprocessor directives and an empty function main. You can modify the code skeleton, or erase it and write your own program from scratch. For example, Figure L-18 shows a simple program that has been written in the editor after the default program skeleton has been erased.

L-12

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-18

Saving a Project to Disk It is important to periodically save your work. To save your project for the rst time, click File on the menu bar, and then click Save Project As on the File menu. A Save As dialog box appears for the C++ source le. The source les default name is Unit1.cpp. Click the OK button if you want to keep this name. If you wish to save the source le under a different name, enter the new name, and click the OK button. (Make sure you use the .cpp extension if you change the name of the le.) Next, a Save As dialog box appears for the project le. A default name, such as Project2.bpr, will appear as the project les name. Click the OK button if you want to keep this name. If you wish to save the project le under a different name, enter the new name, and click the OK button. (Make sure you use the .bpr extension if you change the name of the le.) After you have saved the project the rst time, you may save it subsequent times by clicking File on the menu bar, then clicking Save All.

Using Borland C++ Builder 6

L-13

Compiling and Executing Once you have entered a programs source code, you may compile and execute it by any of the following methods: by clicking the button by pressing F9 by clicking Run on the menu bar, and then clicking Run. A window at the bottom of the editor pane appears if errors are found in your program. Double click an error message in the window, and the editor will highlight the line of code where the error was encountered. For example, look at the program in Figure L-19. The cout statement is missing a semicolon. By double-clicking the error message, the text cursor is positioned on 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 L-19

If the program compiles successfully, a console window appears and the program runs. This is illustrated in Figure L-20. Pausing a Program's Output Notice that the program shown in the previous example has a cin.get() statement in function main. This statement causes the program to pause until the user presses the Enter key. The statement is in the program because the console window automatically closes as soon as the program is nished. If the program did not have the cin.get() statement, it would quickly ash the message This is a simple program on the screen, and the console window would suddenly close.

L-14

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-20

Sometimes a single cin.get() statement will not pause the screen. (This is because a prevous cin statement has left a newline character in the keyboard buffer.) A better way of pausing the screen is to include the conio.h header le and use the getch() function at the end of the program. This is demonstrated in Program L-1. Program L-1
1 2 3 4 5 6 7 8 9 #include <iostream> #include <conio.h> // Needed for the getch() function using namespace std; int main() { cout << "A simple program!"; getch(); return 0; }

Closing a Project To close the project that you currently have open, click File on the menu bar, and then click Close or Close All. Opening an Existing Project To open an existing project, click File on the menu bar, and then click on Open Project Use the resulting dialog box to browse to the location of your project le. When you have located your project le, double-click it. The project will be opened with its source code le(s) displayed in the text editor. Creating a Multi-File Project Many of your programs will consist of more than one le. For example, suppose your instructor has asked you to write a simple class named Pet. An instance of the class will hold the name of your pet. You decide to write the following specication and implementation les.

Using Borland C++ Builder 6

L-15

Contents of Pet.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // Pet class specification file #ifndef PET_H #define PET_H #include <string> using namespace std; class Pet { private: string name; public: // Constructor Pet(string); // Accessor function for name string getName() const; } ; #endif

// To hold the pet's name

Contents of Pet.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 // Pet class implementation file #include <string> #include "Pet.h" using namespace std; // Constructor Pet::Pet(string str) { name = str; } // getName member function string Pet::getName() const { return name; }

To demonstrate the class, you decide to write the code in Program L-2. Program L-2
1 2 3 4 5 #include <iostream> #include <conio.h> #include "Pet.h" using namespace std;

L-16

Appendix L

Introduction to Borland C++ Builder 6.0

6 int main() 7 { 8 // Create an instance of the Pet class. 9 Pet myPet("Fido"); 10 11 // Display my pet's name. 12 cout << "My pet's name is " << myPet.getName() << endl; 13 getch(); 14 return 0; 15 }

The following steps show you how to create all three les in the same project. 1. Start a new project by following steps 1 through 5 under the section Starting a New Project. 2. The text editor opens with a default le named Unit1.cpp. We will rename this le in a moment. Enter the C++ source code for Program L-2 into the text editor. 3. After you have entered the code, you need to save the le under a more meaningful name. We will name the le PetDemo.cpp. Click File on the menu bar, then click Save As... A Save As dialog box appears. Browse to the location where you wish to save the le, and then enter PetDemo.cpp as the le name. Click the OK button. Your editor window will look similar to Figure L-21. Figure L-21

4. Now we will write the source code for the Pet.h le. But rst, we need to add a new, empty source le to the project. Click File on the menu bar. On the File menu, click New, then click Other... You see the New Items dialog box shown in Figure L-22. (Make sure the New tab at the top of the dialog box is selected.)

Using Borland C++ Builder 6

L-17

Figure L-22

5. In the New Items dialog box, select Header File and click the OK button. An empty le with a default name such as File1.h will be added to the project. We will rename the le in a moment. The editor window should now appear as shown in Figure L-23. Notice there are two tabs at the top of the window: one for PetDemo.cpp and another for File1.h. You can use these tabs to switch your view between the two les. Figure L-23

L-18

Appendix L

Introduction to Borland C++ Builder 6.0

6. With the File1.h tab selected, enter the code for the Pet.h le. After you have entered the code, you need to save the le under the name Pet.h. Click File on the menu bar, then click Save As... A Save As dialog box appears. Browse to the location where you wish to save the le, and then enter Pet.h as the le name. Click the OK button. Your editor window will look similar to Figure L-24. Figure L-24

7. Now we will write the source code for the Pet.cpp le. But rst, we need to add a new, empty C++ source le to the project. Click File on the menu bar. On the File menu, click New, then click Other... You see the New Items dialog box. (Make sure the New tab at the top of the dialog box is selected.) Select Cpp File and click the OK button. An empty le with a default name such as File1.cpp will be added to the project. We will rename the le in a moment. Notice now there are three tabs at the top of the window: one for PetDemo.cpp, one for Pet.h, and one for File1.cpp. 8. With the File1.cpp tab selected, enter the code for the Pet.cpp le. After you have entered the code, you need to save the le under the name Pet.cpp. Click File on the menu bar, then click Save As... A Save As dialog box appears. Browse to the location where you wish to save the le, and then enter Pet.cpp as the le name. Click the OK button. Your editor window will look similar to Figure L-25.

Using Borland C++ Builder 6

L-19

Figure L-25

9. All three les, PetDemo.cpp, Pet.h, and Pet.cpp, have been created in our project. Follow the instructions in the section Compiling and Executing to test the program. Adding Example Source Files to a Project If you wish to compile and execute one of the example source les that come with this book, you will have to create a project and add the le to the project. If the example source le is part of a multi-le program, you will have to add all of the les that are part of the program to the project. The following steps lead you through the process. (This tutorial assumes you have copied the Appendix L example source code folder from the Student CD to your hard drive. If you have not, do so before performing these steps.) NOTE: None of the example programs in this book have the getch() statement to pause the program's output. You will need to add the #include <conio.h> directive and the getch() statement in order to pause the program's output. 1. Launch Borland C++ Builder. Click File on the menu bar. On the File menu, click New, then click Other... You see the New Items dialog box shown in Figure L-26. (Make sure the New tab at the top of the dialog box is selected.)

L-20

Appendix L

Introduction to Borland C++ Builder 6.0

Figure L-26

2. Select Console Wizard, then click the OK button. The Console Wizard dialog box is then displayed. Make sure the following items are selected: C++ Console Application Specify project source Because we selected Specify project source, we must also select a source le to initially load into the project. Click the button showing the ellipsis ( ). The Specify Project Source dialog box should appear. Browse to the Appendix L example source code folder and select the le PrL-3.cpp and click the Open button. The Console Wizard dialog box should now appear similar to Figure L-27. Click the OK button. Figure L-27

3. You should now see the program PrL-3.cpp open in the text editor. If this were the only le in the program, we could compile and execute it. This program, however, uses the Rectangle class, which is in the Rectangle.h and Rectangle.cpp les. Next we will add the Rectangle.cpp le to the project. Click Project on the menu

Using Borland C++ Builder 6

L-21

bar. On the Project menu, click Add To Project The Add to Project dialog box appears next. Use the dialog box to nd the le Rectangle.cpp in the Appendix L example source code folder. When you locate the le, click it and then click the Open button. The le Rectangle.cpp is now a member of the project, and appears in the text editor window. 4. The Rectangle.h le does not have to be added to the project because the PrL-3.cpp le has an #include directive that will cause Rectangle.h to be included just before compilation takes place. However, we might want to open the le in the text editor to examine it. To open the le, click File on the menu bar, then click Open. An Open dialog box appears. Use the dialog box to nd the le Rectangle.h in the Appendix L example source code folder. When you locate the le, click it and then click the Open button. The le Rectangle.h now appears in the text editor window. 5. Now you should save the project. Click File on the menu bar, and then click Save Project As on the File menu. A Save As dialog box appears for the project le. Browse to the Appendix L example source code folder on your hard drive. A default name, such as Project2.bpr, will appear as the project les name. Click the OK button if you want to keep this name. If you wish to save the project le under a different name, enter the new name, and click the OK button. (Make sure you use the .bpr extension if you change the name of the le.) 6. Follow the instructions in the section Compiling and Executing to test the program. Where Data Files Are Created When you create a new project, you normally save all of the les associated with that project in the same folder. (See the Saving Your Project to Disk section.) This folder is known as the project folder. For example, suppose weve created a project named Lab5, and saved it in the folder C:\MyProjects\Lab5. All of the C++ source les that you have created for this project, as well as the project le that ends with the extension .bpr, will be stored in that folder. Its important to know the location of the project folder when writing code that opens les for input or output. When running a program from the C++ Builder IDE, the project folder is the default location for all data les. For example, suppose our Lab5 project creates a le with the following code:
ofstream outputFile("names.txt");

Because we have not specied a path with the le name, the le will be created in the C:\MyProjects\Lab5 project folder. Similarly, if our program attempts to open an existing le for reading, it will look in the project folder by default. For example, suppose our Lab5 program attempts to open a le with the following statement:
ifstream inputFile("names.txt");

Because we have not specied a path, the program will look for the le in the project folder, C:\MyProjects\Lab5. If we want to open a le in a location other than the project folder, we must provide a path as well as a le name. For example, the following statement opens a le named Data.txt in the C:\Data folder.
ofstream outputFile("C:\\Data\\Data.txt");

L-22

Appendix L

Introduction to Borland C++ Builder 6.0

Notice that weve 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. Heres another example:
ifstream inputFile("E:\\names.txt");

This statement attempts to open the names.txt le in the root folder of drive E.

You might also like