feat: starting the ex01
This commit is contained in:
parent
13deee8e3c
commit
1cff8e9d9e
11 changed files with 374 additions and 0 deletions
32
cpp04/ex01/Animal.cpp
Normal file
32
cpp04/ex01/Animal.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Animal.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/30 13:21:01 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/01/30 13:37:51 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Animal.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
30
cpp04/ex01/Animal.hpp
Normal file
30
cpp04/ex01/Animal.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Animal.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Animal {
|
||||||
|
public:
|
||||||
|
Animal();
|
||||||
|
~Animal();
|
||||||
|
void makeSound();
|
||||||
|
std::string getType();
|
||||||
|
protected:
|
||||||
|
std::string type;
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
24
cpp04/ex01/Brain.cpp
Normal file
24
cpp04/ex01/Brain.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Brain.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/02/06 15:17:41 by rparodi #+# #+# */
|
||||||
|
/* Updated: 2025/02/06 17:56:18 by rparodi ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Brain.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
Brain::Brain() {
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
idea[i] = "I'm thinking about the number " + std::to_string(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Brain::~Brain() {
|
||||||
|
|
||||||
|
}
|
||||||
29
cpp04/ex01/Brain.hpp
Normal file
29
cpp04/ex01/Brain.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Brain.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <string>
|
||||||
|
class Brain {
|
||||||
|
public:
|
||||||
|
Brain();
|
||||||
|
~Brain();
|
||||||
|
std::string idea[100];
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
26
cpp04/ex01/Cat.cpp
Normal file
26
cpp04/ex01/Cat.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Cat.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
29
cpp04/ex01/Cat.hpp
Normal file
29
cpp04/ex01/Cat.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Cat.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <string>
|
||||||
|
|
||||||
|
class Cat : public Animal {
|
||||||
|
public:
|
||||||
|
Cat();
|
||||||
|
~Cat();
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
26
cpp04/ex01/Dog.cpp
Normal file
26
cpp04/ex01/Dog.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Dog.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
30
cpp04/ex01/Dog.hpp
Normal file
30
cpp04/ex01/Dog.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Dog.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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 <string>
|
||||||
|
|
||||||
|
class Dog : public Animal {
|
||||||
|
public:
|
||||||
|
Dog();
|
||||||
|
~Dog();
|
||||||
|
std::string getType();
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
121
cpp04/ex01/Makefile
Normal file
121
cpp04/ex01/Makefile
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
# **************************************************************************** #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# 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 #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
# 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}
|
||||||
BIN
cpp04/ex01/a.out
Executable file
BIN
cpp04/ex01/a.out
Executable file
Binary file not shown.
27
cpp04/ex01/main.cpp
Normal file
27
cpp04/ex01/main.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue