Lab 0: C++ Builder Instructions


IDEs

An IDE (integrated development environment) manages the programs that programmers write; they include at least an editor and compiler and often some analysis and management tools.

Most (probably all) IDEs provide you with an editor to enter the text of a program and save it in a file. Once your program is saved, you can translate it into your computer's machine language (the binary 0s and 1s that a computer understands) using the C++ Builder compiler and linker. Graphically the process can be pictured as follows:

Starting C++ Builder

Invoke C++ Builder according to your instructor's directions. (This may involve double-clicking on an icon on your computer's desktop or choosing a menu item.)

Creating a Project

The C++ Builder IDE requires that all programs be part of a project that simplifies the translation of a source program into machine language. Normally, we create a project first, before we create any source files for our program, although it is quite easy to add existing source files to a project.

To create a project, first close any projects that are already open with the File -> Close All menu item. Then, select Project -> Add New Project.... In the New Items window that pops up, select the New tab, select the Console Wizard icon, and hit the OK button.

Select C++ as the Source Type; do not use VCL or CLX; Multi-Threaded is fine; Console Application is required. Hit the OK button.

You'll get a file window that opens called Unit1.cpp (or something close to it). Close this window without saving changes to it.

Immediately save the project with a name of your own choosing. (By default it'll be called something like "Project1", and that's not necessarily helpful.) To save the project, use File -> Save Project As.... In the file dialog window that pops up, find the folder for this lab, and enter BasesProject, and hit OK.

The project has been created.

Creating the Source Program

Next, we want to create a new file named bases.cpp in which to store our program. To do so, move the mouse to the File menu within the C++ Builder window and choose File -> New -> Other.... The same New Items window will appear as before; again, make sure that the New tab is selected, then choose Cpp File from the list of options presented. Press the OK button.

A new source-file editor window will open, named File1.cpp (or something very similar). Immediately, give this file a better name by selecting File -> Save As.... The folder you used to save the project earlier should be selected by default.

For this lab, name the file bases.cpp, and hit the OK button. The window will be renamed bases.cpp, and it's ready for the source code.

Within the bases.cpp window, enter (and personalize) the C++ source code from the main exercise. Hint: copy-and-paste works just fine from a browser into a editor window in CodeWarrior.

Personalizing the Program

This program is (according to the comments) the work of a fictitious person, on a fictitious date, in a fictitious course, at a fictitious university. Edit the program's opening comment (the part between the /* and */ symbols) as appropriate to make it your work on the current date, in your course at your university.

Saving Your Work

Helpful hint: Many menu items have keyboard shortcuts and some may be found in a toolbar. Explore the IDE to find these tools to make the tedious jobs a bit easier and faster.

When the bases.cpp window contains the bases.cpp program, you can store this program in a file by choosing File -> Save. (Did you find a keyboard shortcut for this?) You may find the File -> Save All even better since it'll save your project and all of your code files.

If you look in the folder for your project, you will see that it is no longer empty, but now contains a variety of files that you never asked to be created! Don't worry about these other files; they are just your project and other administrative files C++ Builder uses to keep track of what is where. Above everything else, don't delete them!

Translating Your Program

When your source program is entered and saved, it is time to translate it into the computer's machine language. In C++ Builder, this can be done using the Project -> Make BasesProject menu choice. When this is done, C++ Builder opens a Compiling window that reports on the progress of compiling and linking your program. You'll be told when the compilation is finished and if there are any errors or not.

If the compiler or linker complains, then your program contains syntax errors (also known as "typographical errors"); these must be fixed before you can run the program.

In either case, hit the OK button. If there are no errors, you can go on to run the program. But when (not if!) your program contains errors, a Build window lists them for you just below the source code. If you double-click on a given error message, C++ Builder will move the cursor to the line in bases.cpp where it discovered the error. Compare that line and the surrounding lines with those of the source program in your web browser and fix any discrepancies. Then re-translate your program. If you still have errors, continue this edit-translate cycle as many times as necessary until your program is error-free.

Running Your Program

To run the executable program, choose Run -> Run, and the IDE will run the program for you. (It'll also compile it if it needs to be.)

When it prompts you for input, enter an easy-to-check number (like 15, 16 or 17) and verify that you get the correct results.

Unfortunately, you may find this a bit difficult in C++ Builder since the console window disappears as soon as the program finishes.

Helpful hint: To keep the console window open for a C++ Builder application, add this code at the end of every program:
int main () {
  ...
  cin.get();
}

This will require you to enter an extra line of input for the program which will be ignored. At least it will keep the console window up long enough for you to look at the output.

Printing a Hard Copy of Your Program

A paper copy of electronic information is called a hard copy; it is often useful to have a hard copy of source code. Make sure that bases.cpp is selected, and choose File -> Print. If you must do anything beyond this (such as specify a printer), your instructor will inform you of the details.

Printing an Execution Trace

C++ Builder does not allow us to print an execution trace directly. Read the instructions for printing an execution trace for Visual C++. They will also work for C++ Builder.

Back to the Main Exercise

You should go back to the main exercise now and apply the scientific method to the code that you've now compiled and executed. Remember to bookmark this page so that you can re-use these instructions throughout this lab manual.

Return to this page when you finish the main exercise so that you can clean up the project for this lab exercise.

Wrapping Up the Session

Let's examine the final things you will need to do in most sessions.

Quitting C++ Builder

To quit C++ Builder, just click on the close box of the C++ Builder window or select File -> Exit. You may be asked to save changes to your project and/or code files; take advantage of the reminder and save them!

Terminology

IDE, compiler, hard copy, integrated development environment, linker, opening comment, project, syntax error, typographical error

© 2003 by Prentice Hall. All rights reserved.
Report all errors to Jeremy D. Frens.