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

https://github.com/cypri1-dev/42_cpp04

This topic explores polymorphism in C++ with Animal, Dog, and Cat classes, using makeSound to show polymorphic behavior. Animal becomes abstract, enforcing unique behavior for derived classes. Interfaces like ICharacter and IMateriaSource allow for creating reusable magical items and characters, applying deep copy and memory management principles.
https://github.com/cypri1-dev/42_cpp04

42cpp 42projects cpp cpp04

Last synced: 9 months ago
JSON representation

This topic explores polymorphism in C++ with Animal, Dog, and Cat classes, using makeSound to show polymorphic behavior. Animal becomes abstract, enforcing unique behavior for derived classes. Interfaces like ICharacter and IMateriaSource allow for creating reusable magical items and characters, applying deep copy and memory management principles.

Awesome Lists containing this project

README

          

## Description
This project introduces polymorphism and interfaces in C++ through an `Animal` class hierarchy, where `Dog` and `Cat` inherit from `Animal`, showcasing polymorphic behavior with the `makeSound()` method. The exercises build on this by adding abstract classes, deep copying, memory management, and interfaces for managing unique attributes and behaviors.

## Exercise 00
Objectives 🚀:
- Implement a basic `Animal` class and derive `Dog` and `Cat` classes.

Requirements:
- Define `Animal` with protected attribute `type`.
- `Dog` and `Cat` initialize `type` as "Dog" or "Cat".
- Create `makeSound()` for each class to produce specific sounds.

## Exercise 01
Objectives 🚀:
- Extend `Dog` and `Cat` with unique `Brain` objects.

Requirements:
- Add a `Brain` class with 100 `std::string` ideas.
- `Dog` and `Cat` have private `Brain*` attributes, allocated with `new` and deleted on destruction.
- Ensure deep copying of `Dog` and `Cat` objects.

## Exercise 02
Objectives 🚀:
- Make `Animal` an abstract class.

Requirements:
- Convert `Animal` into an abstract base class, making it non-instantiable.
- Derived classes like `Dog` and `Cat` remain functional.

## Exercise 03
Objectives 🚀:
- Implement interfaces using abstract classes.

Requirements:
- Create `AMateria` with `clone()` and `use()` as pure virtual methods.
- Implement `Ice` and `Cure` classes with specific `use` actions.
- Develop `Character` and `MateriaSource` classes with inventory and item management features.