Popular Posts

33.Write a program by inheritance and show a= 5 b= 10 c= 50 a= 5 b= 20 c= 100

33.Write a program by inheritance and show

a= 5
b= 10
c= 50

a= 5
b= 20
c= 100


#include
#include
class B
{
int a;
public:
int b;
void get_ab();
int get_a(void);
void show_a(void);
};
class D:public B
{
int c;
public:
void mul(void);
void display(void);
};
void B::get_ab(void)
{
a=5;b=10;
}
int B::get_a()
{
return a;
}
void B::show_a()
{
cout<<"a= "< }
void D::mul()
{
c=b*get_a();
}
void D:: display()
{
cout<<"a= "< cout<<"b= "< cout<<"c= "< }
int main()
{
clrscr();
D d;
d.get_ab();
d.mul();
d.show_a();
d.display();
d.b=20;
d.mul();
d.display();
getch();
return 0;
}

Output:

a= 5
b= 10
c= 50

a= 5
b= 20
c= 100

No comments: