write a program and input two integers in main and pass them to default constructor of the class show the result of the addition of two numbers
#include <iostream>
class operation {
int a, b;
operation(int a,int b){
this->a = a;
this->b = b;
std::cout<<"Numbers initialized"<<std::endl;
}
int sum(){
return this->a+this->b;
}
};
int main ()
{
int a, b;
std::cout<<"Enter first number : ";
std::cin>>a;
std::cout<<"Enter second number : ";
std::cin>>b;
operation op(a, b);
std::cout << "The addition result on:"<< op.sum()<<std::endl;
return 0;
}
Comments
Leave a comment