Basic-Structure-of-Program .

In this session i have discussed basic structure of program .


C++ is the extension of C . You can write more than 90% code of C in C++ .


The C++ program can be divide into 4 section as follows .

1-Header File Section

2-Class Definition Section

3-Member-Function Definition Section

4-Main Function Section


1-Header Files Section

The header file section includes the various header files like iostream.h , conio.h etc . The header file contains the inbuilt functions that we can use directly in our program .

For Example :

    #include<iostream.h>
    #include<conio.h>
    

2-Class Definition Section

In this section we can declare the class . After declaration of class declare the data members and member function inside the class .

For Example

    class ABC
    {
        int a, b ;//data members
        public :
            void show();//member function
    
    };
    

3-Member Function Definition Section

This section contains the member function definition . But it is optional because You can declare and define the function inside the class and in this section both . If all the member function inside the class then no need for this section .

For Example

    void ABC::show
    {
        cout<<"Hello sir"; // print the hello sir on output     
    }
    

4-Main Function Section

This the very important point in program . It is starting point for the compiler . You can create the object of class and call the function .

For Example

    main()
    {
        ABC obj; // object created
        obj.show(); //function call with object 

    }
    

Example : Write a program that demonstrate the basic structure of C++ program .

   #include<iostream.h> // Header file section
   class ABC  // Class declaration section
   {
        public :
        void show;
        void display()
        {
            cout<<"Hello display";
        }
   };
   void ABC:: show() // Member function definition
   {
        cout<<"Hello show";
   }
   int main() // Main function section
   {
        ABC obj; // object created
        obj.show(); //function call with object 
        return 0;
   }
    

Welcome to AndroidATPoint.

back image                     next image