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

https://github.com/0xromjobert/shiny-engine-cpp09


https://github.com/0xromjobert/shiny-engine-cpp09

Last synced: 25 days ago
JSON representation

Awesome Lists containing this project

README

        

# C++ Module 09 - STL Exercises

This repository contains my solutions for Module 09 of the C++ curriculum at 42 School. Each exercise explores concepts of Standard Template Library (STL), containers, and algorithms in C++98.

**Status**: All exercises validated with a grade of 100%.

---

## Prerequisites

- A C++ compiler supporting the C++98 standard.
- `make` utility for building the project.

---

## Compilation and Execution

For each exercise:

1. Navigate to the respective directory (e.g., `ex00/` for Bitcoin Exchange):
```bash
cd ex00
```
2. Build the project using the provided Makefile:
```bash
make
```
3. Run the program with the appropriate input:
```bash
./
```

---

## Exercises

### Exercise 00: Bitcoin Exchange

**Objective**: Calculate the value of a specific amount of Bitcoin on a given date based on historical exchange rates.

**Directory**: `ex00/`

**Files**: `Makefile`, `main.cpp`, `BitcoinExchange.cpp`, `BitcoinExchange.hpp`

**Features**:
- Parses a CSV file containing historical Bitcoin prices.
- Calculates Bitcoin value based on user input (date and quantity).
- Finds the closest available date in the database if the exact date is not present.
- Validates input formats and handles errors gracefully.

**Input Format**:
- Database file (CSV): `YYYY-MM-DD,price`
- Input file: `date | value`

**Usage Example**:
```bash
./btc input.txt
```
_Output_:
```
2011-01-03 => 3 = 0.9
2011-01-09 => 1 = 0.32
Error: not a positive number.
Error: bad input => 2001-42-42
2012-01-11 => 1 = 7.1
Error: too large a number.
```

**Key Concepts**:
- STL containers (`std::map`).
- File I/O.
- Error handling and validation.
- Algorithmic logic for date proximity.

---

### Exercise 01: Reverse Polish Notation (RPN)

**Objective**: Implement a program to evaluate Reverse Polish Notation expressions.

**Directory**: `ex01/`

**Files**: `Makefile`, `main.cpp`, `RPN.cpp`, `RPN.hpp`

**Features**:
- Supports basic arithmetic operations (`+`, `-`, `*`, `/`).
- Uses a stack to evaluate the RPN expression.
- Validates input format and ensures proper tokenization.
- Handles errors such as division by zero and invalid expressions.

**Usage Example**:
```bash
./RPN "8 9 * 9 - 9 - 9 - 4 - 1 +"
```
_Output_:
```
42
```

**Key Concepts**:
- STL container (`std::stack`).
- Parsing and tokenization.
- Error handling for invalid input.
- Stack-based expression evaluation.

---

### Exercise 02: PmergeMe

**Objective**: Implement the Ford-Johnson merge-insert sort algorithm using two different STL containers.

**Directory**: `ex02/`

**Files**: `Makefile`, `main.cpp`, `PmergeMe.cpp`, `PmergeMe.hpp`

**Features**:
- Accepts a sequence of positive integers as input.
- Sorts the integers using a merge-insert sort algorithm.
- Uses `std::vector` and `std::deque` as containers for sorting.
- Displays the time taken for sorting with each container.

**Usage Example**:
```bash
./PmergeMe 3 5 9 7 4
```
_Output_:
```
Before: 3 5 9 7 4
After (vec): 3 4 5 7 9
After (deque): 3 4 5 7 9
Time to process a range of 5 elements with std::deque: 0.00014 us
Time to process a range of 5 elements with std::vector: 0.00012 us
```

**Key Concepts**:
- STL containers (`std::vector` and `std::deque`).
- Divide-and-conquer algorithms.
- Timing operations and performance comparison.
- Advanced sorting algorithms.

- Each exercise is implemented independently, following the constraints of the subject.
- Containers used in one exercise are not reused in subsequent exercises.