Write a C++ program to add two numbers using constructor?

All QuestionsCategory: Cpp LanguageWrite a C++ program to add two numbers using constructor?
Chetan Shidling Staff asked 5 years ago

I need short information.

1 Answers
Chetan Shidling Staff answered 5 years ago

Code:

#include <iostream>
using namespace std;
class point
{
int x, y;
public:
point(int a1, int b1)
{
x = a1;
y = b1;
cout<<“x =”<<x<<“\n”;
cout<<“y =”<<y<<“\n”;
cout<<“X + Y =”<<x + y;
}
};
int main()
{
point t1 = point(10, 20);
return 0;
}

Output:

x =10
y =20
X + Y =30