fork download
  1. #include<iostream>
  2. #define PI 3.1416
  3. using namespace std;
  4.  
  5. class Shape{
  6. public:
  7. float area, volume;
  8. void display(){
  9. cout<<"Area: "<<area<<endl;
  10. cout<<"Volume: "<<volume<<endl;
  11. }
  12. };
  13.  
  14. class Rectangle:public Shape{
  15. float length;
  16. float width;
  17. float height;
  18. public:
  19.  
  20.  
  21. Rectangle(float l, float w, float h){
  22. length=l;
  23. width=w;
  24. height=h;
  25. }
  26. void calculate(){
  27. area=length*width;
  28. volume=length*width*height;
  29. display();
  30. }
  31.  
  32. };
  33.  
  34. class Circle:public Shape{
  35. float radius;
  36. float height;
  37. public:
  38. Circle(float r, float h){
  39. radius=r;
  40. height=h;
  41. }
  42. void calculate(){
  43. area=PI*radius*radius;
  44. volume=PI*radius*radius*height;
  45. display();
  46.  
  47. }
  48. };
  49.  
  50. class Triangle:public Shape{
  51. float base, height;
  52. float length ;
  53. public:
  54. Triangle(float b, float h, float l){
  55. base=b;
  56. height=h;
  57. length=l;
  58. }
  59.  
  60. void calculate(){
  61. area=0.5*height*base;
  62.  
  63. volume=0.5*(base*height*length);
  64.  
  65. display();
  66. }
  67. };
  68.  
  69. int main(){
  70. Circle r(4.0,3.0);
  71. r.calculate();
  72.  
  73. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Area: 50.2656
Volume: 150.797