14614 - Stone Collection   

Description

Tomorin likes to collect stones, especially those with a unique shape. She has a collection box, with all the stones in sphere, cube, cuboid, and cylinder shapes inside. Now, she wants to find the stone with the largest and the smallest surface area in her collection, as well as the total surface area of all the stones in the collection. Can you help her?

image

Here are the formulas for the surface area of each shape:

  • Sphere: \(4 \pi r^2\)
    • \(r\) is the radius of the sphere
    • \(\pi\) is normally a constant. However, in the world of BanG Dream!, each stone has its own value of \(\pi\). So, you need to use the value of \(\pi\) given in the input.
  • Cube: \(6 a^2\)
    • \(a\) is the length of the side of the cube
  • Cuboid: \(2 (ab + ac + bc)\)
    • \(a\), \(b\), and \(c\) are the lengths of the sides of the cuboid
  • Cylinder: \(2 \pi r^2 + 2 \pi rh\)
    • \(r\) is the radius of the base of the cylinder
    • \(h\) is the height of the cylinder

We represent the stones as a hierarchy of classes. The base class is Stone, which has a method getSurfaceArea() that returns the surface area of the stone. The derived classes are SphereStone, CubeStone, CuboidStone, and CylinderStone, which calculate the surface area of their respective shapes on construction. Additionally, a CollectionBox class is used to keep track of the largest and smallest surface areas of the stones in the collection.

You need to implement the following methods:

  • The constructor of SphereStone, CubeStone, CuboidStone, and CylinderStone classes, which should take the parameters needed to calculate the surface area of the respective shapes and store the surface area in the surfaceArea variable.
  • The constructor of the CollectionBox class, which should initialize the internal variables to keep track of the minimum, maximum, and total surface area of the stones in the collection.
  • The addStone() method of the CollectionBox class, which should take a Stone object as a parameter and add it to the collection. This method should also update the minimum, maximum, and total surface area of the stones in the collection.

Notes

  • Remember to do some basic check. If the input is illegal (e.g. r < 0, pi < 0 …..) then the volume should be 0.
  • Be aware that the calculation of the surface area should be done in double precision. e.g. 4/3=1 in integer, and you should use 4.0/3.0 in double instead.
  • Note that Cube inherited Cuboid not Shape3D.

Input

This is a partial judge problem. You don’t need to implement the input function.

The input consists of multiple lines, each representing a stone in the collection. For each line, the first string is the type of stone, followed by the parameters needed to calculate the surface area. The types of stones are:

  • Sphere: Sphere r pi
  • Cube: Cube a
  • Cuboid: Cuboid a b c
  • Cylinder: Cylinder r h pi

Output

This is a partial judge problem. You don’t need to implement the output function.

You should output the minimum surface area, maximum surface area, and the total surface area of all the stones in the collection. You should round the output to 2 decimal places. The output should be in the following format:

Minimum Surface Area: <min_surface_area>
Maximum Surface Area: <max_surface_area>
Total Surface Area:   <total_surface_area>

Sample Input  Download

Sample Output  Download

Partial Judge Code

14614.cpp

Partial Judge Header

14614.h

Tags




Discuss