Checkpoint 17.12.1.
Form a statement to get the area of cylinder1βs base. You will not need all the blocks.
classDiagram
class Segment {
-m_start : Point
-m_end : Point
...functions()
}
class Point{
...details_omitted...
}
Segment *-- Point
m_start, m_end, or both to do its work. Here are what some functions might look like:
double Segment::getStartX() const {
return m_start.getX();
}
double Segment::length() const {
return m_start.distanceTo(m_end);
}
classDiagram
class Segment {
-m_start : Point
-m_end : Point
-m_label : string
...functions()
}
class Point{
...details_omitted...
}
Segment *-- Point
Segment *-- string
s1 at run time, there would be two contained points:
classDiagram
class Path {
-m_points : vector<Point>
...functions()
}
classDiagram
class Cylinder {
-m_base : Circle
-m_height : double
...functions()
}
class Circle{
...details_omitted...
}
class Point{
...details_omitted...
}
Cylinder *-- Circle
Circle *-- Point
double Cylinder::getHeight() const {
// height is the Cylinder's direct responsibility
return m_height;
}
double Cylinder::getCircumference() const {
// The base is in charge of the radius and data
// calculated from it. So ask the base for the answer
return m_base.getCircumference();
}
double Cylinder::getX() const {
// Cylinder does not have an x, or even a direct link to the center point
// Ask the base to get the x value for us. It will in turn ask the Point
// it contains.
return m_base.getX();
// Or, ask the base for its center and then ask that Point for its x
//Point center = m_base.getCenter();
//return center.getX();
}
Circle Cylinder::getBase() const {
return m_base;
}
cylinder1.getBase().getCenter().getY(). We first get the base of the Cylinder, which is a Circle. Then we ask that Circle to do getY. This is a place where returning a const reference from Cylinder::getBase() and Circle::getRadius could avoid needless work. The versions we have return copies of the objects. So even though we do not store those copies into variables, it still involves making some new, nameless objects that then get discarded.