This project implements a powerful C++ calculator that handles rational numbers (fractions) of virtually arbitrary size. It uses string-based arithmetic to manage numerators and denominators that far exceed the limits of standard C++ data types, ensuring lossless precision for complex calculations.
The library provides a comprehensive set of mathematical tools for handling large rational numbers:
| Category | Functions | Description |
|---|---|---|
| Basic Arithmetic |
+, -, *, /
|
Full precision calculation for addition, subtraction, multiplication, and division. |
| Logical & Bitwise |
AND, OR, NOT, XOR, SHIFT
|
Bitwise logic and shifts (left/right) on large positive integers, supporting decimal and hexadecimal input. |
| Trigonometry |
sin, cos, tan, csc, sec, cot
|
Calculates trigonometric values for an angle in radians. |
| Advanced Math |
log, ln, exp
|
Supports natural logarithm, arbitrary base logarithm, and arbitrary base exponentiation ( |
| Unit Conversion | convert_units |
Built-in conversion factors for Length, Mass, Volume, Temperature, Angle, Force, Pressure, and Density. |
| History & Queue |
HistoryStack, OperationQueue
|
Tracks recent results and allows queuing multiple arithmetic operations for batch processing. |
You need a C++ compiler that supports the C++11 standard or newer (e.g., GCC or Clang).
Use this streamlined command to compile all source files and create a single executable named run:
g++ big_rational.cpp main.cpp -o rung++: The C++ compiler.big_rational.cppandmain.cpp: The source files to be compiled.-o run: Specifies the output filename for the executable asrun
Run the compiled executable to launch the interactive calculator menu:
./run| File | Primary Role & Core Components Used | Key Functions Implemented |
|---|---|---|
main.cpp |
User Interface & Menu Handler | * main(): Manages the main menu loop and directs program flow based on user input. * display_main_menu(): Presents the top-level menu options. * Calls various handle_..._menu and perform_... functions defined in the library. |
big_rational.h |
Definitions & Declarations | * struct BigRational: Defines the core data structure (numerator, denominator, sign). * Declares all helper functions for string-based arithmetic (add_strings, gcd_strings, etc.). * Declares structures for calculation history and operation queue. |
big_rational.cpp |
Core Logic & Engine | * Big Integer Arithmetic: Implements robust, string-based functions for addition, subtraction, multiplication, division, and modulo of large integers. * Rational Operations: Implements addition_rational, division_rational, etc., using the Big Integer helpers and normalize_rational for simplification. * Advanced Math: Contains the logic for unit conversion, as well as the high-precision implementations for trigonometry and log/exp functions. * I/O Helpers: Includes logic for converting between fractions and decimal strings (to_decimal, print_rational). |
| Data Structure | Purpose |
|---|---|
BigRational |
Represents a number as std::string for arbitrary size. |
stack<HistoryEntry> |
Stores the sequence of executed calculations, allowing users to review and reuse the last result. |
queue<OperationQueueEntry> |
Holds pending arithmetic tasks, enabling batch processing outside the main calculation flow. |
TO ADD YOUR FEATURES: --FORK THE REPOSITORY --MAKE CHANGES ACCORDING TO YOUR WORKING
🚀 Conclusion
The BiG-RATIONAL-CALCULATOR project successfully demonstrates how C++ can be used to bypass native type limits, providing a powerful, precise, and flexible mathematical tool. Whether you're dealing with immense financial figures, complex engineering ratios, or need guaranteed accuracy beyond standard floating-point precision, this library offers a robust solution built on fundamental string arithmetic and robust rational number handling. It's an excellent foundation for any application requiring high-precision computation.
HAPPY CODING