diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp new file mode 100644 index 0000000..410e2e7 --- /dev/null +++ b/cpp04/ex01/Animal.cpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:37:51 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Animal.hpp" +#include + +Animal::Animal() { + std::cout << "[Animal] Creating the class" << std::endl; + type = ""; +} + +Animal::~Animal() { + std::cout << "[Animal] Deleting the class" << std::endl; +} + +void Animal::makeSound() { + if (type.compare("Cat")) + std::cout << "🐱 | Meow Meow" << std::endl; + else if (type.compare("Dog")) + std::cout << "🐶 | Wouf Wouf" << std::endl; + else + std::cout << "🤔 | thinking how to make a sound" << std::endl; +} diff --git a/cpp04/ex01/Animal.hpp b/cpp04/ex01/Animal.hpp new file mode 100644 index 0000000..bcd273a --- /dev/null +++ b/cpp04/ex01/Animal.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Animal.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:44:54 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:42:23 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ANIMAL_HPP +#define ANIMAL_HPP + +#include +#include + +class Animal { + public: + Animal(); + ~Animal(); + void makeSound(); + std::string getType(); + protected: + std::string type; + private: +}; + +#endif diff --git a/cpp04/ex01/Brain.cpp b/cpp04/ex01/Brain.cpp new file mode 100644 index 0000000..2c6db6f --- /dev/null +++ b/cpp04/ex01/Brain.cpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */ +/* Updated: 2025/02/06 17:56:18 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Brain.hpp" +#include + +Brain::Brain() { + for (int i = 0; i < 100; i++) { + idea[i] = "I'm thinking about the number " + std::to_string(i + 1); + } +} + +Brain::~Brain() { + +} diff --git a/cpp04/ex01/Brain.hpp b/cpp04/ex01/Brain.hpp new file mode 100644 index 0000000..2d0237e --- /dev/null +++ b/cpp04/ex01/Brain.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Brain.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/06 15:17:49 by rparodi #+# #+# */ +/* Updated: 2025/02/06 17:35:51 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BRAIN_HPP +#define BRAIN_HPP + +#include +class Brain { + public: + Brain(); + ~Brain(); + std::string idea[100]; + + protected: + + private: + +}; + +#endif diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp new file mode 100644 index 0000000..207c674 --- /dev/null +++ b/cpp04/ex01/Cat.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/30 13:32:43 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:38:46 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Cat.hpp" + +Cat::Cat() { + std::cout << "[Cat] Creating the class" << std::endl; + type = "Cat"; +} + +Cat::~Cat() { + std::cout << "[Cat] Deleting the class" << std::endl; +} + +std::string Cat::getType() { + return (type); +} diff --git a/cpp04/ex01/Cat.hpp b/cpp04/ex01/Cat.hpp new file mode 100644 index 0000000..130e8ed --- /dev/null +++ b/cpp04/ex01/Cat.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Cat.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:44:48 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:41:27 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CAT_HPP +#define CAT_HPP + +#include "Animal.hpp" +#include + +class Cat : public Animal { + public: + Cat(); + ~Cat(); + protected: + + private: + +}; + +#endif diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp new file mode 100644 index 0000000..cf6a045 --- /dev/null +++ b/cpp04/ex01/Dog.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/30 13:40:30 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:40:51 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Dog.hpp" + +Dog::Dog() { + std::cout << "[Dog] Creating the class" << std::endl; + type = "Dog"; +} + +Dog::~Dog() { + std::cout << "[Dog] Deleting the class" << std::endl; +} + +std::string Dog::getType() { + return (type); +} diff --git a/cpp04/ex01/Dog.hpp b/cpp04/ex01/Dog.hpp new file mode 100644 index 0000000..80c5361 --- /dev/null +++ b/cpp04/ex01/Dog.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Dog.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:44:51 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:32:28 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef DOG_HPP +#define DOG_HPP + +#include "Animal.hpp" +#include + +class Dog : public Animal { + public: + Dog(); + ~Dog(); + std::string getType(); + protected: + + private: + +}; + +#endif diff --git a/cpp04/ex01/Makefile b/cpp04/ex01/Makefile new file mode 100644 index 0000000..8380d2b --- /dev/null +++ b/cpp04/ex01/Makefile @@ -0,0 +1,121 @@ +# **************************************************************************** # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/12/21 19:50:58 by rparodi ### ########.fr # +# # +# **************************************************************************** # + +# Variables + +# Name +NAME = polyformism + +# Commands +CXX = c++ +RM = rm -rf + +# Flags +# Mandatory flags for 42 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 = main.cpp + +# Objects +OBJDIRNAME = ./build +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Bonus (make bonus) +bonus: header $(OBJ) footer + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @$(CXX) $(CXXFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.cpp + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @$(CXX) $(CXXFLAGS) -o $@ -c $< + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +clangd: + @echo \ + "CompileFlags:\n" \ + " Add:\n" \ + " - \"-std=c++98 -Wall -Wextra -Werror\"\n" \ + " - \"-I"$(shell pwd)"/includes\"\n" \ + " - \"-xc++\"\n" \ + > .clangd + +# Phony +.PHONY: all bonus clean fclean re clangd +-include ${OBJ:.o=.d} diff --git a/cpp04/ex01/a.out b/cpp04/ex01/a.out new file mode 100755 index 0000000..6233131 Binary files /dev/null and b/cpp04/ex01/a.out differ diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp new file mode 100644 index 0000000..abfe447 --- /dev/null +++ b/cpp04/ex01/main.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/01/28 17:08:09 by rparodi #+# #+# */ +/* Updated: 2025/01/30 13:12:32 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Animal.hpp" +#include "Dog.hpp" +#include "Cat.hpp" + +int main() { + const Animal* meta = new Animal(); + const Animal* j = new Dog(); + const Animal* i = new Cat(); + std::cout << j->getType() << " " << std::endl; + std::cout << i->getType() << " " << std::endl; + i->makeSound(); //will output the cat sound! + j->makeSound(); + meta->makeSound(); + return 0; +}