📘 Project Overview
This calculator project demonstrates all concepts learned in Part I of the C++ curriculum: - User-defined classes and objects - Exception handling - STL containers and algorithms - Basic threading concepts - Clean, modular code structure
🎯 Learning Objectives
After completing this project, you will: - Apply object-oriented programming principles - Implement robust error handling with exceptions - Use STL containers for data management - Implement basic threading for complex calculations - Design clean, maintainable code architecture
🏗️ Project Architecture
Core Classes
- Calculator: Main calculator class with basic operations
- Operation: Base class for all operations
- ArithmeticOperation: Handles basic arithmetic
- ScientificOperation: Handles scientific calculations
- OperationHistory: Manages calculation history
- CalculatorException: Custom exception class
Features
- Basic Operations: Addition, subtraction, multiplication, division
- Scientific Operations: Square root, power, logarithm, trigonometric functions
- History Management: Store and retrieve calculation history
- Error Handling: Comprehensive exception handling
- Threading: Background calculation for complex operations
- Memory Management: RAII principles throughout
🧩 Implementation Requirements
1. Exception Handling
- Custom exception classes
- Input validation
- Division by zero protection
- Overflow/underflow detection
2. STL Usage
std::vectorfor operation historystd::stringfor input/outputstd::mapfor operation lookupstd::threadfor background calculations
3. Class Design
- Proper encapsulation
- Constructor/destructor implementation
- Operator overloading where appropriate
- Const correctness
4. Threading
- Background calculation for expensive operations
- Thread-safe history management
- Proper thread cleanup
💻 Code Structure
Calculator_Project/
├── README.md
├── calculator.h
├── calculator.cpp
├── operation.h
├── operation.cpp
├── operation_history.h
├── operation_history.cpp
├── calculator_exception.h
├── calculator_exception.cpp
├── main.cpp
├── Makefile
└── tests/
├── test_calculator.cpp
└── test_operations.cpp
🚀 Getting Started
-
Compile the project:
bash make -
Run the calculator:
bash ./calculator -
Run tests:
bash make test
🎮 Usage Examples
Basic Operations
Enter expression: 2 + 3
Result: 5
Enter expression: 10 / 2
Result: 5
Enter expression: sqrt(16)
Result: 4
History Management
Command: history
1. 2 + 3 = 5
2. 10 / 2 = 5
3. sqrt(16) = 4
Command: clear
History cleared.
Error Handling
Enter expression: 5 / 0
Error: Division by zero
Enter expression: sqrt(-4)
Error: Square root of negative number
🧪 Testing
The project includes comprehensive tests for: - Basic arithmetic operations - Scientific operations - Error handling - History management - Threading functionality
📚 Key Learning Points
- RAII: Resource management through object lifetime
- Exception Safety: Proper error handling without resource leaks
- STL Integration: Effective use of standard containers and algorithms
- Thread Safety: Proper synchronization and thread management
- Code Organization: Clean separation of concerns
🔗 Next Steps
After completing this project, you'll be ready for Part II of the curriculum, which covers advanced language features, memory management, and more complex programming patterns.
🏆 Success Criteria
- [ ] All basic operations work correctly
- [ ] Scientific operations function properly
- [ ] Exception handling works for all error cases
- [ ] History management is thread-safe
- [ ] Code follows C++ best practices
- [ ] All tests pass
- [ ] Memory management is correct (no leaks)