The perfect place for easy learning...

C++ Programming

×

Topics List


C++ Program Structure





The C++ programming language supports both procedure-oriented and object-oriented programming paradigms. So, we can write a C++ program using the POP structure and OOP structure too.

POP structure of C++ program

/*documentation*/
pre-processing statements 
global declaration;
void main()
{
    Local declaration;
    Executable statements;
    .
    .
    .
}
User defined functions 
{
    function body
    .
    .
}

Let's create a C++ program using the POP structure.

Example
/*Program to perform addition of two numbers*/
#include<iostream.h> 
int a, b;
void main()
{
    int c;
    void get_data();
    int sum(int, int);
    
    get_data();    
    c = sum(a, b);    
    cout << "Sum = " << endl;
}
void get_data() 
{
    cout << "Enter any two numbers: ";
    cin >> a >> b;
}

int sum(int a, int b)
{
    return a + b;
}

OOP structure of C++ program

/*documentation*/
pre processing statements 
class ClassName
{
    member variable declaration;
    .
    .
    .
    member functions(){
        function body
        .
        .
    }
};
void main ()
{
    ClassName object;
    object.member;
}


Let's create a C++ program using the OOP structure.

Example
/*Program to perform addition of two numbers*/
#include<iostream.h> 

class Addition{
    int a, b;
    public:
        get_data(){            
            cout << "Enter any two numbers: ";
            cin >> a >> b;
        }
        int sum(){
            get_data();
            return a + b;
        }
};

void main(){
    Addition obj;
    cout << "Sum = " << sum() << endl;
}

🔔 The POP structure program follows the top-bottom flow of execution.

🔔 The OOP structure program follows the bottom-top flow of execution.