Exercise Write a simple class called Cube. The object should calculate the total area and the volume based on the side measurement. If the program supplies a side equal or lower than 0, reset the side to 1. Create an empty constructor and an empty destructor.
Implement the object in different files.
Header File: cube.h
#ifndef CUBE_H#define CUBE_Hclass Cube{public: Cube(); ~Cube(); void setSide(double s); double getSide(); double Area(); double Volume(); void Properties();private: double Side;};#endif
Source File cube.cpp
#include
Main File: Exo.cpp
#include "cube.h"void main(){ Cube cube; cube.setSide(-12.55); cube.Properties(); Cube de; de.setSide(28.15); de.Properties();}
Here is an example of the result:
Characteristics of this cubeSide = 1Area = 6Volume = 1Characteristics of this cubeSide = 28.15Area = 4754.53Volume = 22306.7
No comments:
Post a Comment