Mixed nuts, especially peanuts, has always been Anya's favorite snack. They come in various shapes and sizes: cubes, cuboids, spheres, cones, and cylinders, each with their own unique taste and texture.
However, Anya got poor grades in her math class, and she struggles to acquire the Stella Stars needed for Loid's secret mission -- to get closer to Donovan Desmond and uncover his scheme.
To help Anya on her schoolwork, Loid decided to teach her the basics of geometry with the shapes of mixed nuts. Given several nuts of different shapes and sizes, Loid wants Anya to calculate total volume of the nuts. Since Anya has the ability to read other people's minds, she can easily read the volume formula for each shape straight from Loid's mind. However, she is not familiar with the calculations, so she needs your help to build a program that can calculate the volume of the nuts.
The volume of a nut can be calculated using the following formulas:
Given a base class Nut
, implement the derived classes CubeNut
, CuboidNut
, SphereNut
, ConeNut
, and CylinderNut
that represent the shapes of mixed nuts. You should use setVolume
to set the corresponding volume of each nut on construction.
4/3=1
is of type int
.CubeNut
inherits from CuboidNut
instead of Nut
.oj::Nut::PI
as your $\pi$ in the calculation.This is a partial judge problem, input and output are handled by main.cpp
.
For each line of input, you will be given a string shape
, followed by the corresponding parameters for the shape. The parameters are separated by a single space, and the order of the parameters is as follows:
You should do some basic check: if the input is illegal (e.g. length < 0), then the volume should be 0. Also, you need to consider the scenario like Cuboid -1 -2 3
, where volume would be 0 instead of 6.
double
.This is a partial judge problem, input and output are handled by main.cpp
.
Output the total volume of the nuts, rounded to 4 decimal places.