Class Dividend

Class Documentation

class Dividend

Represents a dividend with both fixed and proportional components.

The Dividend class models a dividend with a fixed amount and a proportional yield. It supports common arithmetic operations, equality checks, and formatting for output.

Public Functions

inline Dividend()

Default constructor that initializes the fixed and proportional components to zero.

inline Dividend(double fixed)

Constructor that initializes the fixed component and sets the proportional component to zero.

Parameters:

fixed – The fixed component of the dividend.

inline Dividend(double fixed, double yield)

Constructor that initializes both fixed and proportional components of the dividend.

Parameters:
  • fixed – The fixed component of the dividend.

  • yield – The proportional yield of the dividend.

inline bool operator==(const Dividend &other) const

Equality operator to compare two Dividend objects.

Parameters:

other – The Dividend object to compare against.

Returns:

True if both the fixed and proportional components are equal, otherwise false.

inline bool operator!=(const Dividend &other) const

Inequality operator to compare two Dividend objects.

Parameters:

other – The Dividend object to compare against.

Returns:

True if the Dividend objects are not equal, otherwise false.

inline bool equal(const Dividend &other, double epsilon) const

Checks if two Dividend objects are equal within a given epsilon tolerance.

Parameters:
  • other – The Dividend object to compare against.

  • epsilon – The tolerance for equality comparison.

Returns:

True if the two Dividend objects are equal within the given epsilon, otherwise false.

inline Dividend &operator+=(const Dividend &rhs)

Addition assignment operator to add another Dividend to the current object.

Parameters:

rhs – The Dividend object to add.

Returns:

A reference to the updated Dividend object.

inline double get_fixed() const

Gets the fixed component of the dividend.

Returns:

The fixed component of the dividend.

inline void set_fixed(double fixed)

Sets the fixed component of the dividend.

Parameters:

fixed – The fixed component to set.

inline double get_proportional() const

Gets the proportional component of the dividend.

Returns:

The proportional component of the dividend.

inline void set_proportional(double proportional)

Sets the proportional component of the dividend.

Parameters:

proportional – The proportional component to set.

Public Static Functions

static inline std::string get_header()

Returns the header string for the Dividend class, representing its components.

Returns:

A string with column headers for fixed and proportional components: “fixed,proportional”.

Friends

inline friend Dividend operator+(Dividend lhs, const Dividend &rhs)

Addition operator to add two Dividend objects and return a new one.

Parameters:
  • lhs – The left-hand side Dividend object.

  • rhs – The right-hand side Dividend object.

Returns:

A new Dividend object that is the sum of lhs and rhs.

friend std::ostream &operator<<(std::ostream &out, const Dividend &obj)

Stream insertion operator for printing a Dividend object.

Parameters:
  • out – The output stream to insert the Dividend object into.

  • obj – The Dividend object to print.

Returns:

The output stream with the Dividend object printed.