Git Product home page Git Product logo

h4jack / cal Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 54 KB

This project is a simple expression calculator implemented in C. It provides functionalities to convert infix expressions to postfix notation and evaluate the resulting postfix expressions.

License: GNU General Public License v3.0

C 100.00%
c cal calculator cmd command-line-calculator command-line-tool cprogramming infix infix-to-postfix postfix postfix-calculator postfix-evaluation

cal's Introduction

Expression Calculator

This project is a simple expression calculator implemented in C. It provides functionalities to convert infix expressions to postfix notation and evaluate the resulting postfix expressions.

Project Structure

The project directory contains the following files:

  • cal.exe: Executable file for the expression calculator.
  • expression-calculator-onefile.c: Main source file containing the implementation of the expression calculator.
  • expression_calculator.c: Source file containing functions for converting infix expressions to postfix notation and evaluating postfix expressions.
  • list.h: Header file containing the implementation of a linked list data structure.
  • util.h: Header file containing utility functions and definitions used in the project.

Installation

To run the game, follow these steps:

Clone the repo and use and analyze the code:

git clone https://www.github.com/h4jack/cal.git ./Expressioin-Calculator

Navigate to the project directory:

cd Expressioin-Calculator

Run the game:

./cal.exe

Usage

To use the expression calculator, you can compile the source files using a C compiler and then run the executable. Here's how to use it:

  • Compile the source files:
gcc expression-calculator-onefile.c expression_calculator.c -o cal.exe
  • Run the executable:
./cal.exe
  • You will be prompted to enter an infix expression. You can also pass the expression as command-line arguments, e.g.:
cal ./cal.exe "10*(-13+17)/1.5-17"
  • The calculator will convert the infix expression to postfix notation, evaluate the postfix expression, and display the result.

Documentation

For detailed documentation of the code and its functionalities, refer to the Documentation.md file.

Expression Calculator Features

The expression calculator project provides the following features:

Infix to Postfix Conversion

  • Convert infix expressions to postfix notation.
  • Supports arithmetic operators: addition (+), subtraction (-), multiplication (*), division (/), modulus (%), and exponentiation (^).
  • Handles parentheses to determine the order of operations.

Postfix Expression Evaluation

  • Evaluate postfix expressions using a stack-based approach.
  • Support for basic arithmetic operations and precedence rules.

Error Handling

  • Detects and handles various types of errors in input expressions.
  • Error messages are displayed for informative purposes, including:
    • Invalid expressions.
    • Division by zero.
    • Unmatched parentheses.

Command-Line Interface

  • Accepts infix expressions as command-line arguments.
  • Provides a user-friendly interface for entering infix expressions if no arguments are provided.
  • Optional verbose mode (-v or -V) for displaying the input infix expression and the resulting postfix expression.

Modular Design

  • Organized into multiple source files for clarity and maintainability:
    • expression-calculator-onefile.c: Main entry point and command-line argument processing.
    • expression_calculator.c: Core functionality for expression conversion and evaluation.
    • list.h: Implementation of a linked list data structure.
    • util.h: Utility functions and definitions used throughout the project.

Portable and Easy to Use

  • Written in C for portability across different platforms.
  • Simple compilation and execution process for ease of use.

Authors

License

This project is licensed under the GNU GENERAL PUBLIC LICENSE

Feedback

If you have any feedback or suggestions, please feel free to create an issue or contact us.

cal's People

Contributors

capelin avatar h4jack avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.