C++ programs can be created using any text editor. For the UNIX implementation of C++, vi or ed text editor can be used for creating and editing the source
code. For the DOS implementations of C++, edlin or any other editor can be used. Some systems such as Turbo C++ and Borland C++ provide an
Integrated Development Environment (IDE) for developing programs. These IDEs provide facilities for typing, editing, searching, compiling etc integrated
in one package.
A C++ program files should have a proper file extension depending upon the implementation of C++, it is developed/compiled into. C++ implementations use several
extensions, for example .c, .cc, .cpp, .cxx etc. TurboC++ and Borland C++ use .cpp for C++ programs. Zortech C++ uses extension .cxx and UNIX AT&T
versions use .c and .cc extension.
Compile and Execute C++ Programs using Borland C++
For writing and compiling programs in Borland C++, the Borland C++ software must either be available on hard disk or floppy disk. After booting your system and once the
dos prompt appears on the screen, then do the following steps :
- Place your working copy of Borland C++ program disk in the floppy disk drive, (if you have BC++ on floppy disk), or change to your Borland C++
subdirectory (if BC++ on the hard disk).
- Type BC at the dos prompt and press Enter. It will take you to the IDE (Integrated Development Environment) of BC++.
The topmost row of the IDE displays its menu that contains options ≡, File, Edit, Search, Run, Compile, Debug,
Project, Options, Window, Help. Each option on the menu can be involved by pressing Alt key and the highlighted letter of the
menu option. The option (≡), the system menu option, can be involved by pressing Alt+spacebar. For details, you can refer to the user manual of Borland
- To write a program, then, Press Alt+E to start the editor, and then Type your C++ program line by line
- To save your program, then, After typing the program, press Alt+F to activate File menu, Press S to save the program file,
Type the program name you want to give to your program file. You need not give extension .cpp since Borland C++ adds it automatically,
and then Press Enter and your file is saved.
- To compile your program, press Alt+F9 key combination or alternatively you can press Alt+C followed by C or enter key.
- To run your program, press ctrl+F9 key combination or alternatively Alt+R followed by R or enter key.
When you execute (run) your program, it waits for the user input if required any and carries out all the instructions.
- To see your program output, press the key combination Alt+F5. Any keypress or click will take your back to Borland C++ IDE.
Compile and Execute C++ Programs using TurboC++
Now let's look at how to save the C++ programming source code in a file, and how to compile and run it using the TurboC++ compiler. Following are the simple steps:
- Download TurboC++ compiler(recommended) from Download TurboC++
- Install it on you system
- Now open TurboC++ and type your C++ program inside it.
- After typing your complete C++ program, press Alt+F key and go to save button and type your program name followed by .cpp extension and press enter. Now
your program will be saved inside BIN directory of TurboC++ in C drive.
- Now to compile C++ program, simply press F9 key, if an error occur then watch at your code to make correction and
- If there will no error appears, then press Ctrl+F9 key to run the program and watch the result.
Role of Compiler
A part of compiler's job is to analyse the program code for "correctness". If the meaning of a program is correct, then a compiler can not detect errors (for example,
if different statements are used etc.), but a compiler can certainly detect errors in the form of a program. Some common forms of program errors are :
- Syntax Errors - Syntax errors occur when rules of a programming language are misused i.e., when a grammatical rule of C++ is voilated.
- Semantics Errors - Semantic errors occur when statements are not meaningful. Semantic refers to the set of rules which give the meaning
of a statement. For instance, the statement.
- Type Errors - Data in C++ has an associated data type. The value 7, for instance, is an integer. 'a' is a character constant and "hello" is a string.
If a function is given wrong type of data, type error is signalled by the compiler.
- Run-time Errors (Execution Errors) - A run-time error is that occurs during the execution of a program. It is caused of some illegal operation taking place
or in-availability of desired or required conditions for the execution of program.
- Logical Errors - A logical error is that error which causes a program to produce incorrect or undesired output.
C++ Environment Setup Step by Step - TurboC++
First download TurboC++ compiler (link provided above), then install it on your system, and open the TurboC++ compiler, here is the windows
coming up after opening the TurboC++ compiler on your system:
Now go to File, and click on New (or simply press Alt+F and then ENTER). After doing this, here is the windows coming up. If you see that
the windows is not appearing in full screen on your system, then simply press Alt+ENTER to make the windows appears in full screen. :
Now to make blue color to occupy full screen or to type your C++ program in full screen mode, simply press F5 function key. Here is the
image showing this:
Now type this C++ program in the windows as shown in above figure:
cout<<"Welcome to codescracker.com";
Type the above code like this:
Before compiling any C++ program, first save the typed C++ program code. To save simply click on FILE and then on SAVE AS, and type the program name
with .cpp extension and press ENTER like this:
Now type program name with .cpp extension as shown here in this figure:
After typing program name and pressing ENTER, here is the figure showing the next output. See the program name present at the top of the windows
in the middle:
Now to compile your C++ program, simply press F9 key, after successfully compilation, here is the image showing:
Press ENTER or any key. To run your C++ program, simply press Ctrl+F9. After doing this, the program will produce this output:
Now press any key, to go back to the code window and start programming in C++.
Here are some more C++ programs listed, that you can experiment on it:
C++ Programming Online Test
Latest 5 Posts by CodesCracker