Followings are the sections in the structure of a C++ Program
1.
Documentation
Section
2.
Preprocessor
Directives or Compiler Directives Section
a.
Link Section
b.
Definition Section
3.
Global Declaration
Section
4.
Class declaration or
definition
5.
Main ( )
1) Documentation Section: In Documentation section we give the Heading,
Comments and brief introductory description of the program. Comment
statement is the non-executable statement.
Comment can be given in two ways:
Single Line Comment: Comment can be given in single line by using"//".
Multiple
Line Comment:Comment can be given in multiple lines starting by using "/*" and end with "*/ ".
2)
Preprocessor
Directives: Preprocessor Directives are divided into two parts.
Link Section:
In the Link Section, we can link the compiler function like cout<<,
cin>>, sqrt ( ), , clrscr( ), with the INCLUDE
subdirectory having header files like iostream.h, conio.h, math.h,
ctype.h, etc. It becomes very useful during the compilation and the linkage
phase.
The general syntax is:
#include <header file>
Definition Section: The second section is the Definition section
by using which we can define a variable with its value. For this purpose define
statement is used.
The general syntax is:
#define variable name value
For example:
#define PI 3.142
3) Global Declaration Section: In this section, we
declare some variables before starting of the main program or outside
the main program. These variables are globally declared and used by the main
function or sub function. These variables are called global variables.
4)
Class declaration or definition: in this section we declare the class. The general syntax or general
form of the class declaration is as follows:
Class <name of class>
{
Datammbers;
Functions ();
}
5)
Main (): main function is where a program starts
execution.
Writing the
First C++ Program:
// my first program in C++ // Comment Line
#include <iostream.h> // Preprocessor Directives
Void main() // Main function/function definition
{
cout << "Hello World!"; //
function body}
}
0 comments:
Post a Comment