5.1 KiB
5.1 KiB
<<<<<<< HEAD
ScientificCalculator
A feature-rich scientific calculator implemented in C++ that provides advanced mathematical operations and a user-friendly interface.
Features
- Basic Arithmetic Operations: Addition, subtraction, multiplication, and division
- Advanced Mathematical Functions:
- Trigonometric functions (sin, cos, tan)
- Inverse trigonometric functions (asin, acos, atan)
- Logarithmic functions (log, log10)
- Exponential functions (exp, pow)
- Square root and power operations
- Memory Functions: Store, recall, and clear memory values
- Error Handling: Comprehensive error detection and user-friendly error messages
- Clean Interface: Simple and intuitive command-line interface
Requirements
- C++ compiler (C++11 or later recommended)
- Standard C++ library only (no external dependencies)
Building the Project
Prerequisites
- C++ compiler (g++, clang++, or MSVC)
- CMake (optional, for automated builds)
Compilation
Using g++ (Linux/macOS)
g++ -std=c++11 -o ScientificCalculator main.cpp calculator.cpp
Using Makefile
make
Using CMake
mkdir build
cd build
cmake ..
make
Usage
-
Run the executable:
./ScientificCalculator -
Basic Operations:
Enter an expression or command: 5 + 3 Result: 8 -
Advanced Functions:
Enter an expression or command: sin(30) Result: 0.5 -
Memory Operations:
Enter an expression or command: memstore 10 Enter an expression or command: memadd 5 Enter an expression or command: memrecall Result: 15 -
Exit the calculator:
Enter an expression or command: exit
Supported Operations
Basic Arithmetic
+: Addition-: Subtraction*: Multiplication/: Division^: Power operation
Trigonometric Functions
sin(x): Sinecos(x): Cosinetan(x): Tangentasin(x): Arcsineacos(x): Arccosineatan(x): Arctangent
Logarithmic and Exponential Functions
log(x): Natural logarithmlog10(x): Base-10 logarithmexp(x): Exponential functionsqrt(x): Square rootpow(x, y): Power function
Memory Functions
memstore x: Store value in memorymemadd x: Add value to memorymemsubtract x: Subtract value from memorymemrecall: Recall memory valuememclear: Clear memory
Project Structure
ScientificCalculator/
├── main.cpp # Main program entry point
├── calculator.cpp # Core calculator implementation
├── calculator.h # Calculator class header
├── README.md # This file
└── Makefile # Build configuration (optional)
Code Structure
Calculator Class
The main calculator functionality is implemented in the Calculator class, which provides:
- Expression parsing and evaluation
- Mathematical function implementations
- Memory management
- Error handling
Key Components
- Expression Parser: Handles input parsing and tokenization
- Evaluator: Processes mathematical expressions and computes results
- Function Library: Implements all supported mathematical functions
- Memory Manager: Handles storage and retrieval of memory values
Error Handling
The calculator includes comprehensive error handling for:
- Invalid expressions
- Division by zero
- Domain errors (logarithm of negative numbers, etc.)
- Memory overflow/underflow
- Syntax errors
Error messages are user-friendly and provide guidance for correct usage.
Examples
Basic Calculations
Enter an expression or command: 15 * 4 + 10 / 2
Result: 65
Enter an expression or command: 2 ^ 10
Result: 1024
Scientific Calculations
Enter an expression or command: sin(45) + cos(45)
Result: 1.41421
Enter an expression or command: log(100) * exp(2)
Result: 18.4207
Memory Operations
Enter an expression or command: memstore 25
Enter an expression or command: memadd 15
Enter an expression or command: memrecall
Result: 40
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
License
This project is open source and available under the MIT License.
Future Enhancements
- Graphical user interface (GUI) implementation
- Additional mathematical functions (hyperbolic functions, statistical functions)
- Expression history and recall
- Custom variable storage
- Unit conversion capabilities
- Complex number support
Contact
For questions, suggestions, or contributions, please open an issue on the GitHub repository.
Scientific Calculator
A simple scientific calculator built in Python.
Features
- Basic arithmetic operations
- Trigonometric functions
- Logarithms and exponentials
How to Use
- Clone the repo:
git clone <repo-url> - Run the calculator:
python calculator.py
Credits
Inspired by Python calculator tutorials.
Disclaimer
For learning purposes.
e44406f (Improve project: code quality, docs, and structure)