An open API service indexing awesome lists of open source software.

https://github.com/pranavh-2004/polycalc

"PolyCalc (Polyglot Calculator) demonstrates core programming concepts across multiple languages, embodying the simplicity and versatility of a calculator as the perfect ‘hello world’ program for learning any new language.”
https://github.com/pranavh-2004/polycalc

basic-learning basic-programming best-practices calculator cross-language muti-language open-source programming-languages

Last synced: 10 months ago
JSON representation

"PolyCalc (Polyglot Calculator) demonstrates core programming concepts across multiple languages, embodying the simplicity and versatility of a calculator as the perfect ‘hello world’ program for learning any new language.”

Awesome Lists containing this project

README

          

# **PolyCalc (short for Polyglot Calculator)**

**PolyCalc** is a multi-language arithmetic calculator project aimed at mastering the basics of various programming languages. The project implements a simple calculator in multiple languages, including Python, C, C++, Go, TypeScript, JavaScript, Bash, PowerShell, PHP and MATLAB demonstrating the fundamentals of input handling, arithmetic operations, and formatted output.

---

## **Features**

- 🧮 Performs basic arithmetic operations: addition (`+`), subtraction (`-`), multiplication (`*`), and division (`/`).
- ✅ Input validation for numbers and operators.
- 🎯 Displays results with two decimal precision.
- 🛠 Modular and structured code for each language, showcasing best practices.

---

## **Languages Implemented**

- **Python**
- **C**
- **Go**
- **TypeScript**
- **JavaScript**
- **Bash**
- **C++**
- **PowerShell**
- **PHP**
- **MATLAB**

---

## **Getting Started**

Follow the instructions below to run the calculator in your preferred language.

### **Python**

1. Install Python 3.x.
2. Run the program:
```bash
python simple_calculator.py
```

### **C**

1. Use GCC to compile:
```bash
gcc simple_calculator.c -o simple_calculator
```
2. Run the program:
```bash
./simple_calculator
```

### **Go**

1. Install Go.
2. Run the program:
```bash
go run simple_calculator.go
```

### **Typescript**

1. Install dependencies: (shown wrt pnpm as i used it for this project)
```bash
pnpm install
```
2. Compile the code:
```bash
pnpm tsc
```
3. Run the compiled code:
```bash
node simple_calculator.js
```

### **Javascript**

1. Run directly with Node.js:
```bash
node simple_calculator.js
```

### **Bash Shell**

1. Make the script executable:
```bash
chmod +x simple_calculator.sh
```
2. Run the program:
```bash
./simple_calculator.sh
```

### **C++**

1. Use G++ to compile:
```bash
g++ simple_calculator.cpp -o simple_calculator
```
2. Run the program:
```bash
./simple_calculator
```

### **PowerShell**

1. Make the script executable:
```powershell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
```
2. Run the script:
```powershell
.\simple_calculator.ps1
```

### **PHP**

1. Run the PHP script using the PHP command line:
```powershell
php simple_calculator.php
```

### **MATLAB**

1. Open MATLAB by launching the MATLAB application
2. Navigate to the Script’s Directory
3. Run the MATLAB script:
```bash
simple_calculator
```

## Project Structure

The project is organized into the following directories and files:

```plaintext
PolyCalc/
├── Python/
│ └── simple_calculator.py
├── C/
│ └── simple_calculator.c
├── C++/
│ └── simple_calculator.cpp
├── Go/
│ └── simple_calculator.go
├── TypeScript/
│ └── simple_calculator.ts
├── JavaScript/
│ └── simple_calculator.js
├── Bash/
│ └── simple_calculator.sh
├── PowerShell/
│ └── simple_calculator.ps1
├── PHP/
│ └── simple_calculator.php
├── MATLAB/
│ └── simple_calculator.m
├── README.md
└── .gitignore
```

## **Contributing**

Contributions are welcome! If you’d like to add more languages or features:

1. **Fork this repository.**
2. **Create a new branch:**
```bash
git checkout -b feature/new-language
```
3. **Commit your changes:**
```bash
git commit -m "Add [language] implementation"
```
4. **Push to the branch:**
```bash
git push origin feature/new-language
```
5. **Submit a pull request.**

## License

This project is licensed under the [MIT License](LICENSE).