Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Readme.md

🧮 Simple Calculator with History

C++ Stack Complete

Interactive calculator with stack-based history tracking


🚀 Features

🔢 Basic Operations

  • Addition - Add two numbers
  • Subtraction - Subtract two numbers
  • ✖️ Multiplication - Multiply two numbers
  • Division - Divide with zero-check protection
  • 📊 Result Display - Immediate calculation output

📚 History Management

  • 📋 Stack Storage - LIFO history tracking
  • 🔄 Complete History - View all past calculations
  • 💾 Session Memory - Results stored until exit
  • Fast Access - Stack-based retrieval

🛠️ Technical Implementation

📚 Stack Data Structure

  • Container: std::stack<float>
  • Operations: Push results after each calculation
  • Access: LIFO (Last In, First Out)
  • Memory: Dynamic allocation

🔧 Core Functions

  • addition() - Basic arithmetic
  • subtraction() - Basic arithmetic
  • multiplication() - Basic arithmetic
  • division() - With zero-division check

🎮 Interactive Menu

Press 1 for addition
Press 2 for subtraction
Press 3 for multiplication
Press 4 for division
Press 0 to exit
Enter Your Choice: 1

Sample Calculation

Enter The First Number: 15.5
Enter The Second Number: 4.5
Result: 20

Enter Your Choice: 4
Enter The First Number: 10
Enter The Second Number: 0
Error dividing by zero

📊 History Display

The Recent History is:
20
15.5
8.75
42

Note: History displays in reverse order (most recent first) due to stack LIFO nature.


🔧 Error Handling

Division by Zero Protection

if(b == 0) {
    cout << "Error dividing by zero" << endl;
    continue;  // Skip storing invalid result
}

Input Validation

  • Float Support - Handles decimal numbers
  • Continuous Operation - Loop until user exits
  • Invalid Choice - Graceful menu return

🎯 Learning Objectives

  • ✅ Stack data structure implementation
  • ✅ LIFO (Last In, First Out) principle
  • ✅ Basic arithmetic operations in C++
  • ✅ Error handling and input validation
  • ✅ Menu-driven program design
  • ✅ Float precision handling

🚀 Usage

Compilation & Run

g++ -o calculator SimpleCalculatorWithHistory.cpp
./calculator

Sample Session

Enter Your Choice: 1
Enter The First Number: 25
Enter The Second Number: 15
Result: 40

Enter Your Choice: 0

The Recent History is:
40

🔮 Future Enhancements

  • 🧮 Advanced Operations - Power, square root, trigonometry
  • 📁 File Storage - Save history to file
  • 🔄 History Navigation - Search and reuse previous results
  • 🎨 GUI Interface - Visual calculator design
  • 📊 Expression Parsing - Handle complex expressions

🧮 Calculate with Confidence! 📊