addition of two numbers in c++ | Using Class - InTerestinG321

addition of two numbers in c++ | Using Class

addition of two numbers in c++, Using Class:



#include<iostream>
using namespace std;
class addition
{
int a,b,sum;
public:
void read(); // Read given data
void calculate(); // Calculate the 2 numbers
void print(); // print the number that have been clalculated
}; void addition::read()
{
cout<<"enter the two numbers\n";
cin>>a>>b;
} void addition::calculate()
{
sum=a+b;
} void addition::print()
{
cout<<"sum of\t"<<a<<" and\t "<<b<<"\tis\t"<<sum;
} int main()
{
addition ob1;
ob1.read();
ob1.calculate();
ob1.print();
}


Output:

Click below Link For Download Executable "CPP" File





Click Here



No comments:

Post a Comment