update: rm -rf to restart from scratch
This commit is contained in:
parent
42e83d8e62
commit
5e999def3a
45 changed files with 813 additions and 366 deletions
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:51:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,18 +14,25 @@
|
|||
#include <iostream>
|
||||
|
||||
Animal::Animal() {
|
||||
std::cout << "[Animal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
std::cout << "[Animal]\tCreating Animal class" << std::endl;
|
||||
type = "Animal";
|
||||
}
|
||||
|
||||
Animal::Animal(Animal const & copy) {
|
||||
std::cout << "[Animal]\tCreating Animal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
Animal & Animal::operator=(Animal const & assign) {
|
||||
std::cout << "[Animal]\tCreating Animal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Animal::~Animal() {
|
||||
std::cout << "[Animal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType() const {
|
||||
return (type);
|
||||
std::cout << "[Animal]\tDeleting animal class" << std::endl;
|
||||
}
|
||||
|
||||
void Animal::makeSound() const {
|
||||
std::cout << "🤔 | thinking how to make a sound" << std::endl;
|
||||
std::cout << "[Animal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:24:40 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,17 @@
|
|||
#define ANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
public:
|
||||
Animal();
|
||||
virtual ~Animal();
|
||||
Animal(Animal const & copy);
|
||||
Animal & operator=(Animal const & assign);
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,22 +5,34 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:03 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:41:28 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Cat::Cat() {
|
||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tCreating cat class" << std::endl;
|
||||
type = "Cat";
|
||||
}
|
||||
|
||||
Cat::Cat(Cat const & copy) {
|
||||
std::cout << "[Cat]\t\tCreating cat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
Cat & Cat::operator=(Cat const & assign) {
|
||||
std::cout << "[Cat]\t\tCreating cat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Cat::~Cat() {
|
||||
std::cout << "[Cat]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tDeleting cat class" << std::endl;
|
||||
}
|
||||
|
||||
void Cat::makeSound() const {
|
||||
std::cout << "🐱 | Meow Meow" << std::endl;
|
||||
std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 18:24:18 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:26:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,16 @@
|
|||
#define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include <string>
|
||||
|
||||
class Cat : public Animal {
|
||||
public:
|
||||
Cat();
|
||||
~Cat();
|
||||
Cat(Cat const & copy);
|
||||
Cat & operator=(Cat const & assign);
|
||||
virtual void makeSound() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,22 +5,34 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:53:02 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:51:41 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Dog::Dog() {
|
||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||
type = "Dog";
|
||||
}
|
||||
|
||||
Dog::Dog(Dog const & copy) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
Dog & Dog::operator=(Dog const & assign) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dog::~Dog() {
|
||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tDeleting dog class" << std::endl;
|
||||
}
|
||||
|
||||
void Dog::makeSound() const {
|
||||
std::cout << "🐶 | Wouf Wouf" << std::endl;
|
||||
std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 18:24:07 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:27:11 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,16 @@
|
|||
#define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include <string>
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
Dog();
|
||||
~Dog();
|
||||
Dog(Dog const & copy);
|
||||
Dog & operator=(Dog const & assign);
|
||||
virtual void makeSound() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,36 +1,38 @@
|
|||
# **************************************************************************** #
|
||||
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr #
|
||||
# Updated: 2025/02/18 16:50:42 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Variables
|
||||
|
||||
# Name
|
||||
NAME = polymorphism
|
||||
NAME = open
|
||||
|
||||
# Commands
|
||||
CXX = c++
|
||||
RM = rm -rf
|
||||
|
||||
# Flags
|
||||
# Mandatory flags for 42
|
||||
# Mandatory flags for 42 cpp
|
||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||
# Flags to debug and have the dependences (can be removed for correction)
|
||||
CXXFLAGS += -MMD -g3
|
||||
|
||||
# Flag to debug (TO REMOVE)
|
||||
# CXXFLAGS += -D DEBUG=1
|
||||
# Sources
|
||||
SRC = Animal.cpp \
|
||||
Cat.cpp \
|
||||
Dog.cpp \
|
||||
WrongAnimal.cpp \
|
||||
SRC = main.cpp \
|
||||
WrongCat.cpp \
|
||||
main.cpp
|
||||
WrongAnimal.cpp \
|
||||
Dog.cpp \
|
||||
Animal.cpp \
|
||||
Cat.cpp
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ./build
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:50:06 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,18 +14,25 @@
|
|||
#include <iostream>
|
||||
|
||||
WrongAnimal::WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||
type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(WrongAnimal const & copy) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType() const {
|
||||
return (type);
|
||||
std::cout << "[WrongAnimal]\tDeleting cat class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound() const {
|
||||
std::cout << "🦊 | What does the fox say ?" << std::endl;
|
||||
std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,17 @@
|
|||
#define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
public:
|
||||
WrongAnimal();
|
||||
virtual ~WrongAnimal();
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
WrongAnimal(WrongAnimal const & copy);
|
||||
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||
void makeSound() const;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,18 +5,34 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:48:59 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:53:06 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
WrongCat::WrongCat() {
|
||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
||||
std::cout << "[WrongCat]\t\tCreating WrongCat class" << std::endl;
|
||||
type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat() {
|
||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
||||
WrongCat::WrongCat(WrongCat const & copy) {
|
||||
std::cout << "[WrongCat]\t\tCreating WrongCat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongCat & WrongCat::operator=(WrongCat const & assign) {
|
||||
std::cout << "[WrongCat]\t\tCreating WrongCat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat() {
|
||||
std::cout << "[WrongCat]\t\tDeleting WrongCat class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound() const {
|
||||
std::cout << "[WrongCat]\t\t🐱 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:49:13 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,16 +14,16 @@
|
|||
#define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
#include <string>
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public:
|
||||
WrongCat();
|
||||
~WrongCat();
|
||||
WrongCat(WrongCat const & copy);
|
||||
WrongCat & operator=(WrongCat const & assign);
|
||||
virtual void makeSound() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
47
cpp04/ex00/color.hpp
Normal file
47
cpp04/ex00/color.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef COLOR_HPP
|
||||
#define COLOR_HPP
|
||||
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define BLACK "\033[0;30m"
|
||||
#define RED "\033[0;31m"
|
||||
#define GREEN "\033[0;32m"
|
||||
#define YELLOW "\033[0;33m"
|
||||
#define BLUE "\033[0;34m"
|
||||
#define MAGENTA "\033[0;35m"
|
||||
#define CYAN "\033[0;36m"
|
||||
#define WHITE "\033[0;37m"
|
||||
#define GOLD "\033[38;5;220m"
|
||||
#define GREY "\033[38;5;240m"
|
||||
|
||||
#define L_BLACK "\033[0;90m"
|
||||
#define L_RED "\033[0;91m"
|
||||
#define L_GREEN "\033[0;92m"
|
||||
#define L_YELLOW "\033[0;93m"
|
||||
#define L_BLUE "\033[0;94m"
|
||||
#define L_MAGENTA "\033[0;95m"
|
||||
#define L_CYAN "\033[0;96m"
|
||||
#define L_WHITE "\033[0;97m"
|
||||
|
||||
#define B_BLACK "\033[1;30m"
|
||||
#define B_RED "\033[1;31m"
|
||||
#define B_GREEN "\033[1;32m"
|
||||
#define B_YELLOW "\033[1;33m"
|
||||
#define B_BLUE "\033[1;34m"
|
||||
#define B_MAGENTA "\033[1;35m"
|
||||
#define B_CYAN "\033[1;36m"
|
||||
#define B_WHITE "\033[1;37m"
|
||||
|
||||
#endif
|
||||
|
|
@ -5,46 +5,40 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:52:09 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:48:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
#include "color.hpp"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
int main() {
|
||||
std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl;
|
||||
const Animal* meta = new Animal();
|
||||
const Animal* j = new Dog();
|
||||
const Animal* i = new Cat();
|
||||
const WrongAnimal* k = new WrongAnimal();
|
||||
const WrongAnimal* l = new WrongCat();
|
||||
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||
const Animal* theClassic = new Animal();
|
||||
const Animal* theDog = new Dog();
|
||||
const Animal* theCat = new Cat();
|
||||
const WrongAnimal* theBadAnimal = new WrongAnimal();
|
||||
const WrongAnimal* theBadCat = new WrongCat();
|
||||
|
||||
std::cout << std::endl << "\033[0;33m[ Testing the getType method ]\033[0m" << std::endl;
|
||||
std::cout << "Type of j:\t" << j->getType() << std::endl;
|
||||
std::cout << "Type of i:\t" << i->getType() << std::endl;
|
||||
std::cout << "Type of l:\t" << l->getType() << std::endl;
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||
theClassic->makeSound();
|
||||
theDog->makeSound();
|
||||
theCat->makeSound();
|
||||
theBadAnimal->makeSound();
|
||||
theBadCat->makeSound();
|
||||
|
||||
std::cout << std::endl << "\033[0;33m[ Testing the makeSound method ]\033[0m" << std::endl;
|
||||
std::cout << "Sound of meta:\t";
|
||||
meta->makeSound();
|
||||
std::cout << std::endl << "Sound of i:\t";
|
||||
i->makeSound();
|
||||
std::cout << std::endl << "Sound of j:\t";
|
||||
j->makeSound();
|
||||
std::cout << std::endl << "Sound of k:\t";
|
||||
k->makeSound();
|
||||
std::cout << std::endl << "Sound of l:\t";
|
||||
l->makeSound();
|
||||
std::cout << std::endl << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl;
|
||||
delete meta;
|
||||
delete j;
|
||||
delete i;
|
||||
delete k;
|
||||
delete l;
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||
delete theClassic;
|
||||
delete theDog;
|
||||
delete theCat;
|
||||
delete theBadAnimal;
|
||||
delete theBadCat;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 17:19:20 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,18 +14,25 @@
|
|||
#include <iostream>
|
||||
|
||||
Animal::Animal() {
|
||||
std::cout << "[Animal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
std::cout << "[Animal]\tCreating Animal class" << std::endl;
|
||||
type = "Animal";
|
||||
}
|
||||
|
||||
Animal::Animal(Animal const & copy) {
|
||||
std::cout << "[Animal]\tCreating Animal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
Animal & Animal::operator=(Animal const & assign) {
|
||||
std::cout << "[Animal]\tCreating Animal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Animal::~Animal() {
|
||||
std::cout << "[Animal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType() const {
|
||||
return (type);
|
||||
std::cout << "[Animal]\tDeleting Animal class" << std::endl;
|
||||
}
|
||||
|
||||
void Animal::makeSound() const {
|
||||
std::cout << "🤔 | thinking how to make a sound" << std::endl;
|
||||
std::cout << "[Animal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:03:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,20 @@
|
|||
#define ANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
public:
|
||||
Animal();
|
||||
virtual ~Animal();
|
||||
Animal(Animal const & copy);
|
||||
Animal & operator=(Animal const & assign);
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
virtual Animal* clone() const = 0;
|
||||
virtual std::string getIdea(int const index) const = 0;
|
||||
virtual void setIdea(int const index, std::string const idea) const = 0;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,27 +5,49 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
Brain::Brain() {
|
||||
std::cout << "[Brain]\t\tCreating Brain class" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
std::ostringstream oss;
|
||||
oss << "I'm thinking about the number " << (i + 1);
|
||||
idea[i] = oss.str();
|
||||
std::stringstream oss;
|
||||
oss << "🧠 | Idea " << (i + 1);
|
||||
ideas[i] = oss.str();
|
||||
}
|
||||
}
|
||||
|
||||
Brain::Brain(Brain const & copy) {
|
||||
std::cout << "[Brain]\t\tCreating Brain class (copy)" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->ideas[i] = std::string(copy.ideas[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Brain& Brain::operator=(Brain const & assign) {
|
||||
if (this != &assign) {
|
||||
std::cout << "[Brain]\t\tCreating Brain class (assign)" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->ideas[i] = std::string(assign.ideas[i]);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Brain::~Brain() {
|
||||
|
||||
std::cout << "[Brain]\t\tDeleting Brain class" << std::endl;
|
||||
}
|
||||
|
||||
Brain& Brain::operator=(Brain &value) {
|
||||
return (value);
|
||||
std::string Brain::getIdea(int index) const {
|
||||
return ideas[index % 100];
|
||||
}
|
||||
|
||||
void Brain::setIdea(int index, std::string idea) {
|
||||
this->ideas[index % 100] = idea;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,17 +15,16 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
class Brain {
|
||||
class Brain {
|
||||
public:
|
||||
Brain();
|
||||
Brain(const Brain ©);
|
||||
Brain& operator=(const Brain &assign);
|
||||
~Brain();
|
||||
std::string idea[100];
|
||||
Brain& operator=(Brain &value);
|
||||
|
||||
protected:
|
||||
|
||||
std::string getIdea(int index) const;
|
||||
void setIdea(int const index, std::string const idea);
|
||||
private:
|
||||
|
||||
std::string ideas[100];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,24 +5,53 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:06:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Cat::Cat() {
|
||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tCreating Cat class" << std::endl;
|
||||
type = "Cat";
|
||||
brain = new Brain();
|
||||
}
|
||||
|
||||
Cat::Cat(Cat const & copy) {
|
||||
std::cout << "[Cat]\t\tCreating Cat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
this->brain = new Brain(*copy.brain);
|
||||
}
|
||||
|
||||
Cat & Cat::operator=(Cat const & assign) {
|
||||
if (this != &assign) {
|
||||
std::cout << "[Cat]\t\tCreating Cat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
for (int i = 0; i < 100; i++)
|
||||
this->brain[i] = assign.brain[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Cat* Cat::clone() const {
|
||||
return new Cat(*this);
|
||||
}
|
||||
|
||||
Cat::~Cat() {
|
||||
delete brain;
|
||||
std::cout << "[Cat]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tDeleting Cat class" << std::endl;
|
||||
}
|
||||
|
||||
void Cat::setIdea(int const index, std::string const idea) const {
|
||||
brain->setIdea(index, idea);
|
||||
}
|
||||
|
||||
std::string Cat::getIdea(int const index) const {
|
||||
return brain->getIdea(index);
|
||||
}
|
||||
|
||||
void Cat::makeSound() const {
|
||||
std::cout << "🐱 | Meow Meow" << std::endl;
|
||||
std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:05:29 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,17 +15,20 @@
|
|||
|
||||
#include "Animal.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <string>
|
||||
|
||||
class Cat : public Animal {
|
||||
public:
|
||||
Cat();
|
||||
~Cat();
|
||||
Cat(Cat const & copy);
|
||||
Cat & operator=(Cat const & assign);
|
||||
virtual void makeSound() const;
|
||||
virtual Cat* clone() const;
|
||||
std::string getIdea(int const index) const;
|
||||
void setIdea(int const index, std::string const idea) const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
Brain *brain;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,25 +5,50 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:07:55 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Dog::Dog() {
|
||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||
type = "Dog";
|
||||
brain = new Brain();
|
||||
}
|
||||
|
||||
Dog::Dog(Dog const & copy) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
this->brain = new Brain();
|
||||
}
|
||||
|
||||
Dog & Dog::operator=(Dog const & assign) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl;
|
||||
(void)assign;
|
||||
this->brain = new Brain();
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string Dog::getIdea(int index) const {
|
||||
return brain->getIdea(index);
|
||||
}
|
||||
|
||||
void Dog::setIdea(int const index, std::string const idea) const {
|
||||
return brain->setIdea(index, idea);
|
||||
}
|
||||
|
||||
Dog* Dog::clone() const {
|
||||
return new Dog(*this);
|
||||
}
|
||||
|
||||
Dog::~Dog() {
|
||||
delete brain;
|
||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tDeleting Dog class" << std::endl;
|
||||
}
|
||||
|
||||
void Dog::makeSound() const {
|
||||
std::cout << "🐶 | Wouf Wouf" << std::endl;
|
||||
std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:07:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,18 +15,20 @@
|
|||
|
||||
#include "Animal.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <string>
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
||||
Dog();
|
||||
~Dog();
|
||||
Dog(Dog const & copy);
|
||||
Dog & operator=(Dog const & assign);
|
||||
virtual void makeSound() const;
|
||||
std::string getIdea(int const index) const;
|
||||
void setIdea(int const index, std::string const idea) const;
|
||||
Dog* clone() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
Brain *brain;
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
# **************************************************************************** #
|
||||
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr #
|
||||
# Updated: 2025/02/18 17:11:17 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Variables
|
||||
|
||||
# Name
|
||||
NAME = polyformism
|
||||
NAME = open
|
||||
|
||||
# Commands
|
||||
CXX = c++
|
||||
RM = rm -rf
|
||||
|
||||
# Flags
|
||||
# Mandatory flags for 42
|
||||
# Mandatory flags for 42 cpp
|
||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||
# Flags to debug and have the dependences (can be removed for correction)
|
||||
CXXFLAGS += -MMD -g3
|
||||
# Flag to debug (TO REMOVE)
|
||||
# CXXFLAGS += -D DEBUG=1
|
||||
# Sources
|
||||
SRC = Animal.cpp \
|
||||
SRC = main.cpp \
|
||||
Brain.cpp \
|
||||
Cat.cpp \
|
||||
Dog.cpp \
|
||||
WrongAnimal.cpp \
|
||||
WrongCat.cpp \
|
||||
main.cpp \
|
||||
WrongAnimal.cpp \
|
||||
Dog.cpp \
|
||||
Animal.cpp \
|
||||
Cat.cpp
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ./build
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,18 +14,25 @@
|
|||
#include <iostream>
|
||||
|
||||
WrongAnimal::WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||
type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(WrongAnimal const & copy) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType() const {
|
||||
return (type);
|
||||
std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound() const {
|
||||
std::cout << "🦊 | What does the fox say ?" << std::endl;
|
||||
std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,17 @@
|
|||
#define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
public:
|
||||
WrongAnimal();
|
||||
virtual ~WrongAnimal();
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
WrongAnimal(WrongAnimal const & copy);
|
||||
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||
void makeSound() const;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,22 +5,34 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
WrongCat::WrongCat() {
|
||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl;
|
||||
type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(WrongCat const & copy) {
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongCat & WrongCat::operator=(WrongCat const & assign) {
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat() {
|
||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
||||
std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound() const {
|
||||
std::cout << "🙀 | Help me I transform my self in cat" << std::endl;
|
||||
std::cout << "[WrongCat]\t🐱 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,16 @@
|
|||
#define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
#include <string>
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public:
|
||||
WrongCat();
|
||||
~WrongCat();
|
||||
WrongCat(WrongCat const & copy);
|
||||
WrongCat & operator=(WrongCat const & assign);
|
||||
virtual void makeSound() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
47
cpp04/ex01/color.hpp
Normal file
47
cpp04/ex01/color.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef COLOR_HPP
|
||||
#define COLOR_HPP
|
||||
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define BLACK "\033[0;30m"
|
||||
#define RED "\033[0;31m"
|
||||
#define GREEN "\033[0;32m"
|
||||
#define YELLOW "\033[0;33m"
|
||||
#define BLUE "\033[0;34m"
|
||||
#define MAGENTA "\033[0;35m"
|
||||
#define CYAN "\033[0;36m"
|
||||
#define WHITE "\033[0;37m"
|
||||
#define GOLD "\033[38;5;220m"
|
||||
#define GREY "\033[38;5;240m"
|
||||
|
||||
#define L_BLACK "\033[0;90m"
|
||||
#define L_RED "\033[0;91m"
|
||||
#define L_GREEN "\033[0;92m"
|
||||
#define L_YELLOW "\033[0;93m"
|
||||
#define L_BLUE "\033[0;94m"
|
||||
#define L_MAGENTA "\033[0;95m"
|
||||
#define L_CYAN "\033[0;96m"
|
||||
#define L_WHITE "\033[0;97m"
|
||||
|
||||
#define B_BLACK "\033[1;30m"
|
||||
#define B_RED "\033[1;31m"
|
||||
#define B_GREEN "\033[1;32m"
|
||||
#define B_YELLOW "\033[1;33m"
|
||||
#define B_BLUE "\033[1;34m"
|
||||
#define B_MAGENTA "\033[1;35m"
|
||||
#define B_CYAN "\033[1;36m"
|
||||
#define B_WHITE "\033[1;37m"
|
||||
|
||||
#endif
|
||||
|
|
@ -5,47 +5,67 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:09:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
#include "color.hpp"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
int main() {
|
||||
const unsigned int n = 42;
|
||||
if (n % 2 != 0) {
|
||||
std::cerr << "n must be an even number, if not i can't create the same number of Cat and Animal" << std::endl;
|
||||
return (1);
|
||||
const int nb = 42;
|
||||
|
||||
if (nb % 2 != 0) {
|
||||
std::cerr << RED << "Error: Please enter an odd number." << RESET << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (nb < 0) {
|
||||
std::cerr << RED << "Error: Please enter a positive number." << RESET << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl;
|
||||
Animal *animals[n];
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
if (i % 2 == 0) {
|
||||
animals[i] = new Dog();
|
||||
} else {
|
||||
animals[i] = new Cat();
|
||||
}
|
||||
Animal *tab[nb];
|
||||
|
||||
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||
if (i % 2 == 0)
|
||||
tab[i] = new Dog();
|
||||
else
|
||||
tab[i] = new Cat();
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl;
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
animals[i]->makeSound();
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET;
|
||||
tab[i]->makeSound();
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl;
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
delete animals[i];
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||
delete tab[i];
|
||||
}
|
||||
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Brains deepCopy ]" << RESET << std::endl;
|
||||
Animal *cat = new Cat();
|
||||
Animal *newCat;
|
||||
|
||||
newCat = cat->clone();
|
||||
std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
cat->setIdea(41, "🧠 | New Idea");
|
||||
std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
std::cout << newCat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
|
||||
delete cat;
|
||||
delete newCat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
38
cpp04/ex02/AAnimal.cpp
Normal file
38
cpp04/ex02/AAnimal.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:10:59 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "AAnimal.hpp"
|
||||
#include <iostream>
|
||||
|
||||
AAnimal::AAnimal() {
|
||||
std::cout << "[AAnimal]\tCreating AAnimal class" << std::endl;
|
||||
type = "AAnimal";
|
||||
}
|
||||
|
||||
AAnimal::AAnimal(AAnimal const & copy) {
|
||||
std::cout << "[AAnimal]\tCreating AAnimal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
AAnimal & AAnimal::operator=(AAnimal const & assign) {
|
||||
std::cout << "[AAnimal]\tCreating AAnimal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
AAnimal::~AAnimal() {
|
||||
std::cout << "[AAnimal]\tDeleting AAnimal class" << std::endl;
|
||||
}
|
||||
|
||||
void AAnimal::makeSound() const {
|
||||
std::cout << "[AAnimal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
@ -1,30 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* AAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:14:43 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef ANIMAL_HPP
|
||||
#define ANIMAL_HPP
|
||||
#ifndef AAnimal_HPP
|
||||
#define AAnimal_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class Animal {
|
||||
class AAnimal {
|
||||
public:
|
||||
Animal();
|
||||
virtual ~Animal();
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
AAnimal();
|
||||
virtual ~AAnimal();
|
||||
AAnimal(AAnimal const & copy);
|
||||
AAnimal & operator=(AAnimal const & assign);
|
||||
virtual void makeSound() const = 0;
|
||||
virtual AAnimal* clone() const = 0;
|
||||
virtual std::string getIdea(int const index) const = 0;
|
||||
virtual void setIdea(int const index, std::string const idea) const = 0;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Animal::Animal() {
|
||||
std::cout << "[Animal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
}
|
||||
|
||||
Animal::~Animal() {
|
||||
std::cout << "[Animal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string Animal::getType() const {
|
||||
return (type);
|
||||
}
|
||||
|
||||
void Animal::makeSound() const {
|
||||
std::cout << "🤔 | thinking how to make a sound" << std::endl;
|
||||
}
|
||||
|
|
@ -5,27 +5,49 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
Brain::Brain() {
|
||||
std::cout << "[Brain]\t\tCreating Brain class" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
std::ostringstream oss;
|
||||
oss << "I'm thinking about the number " << (i + 1);
|
||||
idea[i] = oss.str();
|
||||
std::stringstream oss;
|
||||
oss << "🧠 | Idea " << (i + 1);
|
||||
ideas[i] = oss.str();
|
||||
}
|
||||
}
|
||||
|
||||
Brain::Brain(Brain const & copy) {
|
||||
std::cout << "[Brain]\t\tCreating Brain class (copy)" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->ideas[i] = std::string(copy.ideas[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Brain& Brain::operator=(Brain const & assign) {
|
||||
if (this != &assign) {
|
||||
std::cout << "[Brain]\t\tCreating Brain class (assign)" << std::endl;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
this->ideas[i] = std::string(assign.ideas[i]);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Brain::~Brain() {
|
||||
|
||||
std::cout << "[Brain]\t\tDeleting Brain class" << std::endl;
|
||||
}
|
||||
|
||||
Brain& Brain::operator=(Brain &value) {
|
||||
return (value);
|
||||
std::string Brain::getIdea(int index) const {
|
||||
return ideas[index % 100];
|
||||
}
|
||||
|
||||
void Brain::setIdea(int index, std::string idea) {
|
||||
this->ideas[index % 100] = idea;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,17 +15,16 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
class Brain {
|
||||
class Brain {
|
||||
public:
|
||||
Brain();
|
||||
Brain(const Brain ©);
|
||||
Brain& operator=(const Brain &assign);
|
||||
~Brain();
|
||||
std::string idea[100];
|
||||
Brain& operator=(Brain &value);
|
||||
|
||||
protected:
|
||||
|
||||
std::string getIdea(int index) const;
|
||||
void setIdea(int const index, std::string const idea);
|
||||
private:
|
||||
|
||||
std::string ideas[100];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,24 +5,54 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:14:10 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Cat::Cat() {
|
||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tCreating Cat class" << std::endl;
|
||||
type = "Cat";
|
||||
brain = new Brain();
|
||||
}
|
||||
|
||||
Cat::Cat(Cat const & copy) {
|
||||
std::cout << "[Cat]\t\tCreating Cat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
this->brain = new Brain(*copy.brain);
|
||||
}
|
||||
|
||||
Cat & Cat::operator=(Cat const & assign) {
|
||||
if (this != &assign) {
|
||||
std::cout << "[Cat]\t\tCreating Cat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
for (int i = 0; i < 100; i++)
|
||||
this->brain[i] = assign.brain[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Cat* Cat::clone() const {
|
||||
std::cout << "[Cat]\t\tCopying Cat class (DeepCopy)" << std::endl;
|
||||
return new Cat(*this);
|
||||
}
|
||||
|
||||
Cat::~Cat() {
|
||||
delete brain;
|
||||
std::cout << "[Cat]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Cat]\t\tDeleting Cat class" << std::endl;
|
||||
}
|
||||
|
||||
void Cat::setIdea(int const index, std::string const idea) const {
|
||||
brain->setIdea(index, idea);
|
||||
}
|
||||
|
||||
std::string Cat::getIdea(int const index) const {
|
||||
return brain->getIdea(index);
|
||||
}
|
||||
|
||||
void Cat::makeSound() const {
|
||||
std::cout << "🐱 | Meow Meow" << std::endl;
|
||||
std::cout << "[Cat]\t\t🐱 | Meow meow" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,27 +5,30 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:11:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef CAT_HPP
|
||||
#define CAT_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "AAnimal.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <string>
|
||||
|
||||
class Cat : public Animal {
|
||||
class Cat : public AAnimal {
|
||||
public:
|
||||
Cat();
|
||||
~Cat();
|
||||
Cat(Cat const & copy);
|
||||
Cat & operator=(Cat const & assign);
|
||||
virtual void makeSound() const;
|
||||
virtual Cat* clone() const;
|
||||
std::string getIdea(int const index) const;
|
||||
void setIdea(int const index, std::string const idea) const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
Brain *brain;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,25 +5,51 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:13:30 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Dog::Dog() {
|
||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||
type = "Dog";
|
||||
brain = new Brain();
|
||||
}
|
||||
|
||||
Dog::Dog(Dog const & copy) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
this->brain = new Brain();
|
||||
}
|
||||
|
||||
Dog & Dog::operator=(Dog const & assign) {
|
||||
std::cout << "[Dog]\t\tCreating Dog class (assign)" << std::endl;
|
||||
(void)assign;
|
||||
this->brain = new Brain();
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string Dog::getIdea(int index) const {
|
||||
return brain->getIdea(index);
|
||||
}
|
||||
|
||||
void Dog::setIdea(int const index, std::string const idea) const {
|
||||
return brain->setIdea(index, idea);
|
||||
}
|
||||
|
||||
Dog* Dog::clone() const {
|
||||
std::cout << "[Dog]\t\tCopying Dog class (DeepCopy)" << std::endl;
|
||||
return new Dog(*this);
|
||||
}
|
||||
|
||||
Dog::~Dog() {
|
||||
delete brain;
|
||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
||||
std::cout << "[Dog]\t\tDeleting Dog class" << std::endl;
|
||||
}
|
||||
|
||||
void Dog::makeSound() const {
|
||||
std::cout << "🐶 | Wouf Wouf" << std::endl;
|
||||
std::cout << "[Dog]\t\t🐶 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,28 +5,30 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:11:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DOG_HPP
|
||||
#define DOG_HPP
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "AAnimal.hpp"
|
||||
#include "Brain.hpp"
|
||||
#include <string>
|
||||
|
||||
class Dog : public Animal {
|
||||
class Dog : public AAnimal {
|
||||
public:
|
||||
Dog();
|
||||
~Dog();
|
||||
Dog(Dog const & copy);
|
||||
Dog & operator=(Dog const & assign);
|
||||
virtual void makeSound() const;
|
||||
std::string getIdea(int const index) const;
|
||||
void setIdea(int const index, std::string const idea) const;
|
||||
Dog* clone() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
Brain *brain;
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,38 +1,39 @@
|
|||
# **************************************************************************** #
|
||||
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr #
|
||||
# Updated: 2025/02/18 20:12:03 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
# Variables
|
||||
|
||||
# Name
|
||||
NAME = polyformism
|
||||
NAME = open
|
||||
|
||||
# Commands
|
||||
CXX = c++
|
||||
RM = rm -rf
|
||||
|
||||
# Flags
|
||||
# Mandatory flags for 42
|
||||
# Mandatory flags for 42 cpp
|
||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||
# Flags to debug and have the dependences (can be removed for correction)
|
||||
CXXFLAGS += -MMD -g3
|
||||
# Flag to debug (TO REMOVE)
|
||||
# CXXFLAGS += -D DEBUG=1
|
||||
# Sources
|
||||
SRC = Animal.cpp \
|
||||
SRC = main.cpp \
|
||||
Brain.cpp \
|
||||
Cat.cpp \
|
||||
Dog.cpp \
|
||||
WrongAnimal.cpp \
|
||||
WrongCat.cpp \
|
||||
main.cpp \
|
||||
WrongAnimal.cpp \
|
||||
Dog.cpp \
|
||||
AAnimal.cpp \
|
||||
Cat.cpp
|
||||
|
||||
# Objects
|
||||
OBJDIRNAME = ./build
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,18 +14,25 @@
|
|||
#include <iostream>
|
||||
|
||||
WrongAnimal::WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
||||
type = "";
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||
type = "WrongAnimal";
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(WrongAnimal const & copy) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongAnimal & WrongAnimal::operator=(WrongAnimal const & assign) {
|
||||
std::cout << "[WrongAnimal]\tCreating WrongAnimal class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal() {
|
||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType() const {
|
||||
return (type);
|
||||
std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound() const {
|
||||
std::cout << "🦊 | What does the fox say ?" << std::endl;
|
||||
std::cout << "[WrongAnimal]\t🦊 | What does the fox say ?" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,17 @@
|
|||
#define WRONGANIMAL_HPP
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class WrongAnimal {
|
||||
public:
|
||||
WrongAnimal();
|
||||
virtual ~WrongAnimal();
|
||||
virtual void makeSound() const;
|
||||
std::string getType() const;
|
||||
WrongAnimal(WrongAnimal const & copy);
|
||||
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||
void makeSound() const;
|
||||
|
||||
protected:
|
||||
std::string type;
|
||||
private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -5,22 +5,34 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
#include <iostream>
|
||||
|
||||
WrongCat::WrongCat() {
|
||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl;
|
||||
type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(WrongCat const & copy) {
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class (copy)" << std::endl;
|
||||
this->type = copy.type;
|
||||
}
|
||||
|
||||
WrongCat & WrongCat::operator=(WrongCat const & assign) {
|
||||
std::cout << "[WrongCat]\tCreating WrongCat class (assign)" << std::endl;
|
||||
this->type = assign.type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat() {
|
||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
||||
std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl;
|
||||
}
|
||||
|
||||
void WrongCat::makeSound() const {
|
||||
std::cout << "🙀 | Help me I transform my self in cat" << std::endl;
|
||||
std::cout << "[WrongCat]\t🐱 | Wouf wouf" << std::endl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
||||
/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,17 +14,16 @@
|
|||
#define WRONGCAT_HPP
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
#include <string>
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public:
|
||||
WrongCat();
|
||||
~WrongCat();
|
||||
WrongCat(WrongCat const & copy);
|
||||
WrongCat & operator=(WrongCat const & assign);
|
||||
virtual void makeSound() const;
|
||||
protected:
|
||||
|
||||
private:
|
||||
|
||||
std::string type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
47
cpp04/ex02/color.hpp
Normal file
47
cpp04/ex02/color.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/17 15:27:54 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 16:43:18 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef COLOR_HPP
|
||||
#define COLOR_HPP
|
||||
|
||||
#define RESET "\033[0m"
|
||||
|
||||
#define BLACK "\033[0;30m"
|
||||
#define RED "\033[0;31m"
|
||||
#define GREEN "\033[0;32m"
|
||||
#define YELLOW "\033[0;33m"
|
||||
#define BLUE "\033[0;34m"
|
||||
#define MAGENTA "\033[0;35m"
|
||||
#define CYAN "\033[0;36m"
|
||||
#define WHITE "\033[0;37m"
|
||||
#define GOLD "\033[38;5;220m"
|
||||
#define GREY "\033[38;5;240m"
|
||||
|
||||
#define L_BLACK "\033[0;90m"
|
||||
#define L_RED "\033[0;91m"
|
||||
#define L_GREEN "\033[0;92m"
|
||||
#define L_YELLOW "\033[0;93m"
|
||||
#define L_BLUE "\033[0;94m"
|
||||
#define L_MAGENTA "\033[0;95m"
|
||||
#define L_CYAN "\033[0;96m"
|
||||
#define L_WHITE "\033[0;97m"
|
||||
|
||||
#define B_BLACK "\033[1;30m"
|
||||
#define B_RED "\033[1;31m"
|
||||
#define B_GREEN "\033[1;32m"
|
||||
#define B_YELLOW "\033[1;33m"
|
||||
#define B_BLUE "\033[1;34m"
|
||||
#define B_MAGENTA "\033[1;35m"
|
||||
#define B_CYAN "\033[1;36m"
|
||||
#define B_WHITE "\033[1;37m"
|
||||
|
||||
#endif
|
||||
|
|
@ -5,47 +5,65 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */
|
||||
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||
/* Updated: 2025/02/18 20:12:27 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "AAnimal.hpp"
|
||||
#include "Cat.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "WrongCat.hpp"
|
||||
#include "Dog.hpp"
|
||||
#include "color.hpp"
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
int main() {
|
||||
const unsigned int n = 42;
|
||||
if (n % 2 != 0) {
|
||||
std::cerr << "n must be an even number, if not i can't create the same number of Cat and Animal" << std::endl;
|
||||
return (1);
|
||||
const int nb = 42;
|
||||
|
||||
if (nb % 2 != 0) {
|
||||
std::cerr << RED << "Error: Please enter an odd number." << RESET << std::endl;
|
||||
return 1;
|
||||
}
|
||||
if (nb < 0) {
|
||||
std::cerr << RED << "Error: Please enter a positive number." << RESET << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl;
|
||||
Animal *animals[n];
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
if (i % 2 == 0) {
|
||||
animals[i] = new Dog();
|
||||
} else {
|
||||
animals[i] = new Cat();
|
||||
}
|
||||
AAnimal *tab[nb];
|
||||
|
||||
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||
if (i % 2 == 0)
|
||||
tab[i] = new Dog();
|
||||
else
|
||||
tab[i] = new Cat();
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl;
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
animals[i]->makeSound();
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET;
|
||||
tab[i]->makeSound();
|
||||
}
|
||||
|
||||
std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl;
|
||||
for (unsigned int i = 0; i < n; i++) {
|
||||
std::cout << "(" << i + 1 << ") ";
|
||||
delete animals[i];
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||
for (int i = 0; i < nb && i < nb; i++) {
|
||||
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||
delete tab[i];
|
||||
}
|
||||
|
||||
std::cout << std::endl << YELLOW << "\t\t[ Brains deepCopy ]" << RESET << std::endl;
|
||||
AAnimal *cat = new Cat();
|
||||
AAnimal *newCat;
|
||||
|
||||
newCat = cat->clone();
|
||||
std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
cat->setIdea(41, "🧠 | New Idea");
|
||||
std::cout << cat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
std::cout << newCat->getIdea(41) << " "<< __LINE__ << std::endl;
|
||||
|
||||
delete cat;
|
||||
delete newCat;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue