| #include<iostream.h> class Line { protected : float length; public : void setLength(float len) { length=len;}; float getLength () {return length;}; void showLength(){ cout<<"length is "<<length<<"\n";}; virtual void showDim (){ cout<<"Length is "<<getLength()<<"\n\n";}; }; class Circle { protected : float radius; public: void setRadius(float r){ radius=r;}; float getRadius(){return radius;}; void showRadius(){cout<<radius;}; float circleArea(){ return (2*3.14*radius*radius) ; }; }; class Cylinder : public Line ,public Circle{ public : float volume() { return (circleArea() * length) ;}; }; void main(){ cout<<"\n Defines 3 classes Line ,Circle and Cylinder \n, Cylinder inherits from both classes"; Cylinder clndr; clndr.setLength(2); clndr.setRadius(3); cout << "\n\n The cylinder volume is "<<clndr.volume(); } |