I am writing a Cube class which I have to calculate volume also. The class can have a user input of FLOAT length, width and height in between minimum 1 to maximum 45.00. Otherwise if user inputs any other numbers its all sides would be 1.
so it will be like
#define LIMIT_UNDER 1
#define LIMIT_UPPER 45.00
class Cube {
float height;
float width;
float length;
public:
// Write setter getters here
// default constructor
Cube() {
// default constructor puts default values
height = width = length = LIMIT_UNDER;
Cube(float cHeight, float cWidth, float cLength) {
height = cHeight;
width = cWidth;
length = cLength;
}
float getVolume() {
return height * width * length;
}
};
int main() {
// Default constructor called
Cube cube;
// Parametized called
Cube cube2(2.00f, 2.57f, 5.40f);
// Show volume to 2
// decimal places as 45.00
// is limit that has two decimal places
cout << getVolume() << fixed << setPrecision(2);
)
My question is about should I use all floats (5.40f etc) to two decimal places and the calculations? As I did in main using setPrecision function
Thanks please help