# | Problem | Pass Rate (passed user / total user) |
---|---|---|
14614 | Stone Collection |
|
14622 | Naming Convention |
|
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?
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
, andCylinderStone
classes, which should take the parameters needed to calculate the surface area of the respective shapes and store the surface area in thesurfaceArea
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 theCollectionBox
class, which should take aStone
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 use4.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.cppPartial Judge Header
14614.hTags
Discuss
Description
(This is a rework of 13891 - Polymorphic naming convention conversion.)
NOTE: You are required to implement both the SnakeCase
class and the CamelCase
class.
In computer programming, a naming convention is a set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation, with the goal of enhancing program readability.
For the naming of identifiers, a common recommendation is “Use meaningful identifiers.” A single word may not be as meaningful, or specific, as multiple words. Consequently, some naming conventions specify rules for the treatment of “compound” identifiers containing more than one word. Three most popular naming conventions are explained below:
- kebab-case is a naming convention where words are separated by hyphens (
-
). For example,my-variable-name
ormy-function-name
are examples of the kebab case. - snake_case is a naming convention where words are separated by underscores (
_
). For example,my_variable_name
ormy_function_name
are examples of the snake case. - CamelCase is a naming convention where the first letter of each word is capitalized and there are no separators. For example,
MyVariableName
orMyFunctionName
are examples of the camel case.
(From Wikipedia, the free encyclopedia, https://en.wikipedia.org/wiki/Naming_convention(programming))_
In this problem, we consider an Integrated Development Environment (IDE) that supports naming convention conversion. We assume that the kebab case is the default naming convention. The IDE can convert to a different naming convention according to a programmer’s preference. The IDE can also revert back to the default naming convention for the integration among multiple program files.
We first design the abstract base class ‘Case’ as an interface, which contains two pure virtual member functions:
convert
: convert to the desired naming convention;revert
: revert back to the default naming convention, i.e., the kebab case.
You are asked to implement the two derived classes SnakeCase
and CamelCase
by overriding the two virtual functions, convert
and revert
.
Note: It is highly recommended to practice std::stringstream
in this problem. Here is a simple code that shows you how to use stringstream:
#include <iostream>
#include <sstream> // header file for stringstream
using namespace std;
int main(){
string s;
stringstream ss;
getline(cin, s);
ss << s;
while(!ss.eof()){
string t;
getline(ss, t, ' ');
cout << t << "\n";
}
return 0;
}
/*
- Sample Input
This is a sentence for testing this code.
- Sample Output
This
is
a
sentence
for
testing
this
code.
*/
For more information, please refer to the C++ reference in I’m reference
Input
A line contains only lowercase letters and hyphens.
Output
The Snake case and the Camel case for the input string. Please refer to the sample output for details.