/cpp-module-04

Master advanced C++ concepts like polymorphism, deep copying, and abstract classes, with exercises on polymorphic behavior, memory management, and defining interfaces for derived classes.

Primary LanguageC++

cpp-module-04

This project focuses on inheritance, polymorphism, abstract classes, and interfaces. It teaches class hierarchies, while exploring virtual functions and subtype polymorphism. It introduces abstract classes, preventing direct instantiation of base class, and using interfaces to ensure uniform behaviors.

Final score

100%

ex00 - Animals

In the first exercise, we need to create a basic class, Animal, along with its derived classes Dog and Cat. Each class will have its own makeSound method, producing different outputs depending on the animal. The goal is to manipulate Dog and Cat objects through pointers to their common parent class, Animal, ensuring the correct sound is made for each type of animal.

ex01 - Animals with brains

The second exercise builds upon the first by adding a new class, Brain. In this exercise, both Cat and Dog instances will have a Brain object, which can store up to 100 ideas. The challenge emphasizes proper memory management, ensuring that copies of Cat and Dog objects do not result in shallow copies, and memory leaks are avoided. The goal is to implement deep copying and clean resource management, ensuring the program runs efficiently without unexpected memory issues.

ex02 - Abstract animals

The third exercise introduces the concept of abstract classes. In this task, the Animal base class is modified to become abstract, meaning it can no longer be instantiated directly. Instead, it serves as a blueprint for derived classes like Dog and Cat. This exercise emphasizes the use of pure virtual functions, which force derived classes to implement specific methods, ensuring a consistent interface while preventing direct creation of base class objects.

ex03 - Materias

The fourth and final exercise of the module involves implementing pure abstract classes (interfaces). In this task, you implement the ICharacter interface, which is used by the Character class. A Character has an inventory that can hold up to four Materia items, which can be equipped, unequipped, or used. Materia can either be of type Ice or Cure. The MateriaSource class implements the IMateriaSource interface and is responsible for creating and managing Materia objects. This exercise emphasizes the design of interfaces and their role in defining behavior across different classes, ensuring modular and flexible code.