-
Notifications
You must be signed in to change notification settings - Fork 1
examples cpp docs api
This page demonstrates how to use breathe to document C++ code with yardang.
A class for performing basic arithmetic operations.
The Calculator class provides methods for addition, subtraction, multiplication, and division. It also maintains a history of operations performed.
Example usage:
[calc::Calculator](#calculatorclasscalc_1_1_calculator) [calc](api#calculatornamespacecalc); double result = [calc](api#calculatornamespacecalc).add(5.0, 3.0); std::cout << "Result: " << result << std::endl;
Note
This is a thread-safe implementation.
Subclassed by calc::ScientificCalculator
Default constructor.
Initializes an empty calculator with no operation history.
Destructor.
Add two numbers.
Tip
Parameters:
- a – The first operand.
- b – The second operand.
Returns: The sum of a and b.
Subtract two numbers.
Tip
Parameters:
- a – The minuend.
- b – The subtrahend.
Returns: The difference (a - b).
Multiply two numbers.
Tip
Parameters:
- a – The first factor.
- b – The second factor.
Returns: The product of a and b.
Divide two numbers.
Tip
Warning
Division by zero will throw an exception.
Parameters:
- a – The dividend.
- b – The divisor.
Throws: – if b is zero.
Returns: The quotient (a / b).
std::vector<OperationResult> getHistory() const
Get the history of all operations.
Returns: A vector containing all operation results.
Clear the operation history.
Get the number of operations performed.
Returns: The count of operations in history.
void recordOperation(const OperationResult &result)
Record an operation in the history.
- **Parameters:*- result: The result to record.
class ScientificCalculator : public calc::Calculator
An extended calculator with scientific functions.
This class inherits from Calculator and adds advanced mathematical operations like power and square root.
Calculate the power of a number.
Parameters:
- base – The base number.
- exponent – The exponent.
Returns: base raised to the power of exponent.
Calculate the square root of a number.
- **Parameters:*- value: The number to find the square root of.
Throws: – if value is negative.
Returns: The square root of value.
enum class calc::Operation
Enumeration of supported arithmetic operations.
Values:
Addition operation.
Subtraction operation.
Multiplication operation.
Division operation.
Structure to hold the result of a calculation.
The calculated value.
Operation operation
The operation that was performed.
std::string description
Human-readable description of the operation.
A helper function to format a number as a string.
Parameters:
- value – The number to format.
- precision – The number of decimal places.
Returns: A formatted string representation.
Maximum number of operations to store in history.
typedef std::vector<OperationResult> calc::HistoryList
Type alias for the operation history container.