C++
Implement the following Shape class.
1. TwoDimensionalShape class
provide the function getArea(), which calculate the area of 2 dimensional figure.
2. ThreeDimensionalShape class
provide the function getArea(), which calculate the area of 3 dimensional figure.
provide the function getVolume(), which calculate the volume of 3 dimensional figure.
3. make a program that use Vector of Shape class pointer, which indicate each specific(derived) class object.
4. program should print the object indicated by the pointer.
Also, you should make a loop (ex) for loop) that handles every object.
in that loop, decide the dimension of shape. (if the figure is TwoDimensionalShape or ThreeDimensionalShape)
5. print volume if the figure is TwoDimensionalShape.
6. print area if the figure is ThreeDimensionalShape.
C++
Implement the following Shape class.
1. TwoDimensionalShape class
provide the function getArea(), which calculate the area of 2 dimensional figure.
2. ThreeDimensionalShape class
provide the function getArea(), which calculate the area of 3 dimensional figure.
provide the function getVolume(), which calculate the volume of 3 dimensional figure.
3. make a program that use Vector of Shape class pointer, which indicate each specific(derived) class object.
4. program should print the object indicated by the pointer.
Also, you should make a loop (ex) for loop) that handles every object.
in that loop, decide the dimension of shape. (if the figure is TwoDimensionalShape or ThreeDimensionalShape)
5. print volume if the figure is TwoDimensionalShape.
6. print area if the figure is ThreeDimensionalShape.
Two DimensionalShape Cirde Square Shape Three Dimensional Shape Sphere Cube
package main;
public abstract class TwoDimensionalShape extends Shape {
private double Dimension1, Dimension2;
public TwoDimensionalShape( double x, double y, double dime1, double dime2 ) {
super(x, y);
Dimension1 = dime1;
Dimension2 = dime2; }
public void setDimension1(double dime1) {
this.Dimension1 = dime1; }
public double getDimension1() {
return Dimension1; }
public void setDimension2(double dime2) {
this.Dimension2 = dime2; }
public double getDimension2() {
return Dimension2;}
public abstract double getArea();
}
package main;
public abstract class ThreeDimensionalShape extends Shape{
private double Dimension1, Dimension2, Dimension3;
public ThreeDimensionalShape(double x, double y, double dime1, double dime2, double dime3 ){
super( x, y );
Dimension1 = dime1;
Dimension2 = dime2;
Dimension3 = dime3; }
public void setDimension3(double dime3) {
this.Dimension2 = dime3; }
public double getDimension3() {
return Dimension3;}
public abstract double getArea();
public abstract double getVolume();
}