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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:51:30 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,18 +14,25 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Animal::Animal() {
|
Animal::Animal() {
|
||||||
std::cout << "[Animal]\tCreating the class" << std::endl;
|
std::cout << "[Animal]\tCreating Animal class" << std::endl;
|
||||||
type = "";
|
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() {
|
Animal::~Animal() {
|
||||||
std::cout << "[Animal]\tDeleting the class" << std::endl;
|
std::cout << "[Animal]\tDeleting animal class" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::string Animal::getType() const {
|
|
||||||
return (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animal::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:24:40 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,17 @@
|
||||||
#define ANIMAL_HPP
|
#define ANIMAL_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class Animal {
|
class Animal {
|
||||||
public:
|
public:
|
||||||
Animal();
|
Animal();
|
||||||
virtual ~Animal();
|
virtual ~Animal();
|
||||||
|
Animal(Animal const & copy);
|
||||||
|
Animal & operator=(Animal const & assign);
|
||||||
virtual void makeSound() const;
|
virtual void makeSound() const;
|
||||||
std::string getType() const;
|
|
||||||
protected:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,34 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:03 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:41:28 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Cat::Cat() {
|
Cat::Cat() {
|
||||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
std::cout << "[Cat]\t\tCreating cat class" << std::endl;
|
||||||
type = "Cat";
|
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() {
|
Cat::~Cat() {
|
||||||
std::cout << "[Cat]\t\tDeleting the class" << std::endl;
|
std::cout << "[Cat]\t\tDeleting cat class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cat::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 18:24:18 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:26:01 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,16 @@
|
||||||
#define CAT_HPP
|
#define CAT_HPP
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Cat : public Animal {
|
class Cat : public Animal {
|
||||||
public:
|
public:
|
||||||
Cat();
|
Cat();
|
||||||
~Cat();
|
~Cat();
|
||||||
|
Cat(Cat const & copy);
|
||||||
|
Cat & operator=(Cat const & assign);
|
||||||
virtual void makeSound() const;
|
virtual void makeSound() const;
|
||||||
protected:
|
protected:
|
||||||
|
std::string type;
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,34 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:53:02 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:51:41 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Dog.hpp"
|
#include "Dog.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Dog::Dog() {
|
Dog::Dog() {
|
||||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||||
type = "Dog";
|
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() {
|
Dog::~Dog() {
|
||||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
std::cout << "[Dog]\t\tDeleting dog class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dog::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 18:24:07 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:27:11 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,16 @@
|
||||||
#define DOG_HPP
|
#define DOG_HPP
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Dog : public Animal {
|
class Dog : public Animal {
|
||||||
public:
|
public:
|
||||||
Dog();
|
Dog();
|
||||||
~Dog();
|
~Dog();
|
||||||
|
Dog(Dog const & copy);
|
||||||
|
Dog & operator=(Dog const & assign);
|
||||||
virtual void makeSound() const;
|
virtual void makeSound() const;
|
||||||
protected:
|
protected:
|
||||||
|
std::string type;
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,38 @@
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
# ::: :::::::: #
|
# ::: :::::::: #
|
||||||
# Makefile :+: :+: :+: #
|
# Makefile :+: :+: :+: #
|
||||||
# +:+ +:+ +:+ #
|
# +:+ +:+ +:+ #
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# 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
|
# Variables
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
NAME = polymorphism
|
NAME = open
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
CXX = c++
|
CXX = c++
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
# Mandatory flags for 42
|
# Mandatory flags for 42 cpp
|
||||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
# Flags to debug and have the dependences (can be removed for correction)
|
# Flags to debug and have the dependences (can be removed for correction)
|
||||||
CXXFLAGS += -MMD -g3
|
CXXFLAGS += -MMD -g3
|
||||||
|
# Flag to debug (TO REMOVE)
|
||||||
|
# CXXFLAGS += -D DEBUG=1
|
||||||
# Sources
|
# Sources
|
||||||
SRC = Animal.cpp \
|
SRC = main.cpp \
|
||||||
Cat.cpp \
|
|
||||||
Dog.cpp \
|
|
||||||
WrongAnimal.cpp \
|
|
||||||
WrongCat.cpp \
|
WrongCat.cpp \
|
||||||
main.cpp
|
WrongAnimal.cpp \
|
||||||
|
Dog.cpp \
|
||||||
|
Animal.cpp \
|
||||||
|
Cat.cpp
|
||||||
|
|
||||||
# Objects
|
# Objects
|
||||||
OBJDIRNAME = ./build
|
OBJDIRNAME = ./build
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:50:06 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,18 +14,25 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
WrongAnimal::WrongAnimal() {
|
WrongAnimal::WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||||
type = "";
|
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() {
|
WrongAnimal::~WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
std::cout << "[WrongAnimal]\tDeleting cat class" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::string WrongAnimal::getType() const {
|
|
||||||
return (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WrongAnimal::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,17 @@
|
||||||
#define WRONGANIMAL_HPP
|
#define WRONGANIMAL_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class WrongAnimal {
|
class WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongAnimal();
|
WrongAnimal();
|
||||||
virtual ~WrongAnimal();
|
virtual ~WrongAnimal();
|
||||||
virtual void makeSound() const;
|
WrongAnimal(WrongAnimal const & copy);
|
||||||
std::string getType() const;
|
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||||
|
void makeSound() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,34 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:48:59 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:53:06 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "WrongCat.hpp"
|
#include "WrongCat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
WrongCat::WrongCat() {
|
WrongCat::WrongCat() {
|
||||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
std::cout << "[WrongCat]\t\tCreating WrongCat class" << std::endl;
|
||||||
type = "WrongCat";
|
type = "WrongCat";
|
||||||
}
|
}
|
||||||
|
|
||||||
WrongCat::~WrongCat() {
|
WrongCat::WrongCat(WrongCat const & copy) {
|
||||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:49:13 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,16 +14,16 @@
|
||||||
#define WRONGCAT_HPP
|
#define WRONGCAT_HPP
|
||||||
|
|
||||||
#include "WrongAnimal.hpp"
|
#include "WrongAnimal.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class WrongCat : public WrongAnimal {
|
class WrongCat : public WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongCat();
|
WrongCat();
|
||||||
~WrongCat();
|
~WrongCat();
|
||||||
|
WrongCat(WrongCat const & copy);
|
||||||
|
WrongCat & operator=(WrongCat const & assign);
|
||||||
|
virtual void makeSound() const;
|
||||||
protected:
|
protected:
|
||||||
|
std::string type;
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:52:09 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:48:50 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include "Dog.hpp"
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
|
#include "Dog.hpp"
|
||||||
#include "WrongAnimal.hpp"
|
#include "WrongAnimal.hpp"
|
||||||
#include "WrongCat.hpp"
|
#include "WrongCat.hpp"
|
||||||
|
#include "color.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "\033[0;33m[ Building classes ]\033[0m" << std::endl;
|
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||||
const Animal* meta = new Animal();
|
const Animal* theClassic = new Animal();
|
||||||
const Animal* j = new Dog();
|
const Animal* theDog = new Dog();
|
||||||
const Animal* i = new Cat();
|
const Animal* theCat = new Cat();
|
||||||
const WrongAnimal* k = new WrongAnimal();
|
const WrongAnimal* theBadAnimal = new WrongAnimal();
|
||||||
const WrongAnimal* l = new WrongCat();
|
const WrongAnimal* theBadCat = new WrongCat();
|
||||||
|
|
||||||
std::cout << std::endl << "\033[0;33m[ Testing the getType method ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||||
std::cout << "Type of j:\t" << j->getType() << std::endl;
|
theClassic->makeSound();
|
||||||
std::cout << "Type of i:\t" << i->getType() << std::endl;
|
theDog->makeSound();
|
||||||
std::cout << "Type of l:\t" << l->getType() << std::endl;
|
theCat->makeSound();
|
||||||
|
theBadAnimal->makeSound();
|
||||||
|
theBadCat->makeSound();
|
||||||
|
|
||||||
std::cout << std::endl << "\033[0;33m[ Testing the makeSound method ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||||
std::cout << "Sound of meta:\t";
|
delete theClassic;
|
||||||
meta->makeSound();
|
delete theDog;
|
||||||
std::cout << std::endl << "Sound of i:\t";
|
delete theCat;
|
||||||
i->makeSound();
|
delete theBadAnimal;
|
||||||
std::cout << std::endl << "Sound of j:\t";
|
delete theBadCat;
|
||||||
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;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:53:47 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 17:19:20 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,18 +14,25 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Animal::Animal() {
|
Animal::Animal() {
|
||||||
std::cout << "[Animal]\tCreating the class" << std::endl;
|
std::cout << "[Animal]\tCreating Animal class" << std::endl;
|
||||||
type = "";
|
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() {
|
Animal::~Animal() {
|
||||||
std::cout << "[Animal]\tDeleting the class" << std::endl;
|
std::cout << "[Animal]\tDeleting Animal class" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::string Animal::getType() const {
|
|
||||||
return (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animal::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:03:00 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,20 @@
|
||||||
#define ANIMAL_HPP
|
#define ANIMAL_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class Animal {
|
class Animal {
|
||||||
public:
|
public:
|
||||||
Animal();
|
Animal();
|
||||||
virtual ~Animal();
|
virtual ~Animal();
|
||||||
|
Animal(Animal const & copy);
|
||||||
|
Animal & operator=(Animal const & assign);
|
||||||
virtual void makeSound() const;
|
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:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,49 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
Brain::Brain() {
|
Brain::Brain() {
|
||||||
|
std::cout << "[Brain]\t\tCreating Brain class" << std::endl;
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
std::ostringstream oss;
|
std::stringstream oss;
|
||||||
oss << "I'm thinking about the number " << (i + 1);
|
oss << "🧠 | Idea " << (i + 1);
|
||||||
idea[i] = oss.str();
|
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() {
|
Brain::~Brain() {
|
||||||
|
std::cout << "[Brain]\t\tDeleting Brain class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Brain& Brain::operator=(Brain &value) {
|
std::string Brain::getIdea(int index) const {
|
||||||
return (value);
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,17 +15,16 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Brain {
|
class Brain {
|
||||||
public:
|
public:
|
||||||
Brain();
|
Brain();
|
||||||
|
Brain(const Brain ©);
|
||||||
|
Brain& operator=(const Brain &assign);
|
||||||
~Brain();
|
~Brain();
|
||||||
std::string idea[100];
|
std::string getIdea(int index) const;
|
||||||
Brain& operator=(Brain &value);
|
void setIdea(int const index, std::string const idea);
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string ideas[100];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,53 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:06:18 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Cat::Cat() {
|
Cat::Cat() {
|
||||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
std::cout << "[Cat]\t\tCreating Cat class" << std::endl;
|
||||||
type = "Cat";
|
type = "Cat";
|
||||||
brain = new Brain();
|
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() {
|
Cat::~Cat() {
|
||||||
delete brain;
|
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 {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:05:29 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,17 +15,20 @@
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Cat : public Animal {
|
class Cat : public Animal {
|
||||||
public:
|
public:
|
||||||
Cat();
|
Cat();
|
||||||
~Cat();
|
~Cat();
|
||||||
|
Cat(Cat const & copy);
|
||||||
|
Cat & operator=(Cat const & assign);
|
||||||
virtual void makeSound() const;
|
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:
|
protected:
|
||||||
|
|
||||||
private:
|
|
||||||
Brain *brain;
|
Brain *brain;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,50 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:07:55 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Dog.hpp"
|
#include "Dog.hpp"
|
||||||
#include "Brain.hpp"
|
#include <iostream>
|
||||||
|
|
||||||
Dog::Dog() {
|
Dog::Dog() {
|
||||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||||
type = "Dog";
|
type = "Dog";
|
||||||
brain = new Brain();
|
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() {
|
Dog::~Dog() {
|
||||||
delete brain;
|
delete brain;
|
||||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
std::cout << "[Dog]\t\tDeleting Dog class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dog::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:07:56 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,18 +15,20 @@
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Dog : public Animal {
|
class Dog : public Animal {
|
||||||
public:
|
public:
|
||||||
Dog();
|
Dog();
|
||||||
~Dog();
|
~Dog();
|
||||||
|
Dog(Dog const & copy);
|
||||||
|
Dog & operator=(Dog const & assign);
|
||||||
virtual void makeSound() const;
|
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:
|
protected:
|
||||||
|
|
||||||
private:
|
|
||||||
Brain *brain;
|
Brain *brain;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,39 @@
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
# ::: :::::::: #
|
# ::: :::::::: #
|
||||||
# Makefile :+: :+: :+: #
|
# Makefile :+: :+: :+: #
|
||||||
# +:+ +:+ +:+ #
|
# +:+ +:+ +:+ #
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# 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
|
# Variables
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
NAME = polyformism
|
NAME = open
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
CXX = c++
|
CXX = c++
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
# Mandatory flags for 42
|
# Mandatory flags for 42 cpp
|
||||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
# Flags to debug and have the dependences (can be removed for correction)
|
# Flags to debug and have the dependences (can be removed for correction)
|
||||||
CXXFLAGS += -MMD -g3
|
CXXFLAGS += -MMD -g3
|
||||||
# Flag to debug (TO REMOVE)
|
# Flag to debug (TO REMOVE)
|
||||||
# CXXFLAGS += -D DEBUG=1
|
# CXXFLAGS += -D DEBUG=1
|
||||||
# Sources
|
# Sources
|
||||||
SRC = Animal.cpp \
|
SRC = main.cpp \
|
||||||
Brain.cpp \
|
Brain.cpp \
|
||||||
Cat.cpp \
|
|
||||||
Dog.cpp \
|
|
||||||
WrongAnimal.cpp \
|
|
||||||
WrongCat.cpp \
|
WrongCat.cpp \
|
||||||
main.cpp \
|
WrongAnimal.cpp \
|
||||||
|
Dog.cpp \
|
||||||
|
Animal.cpp \
|
||||||
|
Cat.cpp
|
||||||
|
|
||||||
# Objects
|
# Objects
|
||||||
OBJDIRNAME = ./build
|
OBJDIRNAME = ./build
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,18 +14,25 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
WrongAnimal::WrongAnimal() {
|
WrongAnimal::WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||||
type = "";
|
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() {
|
WrongAnimal::~WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::string WrongAnimal::getType() const {
|
|
||||||
return (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WrongAnimal::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,17 @@
|
||||||
#define WRONGANIMAL_HPP
|
#define WRONGANIMAL_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class WrongAnimal {
|
class WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongAnimal();
|
WrongAnimal();
|
||||||
virtual ~WrongAnimal();
|
virtual ~WrongAnimal();
|
||||||
virtual void makeSound() const;
|
WrongAnimal(WrongAnimal const & copy);
|
||||||
std::string getType() const;
|
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||||
|
void makeSound() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,34 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "WrongCat.hpp"
|
#include "WrongCat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
WrongCat::WrongCat() {
|
WrongCat::WrongCat() {
|
||||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl;
|
||||||
type = "WrongCat";
|
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() {
|
WrongCat::~WrongCat() {
|
||||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WrongCat::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,16 @@
|
||||||
#define WRONGCAT_HPP
|
#define WRONGCAT_HPP
|
||||||
|
|
||||||
#include "WrongAnimal.hpp"
|
#include "WrongAnimal.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class WrongCat : public WrongAnimal {
|
class WrongCat : public WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongCat();
|
WrongCat();
|
||||||
~WrongCat();
|
~WrongCat();
|
||||||
|
WrongCat(WrongCat const & copy);
|
||||||
|
WrongCat & operator=(WrongCat const & assign);
|
||||||
virtual void makeSound() const;
|
virtual void makeSound() const;
|
||||||
protected:
|
protected:
|
||||||
|
std::string type;
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:09:18 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "Animal.hpp"
|
||||||
#include "Dog.hpp"
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
|
#include "Dog.hpp"
|
||||||
#include "WrongAnimal.hpp"
|
#include "WrongAnimal.hpp"
|
||||||
#include "WrongCat.hpp"
|
#include "WrongCat.hpp"
|
||||||
|
#include "color.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const unsigned int n = 42;
|
const int nb = 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;
|
if (nb % 2 != 0) {
|
||||||
return (1);
|
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 *tab[nb];
|
||||||
Animal *animals[n];
|
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||||
std::cout << "(" << i + 1 << ") ";
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
if (i % 2 == 0) {
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||||
animals[i] = new Dog();
|
if (i % 2 == 0)
|
||||||
} else {
|
tab[i] = new Dog();
|
||||||
animals[i] = new Cat();
|
else
|
||||||
}
|
tab[i] = new Cat();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
std::cout << "(" << i + 1 << ") ";
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET;
|
||||||
animals[i]->makeSound();
|
tab[i]->makeSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
std::cout << "(" << i + 1 << ") ";
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||||
delete animals[i];
|
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;
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:23:05 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:14:43 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef ANIMAL_HPP
|
#ifndef AAnimal_HPP
|
||||||
#define ANIMAL_HPP
|
#define AAnimal_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class Animal {
|
class AAnimal {
|
||||||
public:
|
public:
|
||||||
Animal();
|
AAnimal();
|
||||||
virtual ~Animal();
|
virtual ~AAnimal();
|
||||||
virtual void makeSound() const;
|
AAnimal(AAnimal const & copy);
|
||||||
std::string getType() const;
|
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:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:57:51 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:50 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 18:45:33 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
Brain::Brain() {
|
Brain::Brain() {
|
||||||
|
std::cout << "[Brain]\t\tCreating Brain class" << std::endl;
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
std::ostringstream oss;
|
std::stringstream oss;
|
||||||
oss << "I'm thinking about the number " << (i + 1);
|
oss << "🧠 | Idea " << (i + 1);
|
||||||
idea[i] = oss.str();
|
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() {
|
Brain::~Brain() {
|
||||||
|
std::cout << "[Brain]\t\tDeleting Brain class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Brain& Brain::operator=(Brain &value) {
|
std::string Brain::getIdea(int index) const {
|
||||||
return (value);
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:58:06 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:43 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 18:51:23 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,17 +15,16 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Brain {
|
class Brain {
|
||||||
public:
|
public:
|
||||||
Brain();
|
Brain();
|
||||||
|
Brain(const Brain ©);
|
||||||
|
Brain& operator=(const Brain &assign);
|
||||||
~Brain();
|
~Brain();
|
||||||
std::string idea[100];
|
std::string getIdea(int index) const;
|
||||||
Brain& operator=(Brain &value);
|
void setIdea(int const index, std::string const idea);
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string ideas[100];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,54 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:22:32 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:14:10 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Cat::Cat() {
|
Cat::Cat() {
|
||||||
std::cout << "[Cat]\t\tCreating the class" << std::endl;
|
std::cout << "[Cat]\t\tCreating Cat class" << std::endl;
|
||||||
type = "Cat";
|
type = "Cat";
|
||||||
brain = new Brain();
|
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() {
|
Cat::~Cat() {
|
||||||
delete brain;
|
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 {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:20:07 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:11:50 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef CAT_HPP
|
#ifndef CAT_HPP
|
||||||
#define CAT_HPP
|
#define CAT_HPP
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "AAnimal.hpp"
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Cat : public Animal {
|
class Cat : public AAnimal {
|
||||||
public:
|
public:
|
||||||
Cat();
|
Cat();
|
||||||
~Cat();
|
~Cat();
|
||||||
|
Cat(Cat const & copy);
|
||||||
|
Cat & operator=(Cat const & assign);
|
||||||
virtual void makeSound() const;
|
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:
|
protected:
|
||||||
|
|
||||||
private:
|
|
||||||
Brain *brain;
|
Brain *brain;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,51 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:02 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:19:22 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:13:30 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Dog.hpp"
|
#include "Dog.hpp"
|
||||||
#include "Brain.hpp"
|
#include <iostream>
|
||||||
|
|
||||||
Dog::Dog() {
|
Dog::Dog() {
|
||||||
std::cout << "[Dog]\t\tCreating the class" << std::endl;
|
std::cout << "[Dog]\t\tCreating Dog class" << std::endl;
|
||||||
type = "Dog";
|
type = "Dog";
|
||||||
brain = new Brain();
|
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() {
|
Dog::~Dog() {
|
||||||
delete brain;
|
delete brain;
|
||||||
std::cout << "[Dog]\t\tDeleting the class" << std::endl;
|
std::cout << "[Dog]\t\tDeleting Dog class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dog::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:26:17 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/07 17:51:39 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:11:18 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef DOG_HPP
|
#ifndef DOG_HPP
|
||||||
#define DOG_HPP
|
#define DOG_HPP
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "AAnimal.hpp"
|
||||||
#include "Brain.hpp"
|
#include "Brain.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Dog : public Animal {
|
class Dog : public AAnimal {
|
||||||
public:
|
public:
|
||||||
Dog();
|
Dog();
|
||||||
~Dog();
|
~Dog();
|
||||||
|
Dog(Dog const & copy);
|
||||||
|
Dog & operator=(Dog const & assign);
|
||||||
virtual void makeSound() const;
|
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:
|
protected:
|
||||||
|
|
||||||
private:
|
|
||||||
Brain *brain;
|
Brain *brain;
|
||||||
|
std::string type;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,39 @@
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
# ::: :::::::: #
|
# ::: :::::::: #
|
||||||
# Makefile :+: :+: :+: #
|
# Makefile :+: :+: :+: #
|
||||||
# +:+ +:+ +:+ #
|
# +:+ +:+ +:+ #
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# 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
|
# Variables
|
||||||
|
|
||||||
# Name
|
# Name
|
||||||
NAME = polyformism
|
NAME = open
|
||||||
|
|
||||||
# Commands
|
# Commands
|
||||||
CXX = c++
|
CXX = c++
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|
||||||
# Flags
|
# Flags
|
||||||
# Mandatory flags for 42
|
# Mandatory flags for 42 cpp
|
||||||
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
CXXFLAGS = -Werror -Wextra -Wall -std=c++98 -I./includes/
|
||||||
# Flags to debug and have the dependences (can be removed for correction)
|
# Flags to debug and have the dependences (can be removed for correction)
|
||||||
CXXFLAGS += -MMD -g3
|
CXXFLAGS += -MMD -g3
|
||||||
# Flag to debug (TO REMOVE)
|
# Flag to debug (TO REMOVE)
|
||||||
# CXXFLAGS += -D DEBUG=1
|
# CXXFLAGS += -D DEBUG=1
|
||||||
# Sources
|
# Sources
|
||||||
SRC = Animal.cpp \
|
SRC = main.cpp \
|
||||||
Brain.cpp \
|
Brain.cpp \
|
||||||
Cat.cpp \
|
|
||||||
Dog.cpp \
|
|
||||||
WrongAnimal.cpp \
|
|
||||||
WrongCat.cpp \
|
WrongCat.cpp \
|
||||||
main.cpp \
|
WrongAnimal.cpp \
|
||||||
|
Dog.cpp \
|
||||||
|
AAnimal.cpp \
|
||||||
|
Cat.cpp
|
||||||
|
|
||||||
# Objects
|
# Objects
|
||||||
OBJDIRNAME = ./build
|
OBJDIRNAME = ./build
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,8 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:46 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:23 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 17:20:01 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,18 +14,25 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
WrongAnimal::WrongAnimal() {
|
WrongAnimal::WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tCreating the class" << std::endl;
|
std::cout << "[WrongAnimal]\tCreating WrongAnimal class" << std::endl;
|
||||||
type = "";
|
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() {
|
WrongAnimal::~WrongAnimal() {
|
||||||
std::cout << "[WrongAnimal]\tDeleting the class" << std::endl;
|
std::cout << "[WrongAnimal]\tDeleting WrongAnimal class" << std::endl;
|
||||||
}
|
|
||||||
|
|
||||||
std::string WrongAnimal::getType() const {
|
|
||||||
return (type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WrongAnimal::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:56 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:34:06 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:30:56 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,17 @@
|
||||||
#define WRONGANIMAL_HPP
|
#define WRONGANIMAL_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class WrongAnimal {
|
class WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongAnimal();
|
WrongAnimal();
|
||||||
virtual ~WrongAnimal();
|
virtual ~WrongAnimal();
|
||||||
virtual void makeSound() const;
|
WrongAnimal(WrongAnimal const & copy);
|
||||||
std::string getType() const;
|
WrongAnimal & operator=(WrongAnimal const & assign);
|
||||||
|
void makeSound() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string type;
|
std::string type;
|
||||||
private:
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,34 @@
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:05 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:54:35 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 17:17:44 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "WrongCat.hpp"
|
#include "WrongCat.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
WrongCat::WrongCat() {
|
WrongCat::WrongCat() {
|
||||||
std::cout << "[WrongCat]\tCreating the class" << std::endl;
|
std::cout << "[WrongCat]\tCreating WrongCat class" << std::endl;
|
||||||
type = "WrongCat";
|
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() {
|
WrongCat::~WrongCat() {
|
||||||
std::cout << "[WrongCat]\tDeleting the class" << std::endl;
|
std::cout << "[WrongCat]\tDeleting WrongCat class" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WrongCat::makeSound() const {
|
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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:21:49 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/01/31 19:37:00 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 16:48:00 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,17 +14,16 @@
|
||||||
#define WRONGCAT_HPP
|
#define WRONGCAT_HPP
|
||||||
|
|
||||||
#include "WrongAnimal.hpp"
|
#include "WrongAnimal.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class WrongCat : public WrongAnimal {
|
class WrongCat : public WrongAnimal {
|
||||||
public:
|
public:
|
||||||
WrongCat();
|
WrongCat();
|
||||||
~WrongCat();
|
~WrongCat();
|
||||||
|
WrongCat(WrongCat const & copy);
|
||||||
|
WrongCat & operator=(WrongCat const & assign);
|
||||||
virtual void makeSound() const;
|
virtual void makeSound() const;
|
||||||
protected:
|
protected:
|
||||||
|
std::string type;
|
||||||
private:
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#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> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */
|
/* Created: 2025/02/18 16:22:11 by rparodi #+# #+# */
|
||||||
/* Updated: 2025/02/10 12:40:53 by rparodi ### ########.fr */
|
/* Updated: 2025/02/18 20:12:27 by rparodi ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "Animal.hpp"
|
#include "AAnimal.hpp"
|
||||||
#include "Dog.hpp"
|
|
||||||
#include "Cat.hpp"
|
#include "Cat.hpp"
|
||||||
#include "WrongAnimal.hpp"
|
#include "Dog.hpp"
|
||||||
#include "WrongCat.hpp"
|
#include "color.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
const unsigned int n = 42;
|
const int nb = 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;
|
if (nb % 2 != 0) {
|
||||||
return (1);
|
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;
|
AAnimal *tab[nb];
|
||||||
Animal *animals[n];
|
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
std::cout << YELLOW << "\t\t[ Constructor ]" << RESET << std::endl;
|
||||||
std::cout << "(" << i + 1 << ") ";
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
if (i % 2 == 0) {
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||||
animals[i] = new Dog();
|
if (i % 2 == 0)
|
||||||
} else {
|
tab[i] = new Dog();
|
||||||
animals[i] = new Cat();
|
else
|
||||||
}
|
tab[i] = new Cat();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\033[0;33m[ Making sounds ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Make Sound ]" << RESET << std::endl;
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
std::cout << "(" << i + 1 << ") ";
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET;
|
||||||
animals[i]->makeSound();
|
tab[i]->makeSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "\033[0;33m[ Deleting classes ]\033[0m" << std::endl;
|
std::cout << std::endl << YELLOW << "\t\t[ Destructor ]" << RESET << std::endl;
|
||||||
for (unsigned int i = 0; i < n; i++) {
|
for (int i = 0; i < nb && i < nb; i++) {
|
||||||
std::cout << "(" << i + 1 << ") ";
|
std::cout << std::endl << BLUE << "(" << i + 1 << ")\t" << RESET << std::endl;
|
||||||
delete animals[i];
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue