Loading...
Searching...
No Matches
geometry::Square Class Reference

A square — a special case of Rectangle where width equals height. More...

#include <shapes.hpp>

Inheritance diagram for geometry::Square:
[legend]
Collaboration diagram for geometry::Square:
[legend]

Public Member Functions

 Square (double side)
 Construct a square with the given side length.
 
std::string name () const override
 Return the human-readable name of the shape.
 
double side () const
 Get the side length.
 
- Public Member Functions inherited from geometry::Rectangle
 Rectangle (double width, double height)
 Construct a rectangle.
 
double area () const override
 Compute the area of the shape.
 
double height () const
 Get the height.
 
double perimeter () const override
 Compute the perimeter of the shape.
 
double width () const
 Get the width.
 
- Public Member Functions inherited from geometry::Shape
virtual ~Shape ()=default
 Virtual destructor for safe polymorphic deletion.
 
std::string describe () const
 Pretty-print shape information.
 

Additional Inherited Members

- Static Public Member Functions inherited from geometry::Shape
static int instance_count ()
 Get the total count of Shape instances created.
 
- Protected Member Functions inherited from geometry::Shape
 Shape ()
 Increment the instance counter.
 
- Protected Attributes inherited from geometry::Rectangle
double height_
 The rectangle's height.
 
double width_
 The rectangle's width.
 

Detailed Description

A square — a special case of Rectangle where width equals height.

\[ A = s^2, \qquad P = 4s \]

Note
This class inherits from Rectangle and overrides name(). It demonstrates a deeper inheritance chain for the class diagram.

Definition at line 177 of file shapes.hpp.

Constructor & Destructor Documentation

◆ Square()

geometry::Square::Square ( double side)
inlineexplicit

Construct a square with the given side length.

Parameters
sideThe side length (must be positive).

Definition at line 183 of file shapes.hpp.

183: Rectangle(side, side) {}
Rectangle(double width, double height)
Construct a rectangle.
Definition shapes.hpp:145
double side() const
Get the side length.
Definition shapes.hpp:188

References geometry::Rectangle::Rectangle(), and side().

Member Function Documentation

◆ name()

std::string geometry::Square::name ( ) const
inlinenodiscardoverridevirtual

Return the human-readable name of the shape.

Returns
A string like "Circle", "Rectangle", etc.

Reimplemented from geometry::Rectangle.

Definition at line 185 of file shapes.hpp.

185{ return "Square"; }

◆ side()

double geometry::Square::side ( ) const
inlinenodiscard

Get the side length.

Definition at line 188 of file shapes.hpp.

188{ return width_; }
double width_
The rectangle's width.
Definition shapes.hpp:163

References geometry::Rectangle::width_.

Referenced by Square().


The documentation for this class was generated from the following file: