This repository contains three different implementations of a simple calculator program, each demonstrating a different programming paradigm: imperative, functional, and object-oriented.
Programming paradigms are different approaches to writing code, each with its own set of principles and concepts. This repository showcases three programming paradigms used to create a basic calculator program. The goal is to provide insights into how the same functionality can be implemented using different programming styles.
-
Imperative: This version of the calculator program uses traditional control structures like loops and conditionals for logic flow.
-
Functional: The functional version employs concepts like pure functions, immutability, and higher-order functions to perform calculations.
-
Object-Oriented: In the object-oriented version, the calculator's functionality is encapsulated within classes, allowing for modular and organized code.
Each version provides the same core features, including addition, subtraction, multiplication, and division operations.
-
Clone the repository to your local machine:
git clone https://github.com/teaching-repositories/programming_paradigms
-
Navigate to the directory of the specific programming paradigm you want to explore:
cd programming_paradigms/imperative
-
Run the calculator program using your preferred Python interpreter:
python calculator.py
-
Follow the on-screen prompts to choose an operation and input operands. The program will display the result of the calculation.
-
Repeat steps 2-4 for the functional and object-oriented versions.
-
Imperative Paradigm: Focuses on describing "how" to achieve a task using explicit instructions and control structures.
-
Functional Paradigm: Emphasises "what" needs to be done by composing functions and avoiding side effects. It relies on immutability and higher-order functions.
-
Object-Oriented Paradigm: Organises code around objects that encapsulate data and behaviour. It promotes modularity and reusability through classes and inheritance.
Contributions are welcome! If you'd like to enhance or expand the calculator program for any of the paradigms, feel free to fork this repository and submit a pull request with your changes.
This project is licensed under the MIT License. You are free to use, modify, and distribute the code as permitted by the license.
Enjoy exploring the different programming paradigms showcased in this repository! If you have any questions or suggestions, feel free to open an issue or reach out to the repository owner.