Write a c++ program to implement single inheritance

#include<iostream>

using namespace std;

class B

{ int a;

public:

int b;

        void get_ab();

int get_a();

void show_a(void);

};

class D:private B

{

int c;

public:

void mul(void);

void display(void);

};

void B:: get_ab()

{

cout<<“Enter the value of a\n”;

cin>>a;

cout<<“Enter the value of b\n”;

              cin>>b;

}

int  B::get_a()

return a; void B::show_a(void)

{

 cout <<“The value of a= “<<a<<endl;

 cout<<“The value of b= “<<b<<endl;

}

void D::mul()

{   

    get_ab();

get_a();

c=b*get_a();

}

                                                                                                                              

void D::display(void)

{

cout<<“The multiplication result is “<<c<<“\n”;

}

int main()

{

D d;

 d.mul();

d.display();

return 0

;}

output:

enter the value of a

              20

               Enter the value of b

               30

               The multiplication result is

                600

Leave a Comment

Your email address will not be published.