Saved Bookmarks
| 1. |
Write the definition of a class CONTAINER in C++ with the following description: Private Members – Radius, Height // float – Type //int (1 for Cone, 2 for Cylinder) – Volume // float – CalVolume() // Member function to calculate // volume as per the TypePublic Members – GetValues() // A function to allow user to enter value // of Radius, Height and Type. Also, call // function CalVolume () from it – ShowAll () // A function to display Radius, Height, // Type and Volume of Container |
|
Answer» class CONTAINER { float Radius, Height, Volume; int Type; void Cal Volume() { if(Type ==1) Volume = 3.14* Radius * Height; else if (Type =2) Volume = 3.14* Radius * Height/3; else Volume =0; } public; void GetValues() { cout<<"\n Enter the Radius"; cin>>Radius; cout<<"\n Enter the Height"; cin>>Height; cout<<"\n Enter the Type (1 for Cone, 2 for Cylinder)"; cin>>>Type; CalVolume(); } void ShowAll() { cout<<"\n Radius :"<<Radius; cout<<"\n Height:"<<Height; cout<<"\n Type :"< cout<<"\n Volume:"<<Volume; } }; |
|