Description
Implement six existed classes Plane, Solid, Triangle, Rectangle, Tetrahedron, Cuboid.
Plane:
Protected Variables:
- base(int) as the length of plane’s base.
- height(int) as the length of plane’s height.
note that 0 <= base, height <= 100.
Protected Methods:
- double calculateArea() - Return plane’s area(base * height).
Solid: (derived from Plane)
Protected Variables:
- base(derived from Plane) as the length of bottom shape’s base.
- height(derived from Plane) as the length of bottom shape’s height.
- height(int) as the length of solid’s height.
note that 0 <= height <= 100.
Protected Methods:
- double calculateVolume() - Return solid’s volume(base area * height).
Triangle: (derived from Plane)
Protected Variables:
- base(derived from Plane) as the length of triangle’s base.
- height(derived from Plane) as the length of triangle’s height.
Constructors:
- The parameterized constructor Triangle(int b, int h) should initialize triangle’s base, height to b, h.
Public Methods:
- void set(int i) – Should set both triangle’s base and height to i.
- void set(int b, int h) – Should set both triangle’s base and height to b, h.
- void info() – Should print triangle’s information as below format.
[Triangle] Base: base, Height: height, Area: area(scaled to 2nd decimal point)
For example: [Triangle] Base: 20, Height: 30, Area: 300.00
Protected Methods:
- double calculateArea() - Return rectangle's area(base area / 2).
Rectangle: (derived from Plane)
Protected Variables:
- base(derived from Plane) as the length of rectangle’s base.
- height(derived from Plane) as the length of rectangle’s height.
Constructors:
- The parameterized constructor Rectangle(int b, int h) should initialize rectangle's base, height to b, h.
Public Methods:
- void set(int i) – Should set both rectangle's base and height to i.
- void set(int b, int h) – Should set both rectangle's base and height to b, h.
- void info() – Should print rectangle’s information as below format.
[Rectangle] Base: base, Height: height, Area: area(scaled to 2nd decimal point)
For example: [Rectangle] Base: 20, Height: 30, Area: 600.00
Protected Methods:
- double calculateArea() - Return rectangle's area(base area).
Tetrahedron(三角體): (derived from Solid)
Protected Variables:
- base(derived from Plane) as the base of tetrahedron’s bottom.
- height(derived from Plane) as the height of tetrahedron’s bottom.
- height(derived from Solid) as the height of tetrahedron.
Constructors:
- The parameterized constructor Tetrahedron(int b, int h, int k) should initialize tetrahedron’s bottom base to b, tetrahedron’s bottom height to h, tetrahedron’s height to k.
Public Methods:
- void set(int i) – Should set all tetrahedron’s bottom base, tetrahedron’s bottom height, and tetrahedron’s height to i.
- void set(int b, int h, int k) – Should set tetrahedron’s bottom base to b, tetrahedron’s bottom height to h, and tetrahedron’s height to k..
- void info() – Should print tetrahedron’s information as below format.
[Tetrahedron] Plane-base: base, Plane-height: height(derived from Plane), Height: height(derived from Plane), Volume: volume(scaled to 2nd decimal point)
For example: [Tetrahedron] Plane-base: 20, Plane-height: 30, Height: 40, Volume: 6000.00
Protected Methods:
- double calculateVolume() - Return tetrahedron’s volume( 1/6 * base solid volume )

Cuboid(長方體): (derived from Solid)
Protected Variables:
- base(derived from Plane) as the base of cuboid‘s bottom.
- height(derived from Plane) as the height of cuboid’s bottom.
- height(derived from Solid) as the height of cuboid.
Constructors:
- The parameterized constructor Cuboid(int b, int h, int k) should initialize cuboid’s bottom base to b, tetr cuboid’s ahedron’s bottom height to h, cuboid’s height to k.
Public Methods:
- void set(int i) – Should set all cuboid’s bottom base, cuboid’s bottom height, and cuboid’s height to i.
- void set(int b, int h, int k) – Should set cuboid’s bottom base to b, cuboid’s bottom height to h, and cuboid’s height to k..
- void info() – Should print cuboid’s information as below format.
[Cuboid] Plane-base: base, Plane-height: height(derived from Plane), Height: height(derived from Plane), Volume: volume(scaled to 2nd decimal point)
For example: [Cuboid] Plane-base: 20, Plane-height: 30, Height: 40, Volume: 24000.00
Protected Methods:
- double calculateVolume() - Return cuboid’s volume(base solid volume)
Hints of function.cpp is commented in function.h. Download and check it out.
Input
No need to handle input. (Input would be number 1~5 to represent the index of test-case)
Output
Depend on test case show in main.cpp.
Partial Judge Code
13038.cpp
Partial Judge Header
13038.h
Tags