Posts

Showing posts with the label Area

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

In Java, Design UML Of Class MyRectangle2D

Image
public class TestMyRectangle2D { public static void main(String[] args) { MyRectangle2D r1 = new MyRectangle2D(2, 2, 5.5, 4.9); System.out.printf("Area: %.2f\n", r1.getArea()); System.out.printf("Perimeter: %.2f\n", r1.getPerimeter()); System.out.printf("Contains(3, 3)?: %b\n", r1.contains(3, 3)); System.out.printf("Contains(4, 5, 10.5, 3.2)?: %b\n", r1.contains(new MyRectangle2D(4, 5, 10.5, 3.2))); System.out.printf("Overlaps(3, 5, 2.3, 5.4)?: %b\n", r1.overlaps(new MyRectangle2D(3, 5, 2.3, 5.4))); } } 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...