C++ program to print the addition of numbers using default constructor
codeaft.cpp
#include <iostream>
using namespace std;
class codeaft
{
    int a, b;

public:
    void add()
    {
        cout<<"The addition of "<<a<<"+"<<b<<"="<<(a + b)<<"\n";
    }
    codeaft()
    {
        a = 10;
        b = 10;
    }
};
int main()
{
    codeaft c;
    c.add();
    return 0;
}
Output
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out The addition of 10+10=20 codeaft@codeaft:~$
C++ program to print the addition of numbers using parameterized constructor
codeaft.cpp
#include <iostream>
using namespace std;
class codeaft
{
    float a, b;

public:
    void add()
    {
        cout<<"The addition of "<<a<<"+"<<b<<"="<<(a + b)<<"\n";
    }
    codeaft()
    {
        a = 10, b = 10;
    }
    codeaft(int x, float y)
    {
        a = x;
        b = y;
    }
};
int main()
{
    codeaft c, d(10, 10.02351);
    c.add();
    d.add();
    return 0;
}
Output
codeaft@codeaft:~$ g++ codeaft.cpp
codeaft@codeaft:~$ ./a.out The addition of 10+10=20 The addition of 10+10.0235=20.0235 codeaft@codeaft:~$
Comments and Reactions
What Next?
C++ Functions