Add two numbers using class in c++ is simple addition program which we are implementing using class in c++.
In this tutorial we will see what is class, How to add numbers using class , and c++ program to add two numbers.
What is class ?
Class definition : Class is a user defined data type. It encloses data members and member functions.
By default all the members of the class are private.
How to add numbers using class
For this we create class addition in which we write functions which adds two numbers.
Algorithm to add two numbers using class in c++
- Write class and Define function which adds two numbers
- Write main function
- Take two number input
- Pass number and call function
C++ addition program using class
using namespace std;
cout<<"\n Enter two values : ";
void add(); //member function
void addition :: add()
sum = a+b;
cout<<"\nAddition is = "<<sum;
addition a1; //object created