Structure of C++ Program

The structure of C++ program is divided into four different sections:
(1) Header File Section
(2) Class Declaration section
(3) Member Function definition section
(4) Main function section
(1) Header File Section:
o This section contains various header files.
o You can include various header files in to your program using this section.

For example:
# include <iostream.h >

o Header file contains declaration and definition of various built in functions as well as object. In order to use this built in functions or object we need to include particular header file in our program.
(2) Class Declaration Section:
o This section contains declaration of class.
o You can declare class and then declare data members and member functions inside that class.

For example:
class Demo
int a, b;
void input();
void output();

o You can also inherit one class from another existing class in this section.

(3) Member Function Definition Section:
o This section is optional in the structure of C++ program.
o Because you can define member functions inside the class or outside the class. If all the member functions are defined inside the class then there is no need of this section.
o This section is used only when you want to define member function outside the class.
o This section contains definition of the member functions that are declared inside the class.

For example:
void Demo:: input ()
cout << “Enter Value of A:”;
cin >> a;
cout << “Enter Value of B:”;
cin >> b;

(4) Main Function Section:
o In this section you can create an object of the class and then using this object you can call various functions defined inside the class as per your requirement.

For example:
Void main ()
Demo d1;
d1.input ();
d1.output ();

We can also compare the structure of C++ program with client server application. In client server application client send request to the server and server sends response to the client.
In above C++ structure the class declaration section and member function definition section both together works as a server and main () function section works as a client. Because in main () function section we create an object of the class and then using that object we make a call to the function declared in the class.

Download Projects

Download Programs