update: rm -rf to restart from scratch

This commit is contained in:
Raphael 2025-02-18 20:20:27 +01:00
parent 42e83d8e62
commit 5e999def3a
45 changed files with 813 additions and 366 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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

View file

@ -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;
}

View file

@ -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

View file

@ -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;
}

View file

@ -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
View 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

View file

@ -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;
}