CS Electrical And Electronics
@cselectricalandelectronics

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

All QuestionsCategory: Cpp LanguageWrite a C++ program to add two numbers using constructor?
CS Electrical And Electronics Staff asked 4 years ago

I need short information.

1 Answers
CS Electrical And Electronics Staff answered 4 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