C GUI Calculator

A GUI-based calculator developed in C using GTK.


Project maintained by rafisarkar0128 Hosted on GitHub Pages — Theme by mattgraham

๐Ÿงฎ C GUI Calculator

A beginner-friendly project developed as part of the CSE115 course in the Department of Electrical & Computer Engineering in North South University. This GUI-based calculator performs both basic arithmetic and scientific operations using the C programming language with a graphical interface powered by GTK.

๐Ÿงช Project Reactor Status

Issues Forks Stargazers Contributors MIT License Last Commit

๐Ÿ—‚๏ธ Project Structure

c-gui-calculator/
โ”œโ”€โ”€ main.c              # Main code file to run the project
โ”œโ”€โ”€ README.md           # Project documentation
โ”œโ”€โ”€ requirements.txt    # List of required tools/libraries
โ”œโ”€โ”€ .github/            # GitHub workflows and issue templates
โ”œโ”€โ”€ .gitignore          # Ignore unnecessary files
โ”œโ”€โ”€ LICENSE             # Project license
โ”œโ”€โ”€ SECURITY.md         # Security policy
โ”œโ”€โ”€ _config.yml         # Configuration file (for GitHub Pages)
โ”œโ”€โ”€ data/               # Datasets (images, etc.)
โ”œโ”€โ”€ support/            # Other code files
โ”œโ”€โ”€ others/             # Final & update presentations, reports, and demo video
โ”‚   โ”œโ”€โ”€ final_presentation.pptx
โ”‚   โ”œโ”€โ”€ final_report.pdf
โ”‚   โ”œโ”€โ”€ update_presentation.pptx
โ”‚   โ”œโ”€โ”€ update_report.pdf
โ”‚   โ””โ”€โ”€ demo_video.mp4

๐Ÿš€ Features

๐Ÿ“Š Basic Operations

๐Ÿ”ฌ Scientific Functions

๐Ÿง  Advanced Features

๐Ÿ“ Usage Examples

Basic Arithmetic

2 + 3 * 4 = 14          # Respects operator precedence
(2 + 3) * 4 = 20        # Parentheses override precedence
15 / 3 + 2 = 7          # Left-to-right evaluation for same precedence
50% = 0.5               # Percentage conversion

Scientific Functions

sqrt(16) = 4            # Square root
sqrt(2) = 1.414...      # Works with non-perfect squares
log(100) = 2            # Base-10 logarithm
ln(2.718) = 1           # Natural logarithm (approximately e)
sin(30) = 0.5           # Sine in degrees
cos(60) = 0.5           # Cosine in degrees
tan(45) = 1             # Tangent in degrees

Power Operations

2^3 = 8                 # Basic exponentiation
2^3^2 = 512             # Right associative: 2^(3^2), not (2^3)^2
(-2)^3 = -8             # Negative base with integer exponent
4^0.5 = 2               # Fractional exponents (same as sqrt)

Complex Expressions

sin(90) + sqrt(cos(0) * 4) = 3     # Mixed functions: 1 + sqrt(1 * 4) = 1 + 2 = 3
(5 + 3) * sqrt(16) / 2 = 16        # Multiple operations: 8 * 4 / 2 = 16
log(10^3) = 3                      # Logarithm of power: log(1000) = 3
2 * sin(30) + cos(60) = 1.5        # Multiple trig functions: 2 * 0.5 + 0.5 = 1.5

โŒจ๏ธ Keyboard Shortcuts

Key Action Description
Enter Calculate Same as pressing the = button
Backspace Delete Remove last character from input
Numbers 0-9 Input Use on-screen buttons only
Operators Input Use on-screen buttons only

Note: Most input requires using the on-screen buttons to ensure proper token recognition by the expression parser.

โŒ Error Handling

The calculator provides comprehensive error checking for mathematical edge cases:

Domain Errors

sqrt(-4)        โ†’ "Cannot take square root of negative number"
log(0)          โ†’ "Logarithm undefined for zero or negative numbers"
log(-5)         โ†’ "Logarithm undefined for zero or negative numbers"
ln(0)           โ†’ "Natural log undefined for zero or negative numbers"

Division Errors

5 / 0           โ†’ "Division by zero"
1 / (2-2)       โ†’ "Division by zero"
0^(-2)          โ†’ "Cannot raise zero to negative power"

Power Function Errors

(-2)^1.5        โ†’ "Cannot raise negative number to non-integer power"
(-3)^0.333      โ†’ "Cannot raise negative number to non-integer power"

Trigonometric Errors

tan(90)         โ†’ "Tangent undefined at 90ยฐ and odd multiples"
tan(270)        โ†’ "Tangent undefined at 90ยฐ and odd multiples"
tan(-90)        โ†’ "Tangent undefined at 90ยฐ and odd multiples"

Syntax Errors

((2+3)          โ†’ "Mismatched parentheses"
2++)            โ†’ "Invalid character in expression"
sin(            โ†’ "Function 'sin' requires an argument"
+ * 2           โ†’ "Not enough operands for operator"

๐Ÿค Team Members

This project was collaboratively developed by:

๐Ÿš€ Quick Start

Prerequisites

Ensure you have the following installed:

Installation & Setup

  1. Clone the repository

     git clone https://github.com/rafisarkar0128/c-gui-calculator.git
     cd c-gui-calculator
    
  2. Install dependencies

    Linux (Ubuntu/Debian):

     sudo apt update
     sudo apt install gcc pkg-config libgtk-3-dev
    

    Linux (Fedora/CentOS/RHEL):

     sudo dnf install gcc pkgconf-pkg-config gtk3-devel
    

    Windows (MSYS2):

     pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gtk3
    

    macOS (Homebrew):

     brew install gcc pkg-config gtk+3
    
  3. Compile & Run

     gcc -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
     ./calculator
    

๐Ÿ“– Need help? See our comprehensive Getting Started Guide for detailed setup instructions, troubleshooting tips, and platform-specific notes.

๐Ÿ—๏ธ Technical Architecture

The calculator implements several advanced computer science concepts:

Expression Parsing

Memory Management

GUI Architecture

๐Ÿ“š Learning Outcomes

๐Ÿค Contributing

We welcome contributions! Hereโ€™s how you can help:

  1. Fork the repository and create your feature branch
  2. Follow our coding standards - consistent formatting and documentation
  3. Test thoroughly - ensure all features work across platforms
  4. Submit a pull request with a clear description of changes

Development Setup

  1. Follow the Quick Start guide above
  2. Make your changes in a feature branch
  3. Test compilation and functionality
  4. Submit your pull request

๐Ÿ“ž Contact & Support

For questions, bug reports, or contributions:

๐Ÿ“š References & Resources

๐Ÿง  Acknowledgments

Thanks to our instructor and the CSE115 course staff for their guidance and resources, and to the open-source community for tools and inspiration.

๐Ÿ“„ License

This project is licensed under the MIT License.