/Console-Based-Equation-System

Console system for creating, solving, and manipulating first and second degree equations.

Primary LanguageC++

๐Ÿงฎ Console-Based Equation System

Authors: Valdo Castiglia, Giuliana Giusiano, Shoan Genes
Professor: Josรฉ Clavijo
Due Date: February 17, 2025


๐Ÿ“Œ Description

This system allows users to create, display, solve, add, save, and retrieve first and second-degree equations through a command-line interface. It was developed as part of Workshop 1, applying data structure techniques, Abstract Data Types (ADTs), and file persistence.


๐Ÿง  Features

The system recognizes and executes the following commands:

  • crear <id> <a> <b> [c] โ†’ Creates an equation (1st or 2nd degree)
  • mostrar โ†’ Displays all equations loaded in memory
  • resolver <id> โ†’ Solves the equation with the specified identifier
  • sumar <id1> <id2> <idResultado> โ†’ Adds two equations and saves the result
  • guardar <id> โ†’ Saves an equation to disk (.dat file)
  • recuperar <id> โ†’ Retrieves an equation from disk
  • salir โ†’ Frees memory and terminates execution

๐Ÿงช Data Structures Used: Linear list for commands and Binary Search Tree (BST) for storing equations.


๐Ÿ”ง Technologies and Structures

  • Language: C++
  • Paradigm: Structured programming with intensive use of Abstract Data Types (ADTs)
  • Data Structures:
    • Binary Search Tree (BST) for equation storage
    • Linked list of strings for command processing
    • union to distinguish between 1st and 2nd degree equations
    • Binary files for data persistence (.dat format)
  • Architecture: Modular design with header files (.h) and separate ADT implementations

๐Ÿ’ป Usage Example

crear eq1 2 3
crear eq2 1 4 5
sumar eq1 eq2 eq3
resolver eq3
guardar eq3
salir

Command Explanations

Command Parameters Description Example
crear <id> <a> <b> [c] Creates equation: ax + b = 0 (linear) or axยฒ + bx + c = 0 (quadratic) crear eq1 2 -5 creates 2x - 5 = 0
mostrar None Lists all equations in memory mostrar
resolver <id> Solves the specified equation resolver eq1
sumar <id1> <id2> <result_id> Adds two equations coefficient-wise sumar eq1 eq2 eq3
guardar <id> Saves equation to binary file guardar eq1
recuperar <id> Loads equation from binary file recuperar eq1
salir None Exits program and frees memory salir

๐Ÿ—๏ธ Project Structure

โ”œโ”€โ”€ include/
โ”‚   โ”œโ”€โ”€ abbecuaciones.h     # Binary Search Tree ADT for equations
โ”‚   โ”œโ”€โ”€ ecuacion.h          # Equation ADT (supports 1st & 2nd degree)
โ”‚   โ”œโ”€โ”€ comando.h           # Command parsing ADT
โ”‚   โ”œโ”€โ”€ primergrado.h       # First-degree equation operations
โ”‚   โ”œโ”€โ”€ segundogrado.h      # Second-degree equation operations
โ”‚   โ”œโ”€โ”€ ejecucion.h         # Command execution handlers
โ”‚   โ”œโ”€โ”€ string.h            # Custom string ADT
โ”‚   โ”œโ”€โ”€ boolean.h           # Boolean type definition
โ”‚   โ””โ”€โ”€ grado.h             # Degree enumeration
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ abbecuaciones.cpp   # BST implementation
โ”‚   โ”œโ”€โ”€ ecuacion.cpp        # Equation management
โ”‚   โ”œโ”€โ”€ comando.cpp         # Command parsing logic
โ”‚   โ”œโ”€โ”€ primergrado.cpp     # Linear equation solver
โ”‚   โ”œโ”€โ”€ segundogrado.cpp    # Quadratic equation solver
โ”‚   โ”œโ”€โ”€ ejecucion.cpp       # Command execution logic
โ”‚   โ”œโ”€โ”€ string.cpp          # String utilities
โ”‚   โ””โ”€โ”€ main.cpp            # Program entry point
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ README.md

๐ŸŽฏ Key Features

Equation Types Supported

  • Linear Equations (1st degree): ax + b = 0
  • Quadratic Equations (2nd degree): axยฒ + bx + c = 0

Solving Capabilities

  • Linear equations: Direct solution x = -b/a
  • Quadratic equations:
    • No real solutions (negative discriminant)
    • One solution (zero discriminant)
    • Two solutions (positive discriminant)

Data Persistence

  • Binary file storage with .dat extension
  • Automatic file management for save/load operations
  • Prevents overwriting existing files

Error Handling

  • Validates command syntax and parameter count
  • Checks for duplicate identifiers
  • Ensures non-zero leading coefficients
  • Validates alphabetic identifiers and numeric coefficients

๐Ÿš€ Getting Started

Prerequisites

  • C++ compiler (g++, clang++, etc.)
  • Standard C++ libraries

Building the Project

# Compile all source files
g++ -I include src/*.cpp -o equation_system

# Run the program
./equation_system

Sample Session

Ingrese comando: crear linear 3 -9
linear: 3x - 9 = 0

Ingrese comando: crear quadratic 1 -5 6
quadratic: x^2 - 5x + 6 = 0

Ingrese comando: resolver linear
[ Resultado ]: x = 3.00

Ingrese comando: resolver quadratic
[ Resultado ]: x1 = 3.00, x2 = 2.00

Ingrese comando: salir
[ MENSAJE ]: Hasta la proxima!

๐Ÿ“š Learning Objectives

This project demonstrates proficiency in:

  • Abstract Data Types (ADTs) design and implementation
  • Binary Search Trees for efficient data storage and retrieval
  • Memory management in C++ with proper allocation/deallocation
  • File I/O operations for data persistence
  • Modular programming with header/implementation separation
  • Command-line interface design and user input validation

๐Ÿค Contributing

This is an academic project developed for educational purposes. The codebase showcases fundamental computer science concepts including data structures, algorithms, and software engineering principles.


๐Ÿ“ License

This project is part of an academic assignment and is intended for educational use.