Answer to Question #203501 in C++ for Sherlyn Alipo-on

Question #203501

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


1
Expert's answer
2021-06-05T02:14:19-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog