Posts

Showing posts with the label Volume

In Cpp, Compute Volume And Surface Area Of Box

Image
Download

In Cpp, Application That Calculates The Surface Area And Volume Of 2 Cylinders Using Two Sets Of Classes

Image
#include<iostream> #include<cmath> using namespace std; class ProtectedCircle{ protected: float radius; public: void setRadius(float r){ if(0 <= r) radius = r; } public: float getRadius() const{ return radius; } public: float getPerimeter() const{ return (2 * M_PI * radius); } public: float getArea() const{ return (radius * radius) * M_PI; } public: ProtectedCircle(float r = 0){ setRadius(r); } }; class ProtectedCylinder: public ProtectedCircle { private: float height; public: void setHeight(float h){ if(0 <= h) height = h; } public: float getHeight() const{ return height; } public: float getArea() const{ return (((radius * radius) * (2 * M_PI)) + (2 * M_PI * radius * height)); } public: float getVolume() const{ return (M_PI * (radius * radius) * height); } public: ProtectedCylinder(float r = 0, float h = 0): ProtectedCircle(r){ setHeight(h); } }; class PrivateCircle{ ...

In Java, Compute And Display Area And Volume Of Various Shapes

Image
Download

How to find area & volume of different shapes with C#?

Image
using System; interface Shape{ double Area{get;} string Desc{get;} }; interface TwoDimensionalShape : Shape {} interface ThreeDimensionalShape : Shape { double Volume{get;} } class Circle: TwoDimensionalShape{ private double Radius; public Circle(double r){Radius = r;} public double Area{ get{ return ((Radius * Radius) * Math.PI); }} public string Desc{get{return "A circle";}} } class Square: TwoDimensionalShape{ private double Side; public Square(double s){Side = s;} public double Area{ get{ return (Side * Side); }} public string Desc{get{return "A square";}} } class Sphere: ThreeDimensionalShape{ private double Radius; public Sphere(double r){Radius = r;} public double Area{ get{ return (4 * Math.Pow(Radius,2) * Math.PI); }} public double Volume{ get{ return (4/3.0 * Math.Pow(Radius,3) * Math.PI); }} public string Desc{get{return "A sphere";}} } class Cube: ThreeDimensionalShape{ private double Side; public Cub...