Program to illustrate the concept of parameterized constructor.
#include<iostream>
using namespace std;
class A
{
private:
int a,b;
public:
A()//Default Constructor
{
a=b=1;
}
A(int x)//Parameterized Constructor
{
a=b=x;
}
void show(){
cout<<"a = "<<a<<endl<<"b = "<<b<<endl;
}
};
int main()
{
A a;
a.show();
A b(20);
b.show();
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
using namespace std;
class A
{
private:
int a,b;
public:
A()//Default Constructor
{
a=b=1;
}
A(int x)//Parameterized Constructor
{
a=b=x;
}
void show(){
cout<<"a = "<<a<<endl<<"b = "<<b<<endl;
}
};
int main()
{
A a;
a.show();
A b(20);
b.show();
cout<<"/*\nName-Sanjampreet Singh\nRoll Number-1507967\n*/";
}
Comments
Post a Comment