#include <iostream>
#include <cstring>
#include <cmath>
usingnamespace std;
#define PI 3.14159
class values{
public:
double sideA; //a= length of side
double sideBR; //b = breadth
double sideB; //b = base
double sideH; //h = height
double sideVH; //vh = vertical height
double sideR; //r = radius of a circle
};
class twoDobjects: public values{ //some values that are obtained via Pythagora's Theorem included
public:
double sideC () // C is in fact a hypotenuse of a triangle
{
return sqrt ((sideR*sideR)+(sideVH*sideVH));
}
double squarearea ()
{
return sideA*sideA;
}
double trianglearea ()
{
return (sideB*sideVH)/2;
}
double circlearea ()
{
return PI*(sideR*sideR);
}
};
class threeDobjects: public twoDobjects{
public:
double cubearea ()
{
return squarearea()*6;
}
double conearea ()
{
return circlearea () + PI * sideR * sideC ();
}
};
//
int main ()
{
twoDobjects twoD;
threeDobjects threeD;
int a;
cout << "Insert the side of the " <<endl;
cin>>a;
twoD.sideA=a;
cout << "The area of the cube is: " << twoD.squarearea ()<<endl;
cout << " The volume of the cube: " << threeD.cubearea () <<endl;
system ("pause");
return 0;
}
i need to make a program with 3 classes, and need to find the volume and the area of a Cube, Pyramid and of a Cone. me and my friend cannot move any further... because the third class wont work ... :( anyone can help ???
actually there should be 2 classes only
one for 2d objects
and one for 3d
the class for 3d objects should use values obtained from the class that calculates 2d objects in order to calculate things such as area of a cube or etc
enum SHAPE { SQUARE, TRIANGLE, CIRCLE, PYRAMID, CONE, CUBE };
class Shape2D
{
private:
int width;
int height;
// it's probably better to create a derived class for each shape
// but since you're limited to 2 classes you could do it this way.
SHAPE typeOfShape;
public:
Shape2D(SHAPE initShapeType); // constructor
// add methods you want like computeArea() or something
};
class Shape3D : Shape2D
{
private:
int thickness; // new attribute for all 3D objects
public:
// add methods you want computeVolume() etc.
};