「✨」 feat(Ex01): Finished
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -2,3 +2,6 @@
|
||||
*.o
|
||||
obj/
|
||||
Polymorphism
|
||||
compile_commands.json
|
||||
.cache
|
||||
*.d
|
||||
|
@ -1,16 +1,16 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* animal.cpp :+: :+: :+: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:37:30 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:52:01 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "animal.hpp"
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal(void) {
|
||||
log("➕", "Animal", "", "construtor called");
|
@ -1,16 +1,16 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cat.cpp :+: :+: :+: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/01 20:18:55 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:52:10 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "cat.hpp"
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat(void) : Animal("Cat"){
|
||||
log("➕", "Cat", "", "construtor called");
|
@ -1,18 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* cat.hpp :+: :+: :+: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/01 20:18:42 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:52:20 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "animal.hpp"
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Cat : public Animal {
|
||||
public:
|
@ -1,16 +1,16 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dog.cpp :+: :+: :+: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 20:05:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 14:01:24 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:52:26 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "dog.hpp"
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog(void) : Animal("Dog"){
|
||||
log("➕", "Dog", "", "construtor called");
|
@ -1,18 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* dog.hpp :+: :+: :+: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 20:06:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/01 20:18:35 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:52:35 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "animal.hpp"
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Dog : public Animal {
|
||||
public:
|
@ -6,13 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:49:51 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:55:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat(void) : Animal("WrongCat"){
|
||||
WrongCat::WrongCat(void) : WrongAnimal("WrongCat"){
|
||||
log("➕", "WrongCat", "", "construtor called");
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ WrongCat::~WrongCat(void) {
|
||||
log("➖", "WrongCat", "", "destructor called");
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat &cpy) : Animal("WrongCat"){
|
||||
WrongCat::WrongCat(const WrongCat &cpy) : WrongAnimal("WrongCat"){
|
||||
log("➕", "WrongCat", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
@ -6,15 +6,15 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:49:47 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 15:55:47 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "animal.hpp"
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public Animal {
|
||||
class WrongCat : public WrongAnimal {
|
||||
public:
|
||||
WrongCat(void);
|
||||
~WrongCat(void);
|
||||
|
@ -6,14 +6,13 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 16:21:28 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:56:06 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/12/06 16:02:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
#include "cat.hpp"
|
||||
#include "dog.hpp"
|
||||
#include <iostream>
|
||||
#include "Cat.hpp"
|
||||
#include "Dog.hpp"
|
||||
|
||||
int main() {
|
||||
{
|
||||
@ -21,7 +20,6 @@ int main() {
|
||||
const Animal* dog = new Dog();
|
||||
const Animal* cat = new Cat();
|
||||
|
||||
|
||||
log("✨", "Animal/Cat", "Type", cat->getType());
|
||||
log("✨", "Animal/Dog", "Type", dog->getType());
|
||||
cat->makeSound(); //will output the cat sound!
|
||||
|
46
ex01/Animal.cpp
Normal file
46
ex01/Animal.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:00 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
Animal::Animal(void) {
|
||||
log("➕", "Animal", "", "construtor called");
|
||||
}
|
||||
|
||||
Animal::~Animal() {
|
||||
log("➖", "Animal", _type, "destructor called");
|
||||
}
|
||||
|
||||
Animal::Animal(std::string type) : _type(type) {
|
||||
log("➕", "Animal", type, "construtor called");
|
||||
}
|
||||
|
||||
Animal::Animal(const Animal &cpy) {
|
||||
log("➕", "Animal", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Animal &Animal::operator=(const Animal &cpy) {
|
||||
log("🟰", "Animal", _type, "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void Animal::makeSound(void) const {
|
||||
log("🔊", "Animal", "", "making a sound MEOWMEOW");
|
||||
}
|
||||
|
||||
std::string Animal::getType(void) const {
|
||||
return (_type);
|
||||
}
|
32
ex01/Animal.hpp
Normal file
32
ex01/Animal.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 16:33:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:05 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Log.hpp"
|
||||
|
||||
class Animal {
|
||||
protected:
|
||||
std::string _type;
|
||||
|
||||
public:
|
||||
Animal(void);
|
||||
Animal(std::string);
|
||||
virtual ~Animal(void);
|
||||
Animal(const Animal &);
|
||||
Animal &operator=(const Animal &);
|
||||
|
||||
std::string getType(void) const;
|
||||
|
||||
virtual void makeSound(void) const;
|
||||
};
|
36
ex01/Brain.cpp
Normal file
36
ex01/Brain.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 11:47:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:11 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Brain.hpp"
|
||||
|
||||
Brain::Brain(void) {
|
||||
log("➕", "Brain", "", "construtor called");
|
||||
}
|
||||
|
||||
Brain::~Brain(void) {
|
||||
log("➖", "Brain", "", "destructor called");
|
||||
}
|
||||
|
||||
Brain::Brain(const Brain &cpy) {
|
||||
log("➕", "Brain", "", "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Brain &Brain::operator=(const Brain &cpy) {
|
||||
log("🟰", "Brain", "", "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
for (uint i = 0; i < 100; i++) {
|
||||
this->_ideas[i] = cpy._ideas[i];
|
||||
}
|
||||
}
|
||||
return (*this);
|
||||
}
|
26
ex01/Brain.hpp
Normal file
26
ex01/Brain.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Brain.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 11:35:05 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:18 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "Log.hpp"
|
||||
|
||||
class Brain {
|
||||
public:
|
||||
Brain(void);
|
||||
~Brain(void);
|
||||
Brain(const Brain &);
|
||||
Brain &operator=(const Brain &);
|
||||
|
||||
std::string _ideas[100];
|
||||
};
|
48
ex01/Cat.cpp
Normal file
48
ex01/Cat.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:23 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Cat.hpp"
|
||||
|
||||
Cat::Cat(void) : Animal("Cat"){
|
||||
_brain = new Brain();
|
||||
log("➕", "Cat", "", "construtor called");
|
||||
}
|
||||
|
||||
Cat::~Cat(void) {
|
||||
delete _brain;
|
||||
log("➖", "Cat", "", "destructor called");
|
||||
}
|
||||
|
||||
Cat::Cat(const Cat &cpy) : Animal("Cat"){
|
||||
log("➕", "Cat", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Cat &Cat::operator=(const Cat &cpy) {
|
||||
log("🟰", "Cat", "", "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
this->_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void Cat::makeSound(void) const {
|
||||
log("🔊", "Cat", "", "Mmmmmmeeeeeeeeoooooooowwwwww");
|
||||
}
|
||||
|
||||
void Cat::setIdea(std::string idea, uint i) {
|
||||
_brain->_ideas[i] = idea;
|
||||
}
|
||||
|
||||
std::string Cat::getIdea(uint i) {
|
||||
return (_brain->_ideas[i]);
|
||||
}
|
30
ex01/Cat.hpp
Normal file
30
ex01/Cat.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Cat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:30 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Brain.hpp"
|
||||
|
||||
class Cat : public Animal {
|
||||
private:
|
||||
Brain *_brain;
|
||||
public:
|
||||
Cat(void);
|
||||
~Cat(void);
|
||||
Cat(const Cat &);
|
||||
Cat &operator=(const Cat &);
|
||||
|
||||
void makeSound(void) const;
|
||||
void setIdea(std::string, uint);
|
||||
std::string getIdea(uint);
|
||||
};
|
48
ex01/Dog.cpp
Normal file
48
ex01/Dog.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 20:05:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:35 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
|
||||
Dog::Dog(void) : Animal("Dog"){
|
||||
_brain = new Brain();
|
||||
log("➕", "Dog", "", "construtor called");
|
||||
}
|
||||
|
||||
Dog::~Dog(void) {
|
||||
delete _brain;
|
||||
log("➖", "Dog", "", "destructor called");
|
||||
}
|
||||
|
||||
Dog::Dog(const Dog &cpy) : Animal("Dog"){
|
||||
log("➕", "Dog", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
Dog &Dog::operator=(const Dog &cpy) {
|
||||
log("🟰", "Dog", "", "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
this->_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void Dog::makeSound(void) const {
|
||||
log("🔊", "Dog", "", "woof");
|
||||
}
|
||||
|
||||
void Dog::setIdea(std::string idea, uint i) {
|
||||
_brain->_ideas[i] = idea;
|
||||
}
|
||||
|
||||
std::string Dog::getIdea(uint i) {
|
||||
return (_brain->_ideas[i]);
|
||||
}
|
30
ex01/Dog.hpp
Normal file
30
ex01/Dog.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Dog.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 20:06:20 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:53:41 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Animal.hpp"
|
||||
#include "Brain.hpp"
|
||||
|
||||
class Dog : public Animal {
|
||||
private:
|
||||
Brain *_brain;
|
||||
public:
|
||||
Dog(void);
|
||||
~Dog(void);
|
||||
Dog(const Dog &);
|
||||
Dog &operator=(const Dog &);
|
||||
|
||||
void makeSound(void) const;
|
||||
void setIdea(std::string, uint);
|
||||
std::string getIdea(uint);
|
||||
};
|
22
ex01/Log.cpp
Normal file
22
ex01/Log.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* log.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 16:30:53 by adjoly #+# #+# */
|
||||
/* Updated: 2024/11/30 16:32:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
void log(std::string emoji, std::string what, std::string who, std::string str) {
|
||||
if (who.empty())
|
||||
std::cout << "「" << emoji << "」" << what << ": " << str << std::endl;
|
||||
else
|
||||
std::cout << "「" << emoji << "」" << what << "(" << who << "): " << str << std::endl;
|
||||
}
|
||||
|
19
ex01/Log.hpp
Normal file
19
ex01/Log.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* log.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 12:01:21 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 13:12:13 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
void log(std::string, std::string, std::string, std::string);
|
56
ex01/Makefile
Normal file
56
ex01/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||
# Updated: 2024/12/06 12:07:06 by adjoly ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
SHELL = bash
|
||||
|
||||
NAME = Settheworldonfire
|
||||
|
||||
CC = c++
|
||||
|
||||
OBJSDIR = obj/
|
||||
|
||||
SRCS = $(shell find . -name '*.cpp')
|
||||
|
||||
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||
|
||||
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||
|
||||
RED = \033[0;31m
|
||||
GREEN = \033[0;32m
|
||||
YELLOW = \033[1;33m
|
||||
PURPLE = \e[0;35m
|
||||
NC = \033[0m
|
||||
DELETE = \x1B[2K\r
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||
|
||||
$(OBJSDIR)%.o: %.cpp
|
||||
@mkdir -p $(@D)
|
||||
@$(CC) $(FLAGS) -c $< -o $@
|
||||
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||
|
||||
clean:
|
||||
@rm -f $(OBJS)
|
||||
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||
|
||||
fclean: clean
|
||||
@rm -f $(NAME)
|
||||
@rm -Rf $(OBJSDIR)
|
||||
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: clean fclean all re
|
46
ex01/WrongAnimal.cpp
Normal file
46
ex01/WrongAnimal.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:14:27 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:56:34 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal(void) {
|
||||
log("➕", "WrongAnimal", "", "construtor called");
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal() {
|
||||
log("➖", "WrongAnimal", _type, "destructor called");
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(std::string type) : _type(type) {
|
||||
log("➕", "WrongAnimal", type, "construtor called");
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal &cpy) {
|
||||
log("➕", "WrongAnimal", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
WrongAnimal &WrongAnimal::operator=(const WrongAnimal &cpy) {
|
||||
log("🟰", "WrongAnimal", _type, "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound(void) const {
|
||||
log("🔊", "WrongAnimal", "", "making a wrong sound OOOOOOOOOOOOOOOoo");
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType(void) const {
|
||||
return (_type);
|
||||
}
|
33
ex01/WrongAnimal.hpp
Normal file
33
ex01/WrongAnimal.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongAnimal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 16:33:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/04 13:50:36 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class WrongAnimal {
|
||||
protected:
|
||||
std::string _type;
|
||||
|
||||
public:
|
||||
WrongAnimal(void);
|
||||
~WrongAnimal(void);
|
||||
WrongAnimal(std::string);
|
||||
WrongAnimal(const WrongAnimal &);
|
||||
WrongAnimal &operator=(const WrongAnimal &);
|
||||
|
||||
std::string getType(void) const;
|
||||
|
||||
void makeSound(void) const;
|
||||
};
|
||||
|
||||
void log(std::string, std::string, std::string, std::string);
|
38
ex01/WrongCat.cpp
Normal file
38
ex01/WrongCat.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:49:11 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:55:37 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat(void) : WrongAnimal("WrongCat"){
|
||||
log("➕", "WrongCat", "", "construtor called");
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat(void) {
|
||||
log("➖", "WrongCat", "", "destructor called");
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat &cpy) : WrongAnimal("WrongCat"){
|
||||
log("➕", "WrongCat", _type, "copy construtor called");
|
||||
*this = cpy;
|
||||
}
|
||||
|
||||
WrongCat &WrongCat::operator=(const WrongCat &cpy) {
|
||||
log("🟰", "WrongCat", "", "copy assignment construtor called");
|
||||
if (this != &cpy) {
|
||||
this->_type = cpy._type;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void WrongCat::makeSound(void) const {
|
||||
log("🔊", "WrongCat", "", "wwwwwwwwooooooooeeeeeeeeemmmmmmm");
|
||||
}
|
25
ex01/WrongCat.hpp
Normal file
25
ex01/WrongCat.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* WrongCat.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/01 19:06:08 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:55:47 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal {
|
||||
public:
|
||||
WrongCat(void);
|
||||
~WrongCat(void);
|
||||
WrongCat(const WrongCat &);
|
||||
WrongCat &operator=(const WrongCat &);
|
||||
|
||||
void makeSound(void) const;
|
||||
};
|
41
ex01/main.cpp
Normal file
41
ex01/main.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/06 11:20:59 by adjoly #+# #+# */
|
||||
/* Updated: 2024/12/06 15:58:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Dog.hpp"
|
||||
#include "Cat.hpp"
|
||||
|
||||
int main() {
|
||||
const Animal* dog = new Dog();
|
||||
Cat* cat = new Cat();
|
||||
|
||||
cat->setIdea("I want to eat", 0);
|
||||
cat->setIdea("I want to eat", 1);
|
||||
cat->setIdea("I want to eat", 2);
|
||||
cat->setIdea("I want to eat", 3);
|
||||
cat->setIdea("I want to eat", 4);
|
||||
cat->setIdea("I want to eat", 5);
|
||||
cat->setIdea("I want to eat", 6);
|
||||
dog->makeSound();
|
||||
cat->makeSound();
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(0));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(1));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(2));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(3));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(4));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(5));
|
||||
log("🥩", "Idea", "Cat", cat->getIdea(6));
|
||||
|
||||
delete cat;
|
||||
delete dog;
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user