Class with default constructor in C++

 #include<iostream>
using namespace std;
class alpha 
{
int x;
public:

alpha(int i //constructor 
{
x=i;
cout<<"alpha initialized\n";
}
void showx()
{
cout<<"x="<<x<<endl;
}
};
class beta
{
float y;
public:

beta(float b)
{
y=b;
cout<<"Beta initialized\n";
}
void showy()
{
cout<<"y="<<y<<endl;
}
};
class gamma:public alpha,public beta
{
int m,n;

public:
gamma(int a,float b,int c,int d):alpha(a),beta(b)
{
m=c;
n=d;
cout<<"Gamma initialized\n";
}
void showmn()
{
cout<<"M="<<m<<endl;
cout<<"N="<<n<<endl;
}
};
int main()
{
gamma g(5,30.3,23,12);
cout<<"\n";

g.showx();
g.showy();
g.showmn();
}


output:
alpha initialized
Beta initialized
Gamma initialized

x=5
y=30.3
M=23
N=12

Comments