Project finished
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
NAME = animals
|
||||
|
||||
SRCS = main.cpp Animal/Animal.cpp Dog/Dog.cpp Cat/Cat.cpp
|
||||
SRCS = main.cpp Animal/Animal.cpp Dog/Dog.cpp Cat/Cat.cpp \
|
||||
WrongAnimal/WrongAnimal.cpp WrongCat/WrongCat.cpp
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
CC = c++
|
||||
@@ -11,8 +13,8 @@ all: $(NAME)
|
||||
$(NAME): $(OBJS)
|
||||
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
|
||||
|
||||
%.o: %cpp
|
||||
$(CC) $(CFLAGS) -c $@ -o $<
|
||||
%.o: %.cpp
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS)
|
||||
|
||||
47
ex00/WrongAnimal/WrongAnimal.cpp
Normal file
47
ex00/WrongAnimal/WrongAnimal.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongAnimal.hpp"
|
||||
|
||||
WrongAnimal::WrongAnimal() : type("WrongAnimal")
|
||||
{
|
||||
std::cout << "Animal has been created" << std::endl;
|
||||
}
|
||||
|
||||
WrongAnimal::~WrongAnimal()
|
||||
{
|
||||
std::cout << "Animal has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
WrongAnimal::WrongAnimal(const WrongAnimal &other)
|
||||
{
|
||||
std::cout << "WrongAnimal copied" << std::endl;
|
||||
*this = other;
|
||||
}
|
||||
|
||||
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &other)
|
||||
{
|
||||
std::cout << "WrongAnimal copy assignment called" << std::endl;
|
||||
if (this != &other)
|
||||
this->type = other.type;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void WrongAnimal::makeSound() const
|
||||
{
|
||||
std::cout << "WrongAnimal weird sounds..." << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongAnimal::getType() const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
33
ex00/WrongAnimal/WrongAnimal.hpp
Normal file
33
ex00/WrongAnimal/WrongAnimal.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGANIMAL_HPP
|
||||
|
||||
# define WRONGANIMAL_HPP
|
||||
|
||||
# include <iostream>
|
||||
|
||||
class WrongAnimal
|
||||
{
|
||||
protected:
|
||||
std::string type;
|
||||
public:
|
||||
WrongAnimal();
|
||||
~WrongAnimal();
|
||||
WrongAnimal(const WrongAnimal &other);
|
||||
WrongAnimal& operator=(const WrongAnimal &other);
|
||||
|
||||
void makeSound() const;
|
||||
std::string getType() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
48
ex00/WrongCat/WrongCat.cpp
Normal file
48
ex00/WrongCat/WrongCat.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "WrongCat.hpp"
|
||||
|
||||
WrongCat::WrongCat() : WrongAnimal()
|
||||
{
|
||||
std::cout << "Cat has been created" << std::endl;
|
||||
this->type = "WrongCat";
|
||||
}
|
||||
|
||||
WrongCat::~WrongCat()
|
||||
{
|
||||
std::cout << "Cat has been destroyed" << std::endl;
|
||||
}
|
||||
|
||||
WrongCat::WrongCat(const WrongCat &other)
|
||||
{
|
||||
std::cout << "WrongCat copied" << std::endl;
|
||||
*this = other;
|
||||
}
|
||||
|
||||
WrongCat& WrongCat::operator=(const WrongCat &other)
|
||||
{
|
||||
std::cout << "WrongCat copy assignment called" << std::endl;
|
||||
if (this != &other)
|
||||
this->type = other.type;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void WrongCat::makeSound() const
|
||||
{
|
||||
std::cout << "WrongCat weird sounds..." << std::endl;
|
||||
}
|
||||
|
||||
std::string WrongCat::getType() const
|
||||
{
|
||||
return (this->type);
|
||||
}
|
||||
32
ex00/WrongCat/WrongCat.hpp
Normal file
32
ex00/WrongCat/WrongCat.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Animal.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
|
||||
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef WRONGCAT_HPP
|
||||
|
||||
# define WRONGCAT_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include "../WrongAnimal/WrongAnimal.hpp"
|
||||
|
||||
class WrongCat : public WrongAnimal
|
||||
{
|
||||
public:
|
||||
WrongCat();
|
||||
~WrongCat();
|
||||
WrongCat(const WrongCat &other);
|
||||
WrongCat& operator=(const WrongCat &other);
|
||||
|
||||
void makeSound() const;
|
||||
std::string getType() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -6,13 +6,15 @@
|
||||
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/08 17:43:10 by hadi #+# #+# */
|
||||
/* Updated: 2025/11/09 21:49:36 by aortigos ### ########.fr */
|
||||
/* Updated: 2025/11/10 10:33:20 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Animal/Animal.hpp"
|
||||
#include "Dog/Dog.hpp"
|
||||
#include "Cat/Cat.hpp"
|
||||
#include "WrongAnimal/WrongAnimal.hpp"
|
||||
#include "WrongCat/WrongCat.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -20,20 +22,24 @@ int main()
|
||||
const Animal* meta = new Animal();
|
||||
const Animal* j = new Dog();
|
||||
const Animal* i = new Cat();
|
||||
const WrongAnimal* z = new WrongCat();
|
||||
|
||||
std::cout << std::endl << "----- Getting types ------" << std::endl;
|
||||
std::cout << j->getType() << " " << std::endl;
|
||||
std::cout << i->getType() << " " << std::endl;
|
||||
|
||||
std::cout << std::endl << "----- Making sounds ------" << std::endl;
|
||||
i->makeSound();
|
||||
std::cout << std::endl << "----- Animal sounds ------" << std::endl;
|
||||
|
||||
std::cout << j->getType() << " says: ";
|
||||
j->makeSound();
|
||||
meta->makeSound();
|
||||
|
||||
std::cout << std::endl << i->getType() << " says ";
|
||||
i->makeSound();
|
||||
|
||||
std::cout << std::endl << z->getType() << " says ";
|
||||
z->makeSound();
|
||||
|
||||
std::cout << std::endl << "----- Free all! ------" << std::endl;
|
||||
delete (meta);
|
||||
delete (j);
|
||||
delete (i);
|
||||
delete (z);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user