Write a program for addition of two number using class and object.
Answers
Answered by
1
Answer:
#include<iostream>
using namespace std;
class Add {
public:
int addition(int x, int y) {
return x + y;
}
};
int main() {
int x, y, s;
cout << "Enter two numbers:";
cin >> x >> y;
Add obj;
s = obj.addition(x, y);
cout << "Sum of two numbers:" << s;
return 0;
}
C++
Output:
Enter two numbers:10 20
Sum of two numbers:30
Similar questions
Math,
1 month ago
Science,
1 month ago
Science,
2 months ago
Physics,
9 months ago
Computer Science,
9 months ago