

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Class A { Int a; public: int b; void get_ab ( ) { a=5; b=10;} int get_a ( ) { return a;} void show_a ( ) { cout<<a;} } Class B : public A { int c; public: void mul ( ) { c=b * get_a ( );} void display ( ) { cout <<โa=โ<<get_a( )<<โ\nโ; cout <<โb=โ<<b<<โ\nโ; cout <<โc=โ<<c<<โ\nโ; } } Int main ( ) { B b; b.get_ab ( ); b.mul ( ); b.display ( ); } Output: a=5, b=10, c=50.
class M { Protected:
int m; public: void get_m (int x) { m=x; } } class N { Protected: int n; public: void get_n (int x) { n=x; } } Class P : public M, public N { public: void display ( ) { cout <<โm=โ<<m( )<<โ\nโ; cout <<โn=โ<<n<<โ\nโ; cout <<โmn=โ<<mn<<โ\nโ; } } int main ( ) { P p; p.get_m (10 ); p.get_n (20 ); p.display ( ); } Output: m=10, n=20, m*n=200.