Coupon Accepted Successfully!


Steps to Create and Execute a C++ Program

For creating and executing a C++ program, one must follow various phases. The C++ program is created with an editor and saved with extension .cpp. Following this step, compilation and execution operations are to be performed. The following phases are essential in ‘C++’ when a program is to be executed in MS-DOS mode.

  1. Create
  2. Save
  3. Compile
  4. Execute

We would now see the steps in each phase.

  1. Steps for creation of a C++ program
    1. Open the Turbo C++ editor. In this book, the path selected for opening the C++ editor is C:\TURBOC3\TC\BIN. Executable file TC is to be clicked in BIN file to open the window of C++.
    2. In the Edit menu section with alt+f, select the New option. A new file is selected with this procedure.
    3. The program should be written in ‘C++’ editor.
  2. Saving a C++ program
    1. Save the program using the Save option in the file menu with extension .cpp. The reader may create his/her own folder where programs are to be stored. The file name does not necessarily include extension “.cpp.” The default extension is “.cpp.” The user can also specify his/her own extension. The C++ program includes preprocessor directives.
  3. Compilation of a C++ program
    1. The source program contains statements that are to be translated into object codes. These object codes are used for execution by the computer. So, compile the source code with alt+c keys.
    2. If the program contains errors, the programmer should correct it using C++ editor.
    3. If there is no error in the program, compilation proceeds and the translated program is stored in another file with the same file name and with extension “.obj.” This object file is stored on a secondary storage device such as the disk.
  4. Linking and running/execution of a C++ program
    1. The linking is also an essential process. It puts together all the program files and functions that are required by the program. For example, if the programmer is using pow() function, then the object code of this function should be brought from math.h library of the system and linked to the main() program. After linking, the program code is stored on the disk. The program code generated is called the executable code.
    2. Run the executable code file with alt+r, in case of no errors. In case there are errors, correct the program, and follow steps (1), (2), (3), and (4).

Test Your Skills Now!
Take a Quiz now
Reviewer Name