Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please I need some help in my answer in this question in the part of << Threedim

ID: 3778393 • Letter: P

Question

Please I need some help in my answer in this question in the part of << ThreedimensionalShape.h>> I need cpp for this header file See answer and give me cpp for ThreedimensionalShape.h
Question is:
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. 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.

Answer is:
test.cpp

#include <iostream> #include <vector>
#include "Circle.h" #include "Square.h" #include "Triangle.h" #include "Cube.h" #include "Sphere.h" #include "Tetrahedron.h"
using namespace std;
int main () { vector< Shape * > shapes( 6 );
Circle circle( 2 ); Square square( 2 ); Triangle triangle( 3, 4, 5 ); Cube cube( 2, 3, 4 ); Sphere sphere( 2 ); Tetrahedron tetrahedron( 2 );    shapes[ 0 ] = &circle; shapes[ 1 ] = &square; shapes[ 2 ] = &triangle; shapes[ 3 ] = &cube; shapes[ 4 ] = &sphere; shapes[ 5 ] = &tetrahedron;
for ( size_t i = 0; i < 6; i++ ) { TwodimensionalShape *ptr1 = dynamic_cast < TwodimensionalShape * > ( shapes[ i ] ); ThreedimensionalShape *ptr2 = dynamic_cast < ThreedimensionalShape * > ( shapes[ i ] );
if ( ptr1 != 0 ) shapes[ i ]->print();
if( ptr2 != 0 ) shapes[ i ]->print(); } return 0; }
Circle.cpp

#include <iostream> #include "Circle.h"
using namespace std;
Circle::Circle( double r ) :TwodimensionalShape(), radius( r ) { }
double Circle::getArea() const { return radius * radius * 3.14; }
void Circle::print() const { TwodimensionalShape::print(); cout << "The area of circle is: " << getArea() << endl; }
Circle.h

#ifndef CIRCLE_H #define CIRCLE_H
#include "TwodimensionalShape.h"
class Circle: public TwodimensionalShape { public: Circle( double = 0 );
virtual double getArea() const; virtual void print() const;    private: double radius; };
#endif // CIRCLE_H
Cube.cpp

#include <iostream> #include "Cube.h"
using namespace std;
Cube::Cube( double w, double l, double h ) :ThreedimensionalShape(), width( w ), length( l ), heigth( h ) {}
double Cube::getArea() const { return 2 * ( width * length + width * heigth + length * heigth ); } double Cube::getVolume() const { return width * length * heigth; }
void Cube::print() const { ThreedimensionalShape::print(); cout << "The area of cube is " << getArea() << endl; cout << "The Volume of cube is " << getVolume() << endl; }
Cube.h

#ifndef CUBE_H #define CUBE_H
#include "ThreedimensionalShape.h"
class Cube: public ThreedimensionalShape { public: Cube( double, double, double );
virtual double getArea() const; virtual double getVolume() const;
virtual void print() const;
private: double width; double length; double heigth; };
#endif // CUBE_H

Shape.cpp
#include "Shape.h" #include <iostream>
using namespace std;
Shape::Shape() {} Shape::~Shape() { cout << "delete class Shape " << endl; }
Shape.h

#ifndef SHAPE_H #define SHAPE_H
class Shape { public: Shape( ); virtual ~Shape();
virtual double getArea() const = 0; virtual void print() const = 0;   
};
#endif // SHAPE_H

Sphere.cpp

#include <iostream> #include "Sphere.h"
using namespace std;
Sphere::Sphere( double r ) :ThreedimensionalShape(), radius( r ) { }
double Sphere::getVolume() const { return 3 * 3.14 * radius * radius * radius / 4; }
double Sphere::getArea() const { return 4 * 3.14 * radius * radius; }
void Sphere::print() const { ThreedimensionalShape::print(); cout << "The area of sphere is " << getArea() << endl; cout << "The volume of sphere is " << getVolume() << endl; }

Sphere.h

#ifndef SPHERE_HN #define SPHERE_HN
#include "ThreedimensionalShape.h"
class Sphere: public ThreedimensionalShape { public: Sphere( double );
virtual double getArea() const; virtual double getVolume() const; virtual void print() const;    private: double radius; };
#endif // TRIANGLE_H

Tetrahedron.cpp

#include <iostream> #include <cmath> #include "Tetrahedron.h"
using namespace std;
Tetrahedron::Tetrahedron( double l ) :ThreedimensionalShape(), length( l ) {    }
double Tetrahedron::getArea() const { return 4 * length * length * sqrt( 3 ) / 4; }
double Tetrahedron::getVolume() const { return length * length * length / 2; }
void Tetrahedron::print() const { ThreedimensionalShape::print(); cout << "The area of tetrahedron is " << getArea() << endl; cout << "The volume of tetrahedron is " << getVolume() << endl; }

Tetrahedron.h

#ifndef TETRAHEDRON_H #define TETRAHEDRON_H
#include "ThreedimensionalShape.h"
class Tetrahedron: public ThreedimensionalShape { public: Tetrahedron( double );
virtual double getArea() const; virtual double getVolume() const;
virtual void print() const; private: double length;
};
#endif // TETRAHEDRON_H
ThreedimensionalShape.h

#ifndef THREEDIMENIALSHAPE_H #define THREEDIMENIALSHAPE_H
#include "Shape.h"
class ThreedimensionalShape: public Shape { public: ThreedimensionalShape();
virtual double getArea() const = 0; virtual void print() const;
virtual double getVolume() const = 0;
};
#endif // THREEDIMENIALSHAPE_H
Triangle.cpp

#include <iostream> #include <cmath> #include "Triangle.h"
using namespace std;
Triangle::Triangle( double l1, double l2, double l3 ) :TwodimensionalShape(), length1( l1 ), length2( l2 ), length3( l3 ) { }
double Triangle::getArea() const { double p = ( length1 + length2 + length3 ) / 2;
return sqrt( p * ( p - length1 ) * ( p - length2 ) * ( p - length3 ) ); }
void Triangle::print() const { TwodimensionalShape::print(); cout << "The area of Triangle is " << getArea() <<endl; }
Triangle.h

#ifndef TRIANGLE_H #define TRIANGLE_H
#include "TwodimensionalShape.h"
class Triangle: public TwodimensionalShape { public: Triangle( double, double , double );
virtual double getArea() const; virtual void print() const;
private: double length1; double length2; double length3; };
#endif // TRIANGLE_H
TwodimensionalShape.cpp

#include <iostream> #include "TwodimensionalShape.h"
using namespace std;
TwodimensionalShape::TwodimensionalShape() :Shape() { } TwodimensionalShape::~TwodimensionalShape() { } void TwodimensionalShape::print() const { cout << " This is a TwodimensionalShape" << endl; }

TwodimensionalShape.h

#ifndef TWODIMENIALSHAPE_H #define TWODIMENIALSHAPE_H
#include "Shape.h"
class TwodimensionalShape: public Shape { public: TwodimensionalShape(); virtual ~TwodimensionalShape();
virtual double getArea() const = 0; virtual void print() const;
};
#endif // TWODIMENSIONALSHAPE_H
Square.cpp

#include <iostream> #include "Square.h"
using namespace std;
Square::Square ( double l ) :TwodimensionalShape(), length( l ) { }
double Square::getArea() const { return length * length; }
void Square::print() const { TwodimensionalShape::print(); cout << "The area of square is: " << getArea() << endl; }

Square.h

#ifndef SQUARE_H #define SQUARE_H
#include "TwodimensionalShape.h"
class Square: public TwodimensionalShape { public: Square( double );
virtual double getArea() const; virtual void print() const;
private: double length;    };
#endif // SQUARE_H

TwoDimensionalshape Circle Square Shapes Three Dimensionalshape Sphere Cube

Explanation / Answer

// ThreeDimensionalShape.cpp: implementation of the ThreeDimensionalShape class

#include "ThreeDimensionalShape.h"   

#include <iostream.h>    

ThreeDimensionalShape::ThreeDimensionalShape(float h)   

{   

    height=h>0?h:0;   

}   

void ThreeDimensionalShape::print() const

{   

    cout<<""This is a Three dimentional shape"<<endl;   

}

ThreeDimensionalShape::~ThreeDimensionalShape()   

{ }