Constructor in derived class

/* Constructor in derived class */
#include<iostream>
using namespace std;
class Alpha{
int x;
public:
Alpha(){ x = 0; }
Alpha(int i){ x = i; }
void show_x(){
cout<<“X=”<<x<<endl;
}
};
class Beta{
float p,q;
public:
Beta(){
p = 0.0; q = 0.0;
}
Beta(float a, float b){
p =a; q = b;
}
void show_pq(){
cout<<“P=”<<p<<endl;
cout<<“Q=”<<q<<endl;
}
};
class Gamma: public Beta, public Alpha{
int z;
public:
Gamma(){ z = 0; }
Gamma(int a, float b, float c, int d):
Alpha(a), Beta(b,c){
z = d;
}
void show(){
show_x();
show_pq();
cout<<“Z=”<<z<<endl;
}
};
int main(){
Gamma g2;
Gamma g1(1,2,3,4);
g1.show();
return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>