|
Steppable 0.0.1
A CAS project written from scratch in C++
|
Acts as a fraction in math. It can be added, subtracted, multiplied and divided. More...
#include <fraction.hpp>
Public Member Functions | |
| Fraction (const std::string &top="1", const std::string &bottom="1") | |
| Initializes a fraction with a specified top component and bottom component. | |
| Fraction (const Number &number) | |
| Initialized a fraction from a number. | |
| Fraction () | |
| Initializes a fraction with no top component and bottom component specified. By default, this fraction equals to 1. | |
| std::string | present (bool inLine=true) |
| Returns the fraction as a string. The string is formatted as "top/bottom", and it will automatically simplify the fraction. | |
| std::array< std::string, 2 > | asArray () const |
| Returns the fraction as an array of its top and bottom components. | |
| Fraction | operator+ (const Fraction &rhs) const |
| Adds two fractions together. This function does it by doing a simple fraction addition and returns the sum. | |
| Fraction | operator+ () const |
| Unary plus operator. | |
| Fraction | operator- (const Fraction &rhs) const |
| Subtracts a fraction from another fraction. This function does it by doing a simple fraction subtraction and returns the difference. | |
| Fraction | operator- () const |
| Unary minus operator. | |
| Fraction | operator* (const Fraction &rhs) const |
| Multiplies two fractions together. This function does it by doing a simple fraction multiplication and returns the sum. | |
| Fraction | operator/ (const Fraction &rhs) const |
| Divides a fraction by abother fraction. This function does it by doing a simple fraction division (multiply by inverse) and returns the sum. | |
| Fraction | operator^ (const Number &rhs) |
| Raises the fraction to a power. | |
| Fraction & | operator+= (const Fraction &rhs) |
| Adds two fractions together and stores the result in the current one. This function does it by doing a simple fraction addition and returns the sum. | |
| Fraction & | operator-= (const Fraction &rhs) |
| Subtracts a fraction from another fraction and stores the result in the current one. This function does it by doing a simple fraction subtraction and returns the difference. | |
| Fraction & | operator*= (const Fraction &rhs) |
| Multiplies two fractions together and stores the result in the current one. This function does it by doing a simple fraction multiplication and returns the sum. | |
| Fraction & | operator/= (const Fraction &rhs) |
| Divides a fraction by abother fraction and stores the result in the current one. This function does it by doing a simple fraction division (multiply by inverse) and returns the sum. | |
| Fraction & | operator^= (const Number &rhs) |
| Raises the fraction to a power and stores the result in the current one. | |
| bool | operator== (const Fraction &rhs) const |
| Compares two numbers for equality. | |
| bool | operator!= (const Fraction &rhs) const |
| bool | operator< (const Fraction &rhs) const |
| Compares two numbers for greater than. | |
| bool | operator> (const Fraction &rhs) const |
| Compare two fractions for less than. | |
| bool | operator<= (const Fraction &rhs) const |
| Compare two fractions for less or equal than. | |
| bool | operator>= (const Fraction &rhs) const |
| Compare two fractions for greater or equal than. | |
| void | reciprocal () |
| Converts a fraction to its reciprocal. This function converts the fraction to its reciprocal. | |
| void | simplify () |
| Simplifies a fraction. This function simplifies the fraction by dividing the top and bottom components by their greatest common divisor. | |
Private Attributes | |
| std::string | top |
| The numerator. (Top component) | |
| std::string | bottom |
| The denominator. (Bottom component) | |
Acts as a fraction in math. It can be added, subtracted, multiplied and divided.
|
explicit |
Initializes a fraction with a specified top component and bottom component.
| ZeroDenominatorException | when the bottom component is zero. |
|
explicit |
Initialized a fraction from a number.
| number | The number to convert to a fraction. |
| steppable::Fraction::Fraction | ( | ) |
Initializes a fraction with no top component and bottom component specified. By default, this fraction equals to 1.
|
nodiscard |
Returns the fraction as an array of its top and bottom components.
| bool steppable::Fraction::operator!= | ( | const Fraction & | rhs | ) | const |
@briefCompares two numbers for inequality.
| rhs | Another fraction. |
Multiplies two fractions together. This function does it by doing a simple fraction multiplication and returns the sum.
| [in] | rhs | The other fraction. |
Multiplies two fractions together and stores the result in the current one. This function does it by doing a simple fraction multiplication and returns the sum.
| [in] | rhs | The other fraction. |
| Fraction steppable::Fraction::operator+ | ( | ) | const |
Unary plus operator.
Does nothing. Simply returns a new instance of the fraction.
Adds two fractions together. This function does it by doing a simple fraction addition and returns the sum.
| [in] | rhs | The other fraction. |
Adds two fractions together and stores the result in the current one. This function does it by doing a simple fraction addition and returns the sum.
| [in] | rhs | The other fraction. |
| Fraction steppable::Fraction::operator- | ( | ) | const |
Unary minus operator.
Converts the fraction to itself with the opposite sign. Returns a new instance of the fraction.
Subtracts a fraction from another fraction. This function does it by doing a simple fraction subtraction and returns the difference.
| [in] | rhs | The other fraction. |
Subtracts a fraction from another fraction and stores the result in the current one. This function does it by doing a simple fraction subtraction and returns the difference.
| [in] | rhs | The other fraction. |
Divides a fraction by abother fraction. This function does it by doing a simple fraction division (multiply by inverse) and returns the sum.
| [in] | rhs | The other fraction. |
Divides a fraction by abother fraction and stores the result in the current one. This function does it by doing a simple fraction division (multiply by inverse) and returns the sum.
| [in] | rhs | The other fraction. |
| bool steppable::Fraction::operator< | ( | const Fraction & | rhs | ) | const |
Compares two numbers for greater than.
| rhs | Another fraction. |
| bool steppable::Fraction::operator<= | ( | const Fraction & | rhs | ) | const |
Compare two fractions for less or equal than.
| rhs | Another fraction. |
| bool steppable::Fraction::operator== | ( | const Fraction & | rhs | ) | const |
Compares two numbers for equality.
| rhs | Another fraction. |
| bool steppable::Fraction::operator> | ( | const Fraction & | rhs | ) | const |
Compare two fractions for less than.
| rhs | Another fraction. |
| bool steppable::Fraction::operator>= | ( | const Fraction & | rhs | ) | const |
Compare two fractions for greater or equal than.
| rhs | Another fraction. |
Raises the fraction to a power.
| rhs | Any number. |
Raises the fraction to a power and stores the result in the current one.
| rhs | Any number. |
| std::string steppable::Fraction::present | ( | bool | inLine = true | ) |
Returns the fraction as a string. The string is formatted as "top/bottom", and it will automatically simplify the fraction.
| inLine | Whether to present the fraction in a single line. |
| void steppable::Fraction::reciprocal | ( | ) |
Converts a fraction to its reciprocal. This function converts the fraction to its reciprocal.
| void steppable::Fraction::simplify | ( | ) |
Simplifies a fraction. This function simplifies the fraction by dividing the top and bottom components by their greatest common divisor.
|
private |
The denominator. (Bottom component)
|
private |
The numerator. (Top component)