Answer to Question #240346 in C++ for xyz

Question #240346

For the program given below, write statements to call display function from base and

derived class in main.

class base

{

int x;

public:

base (int a){x=a;}

void display ( )

{ cout <<x<<"\n";}

};


class derived :public base

{ int d;

public:

derived (int a, int b): base (a)

{ d=b; }

void display ( )

{cout <<d;}

};


int main ( )

{ derived D(10,20);

return 0;

}


1
Expert's answer
2021-09-23T17:48:15-0400


#include<iostream>
using namespace std;
class base


{


int x;


public:
base(){
}
base (int a){
x=a;


}


void display ( )


{ 
cout <<x<<"\n";


}


};






class derived :public base


{ int d;


public:


derived (int a, int b): base (a)


{ 


d=b; 


}


void display ( )


{


cout <<d;




}


};






int main ( )


{ 


base b(5);
b.display();


derived D(10,20);
D.display();


return 0;


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS