CS Electrical And Electronics
@cselectricalandelectronics

Write a Cpp program and use multiple constructor?

All QuestionsCategory: Cpp LanguageWrite a Cpp program and use multiple 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 integer
{
int m, n;
public:
integer(){m=0;n=0;}
integer(int a, int b)
{
cout<<“A:”<<a<<“\n”<<“B:”<<b<<“\n”;
m=a;n=b;
}
integer(integer &i)
{
m = i.m;
n = i.n;
cout<<“M:”<<m<<“\n”<<“N:”<<n;
}
};
int main()
{
integer I1;
integer I2(10, 20);
integer I3(I2);
return 0;
}

Output:

A:10
B:20
M:10
N:20