narnaud
3 years ago
44 changed files with 1094 additions and 35 deletions
@ -0,0 +1,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Animal.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:22:10 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Animal.hpp" |
|||
|
|||
Animal::Animal (void) { |
|||
cout << "Animal default constructor called " << endl; |
|||
} |
|||
|
|||
Animal::Animal (string type):_type(type) { |
|||
cout << "Animal parameter constructor called" << endl; |
|||
} |
|||
|
|||
Animal::Animal (Animal const & src) { |
|||
(void)src; |
|||
cout << "Animal copy constructor called" << endl; |
|||
} |
|||
|
|||
Animal & Animal::operator= (Animal const & src) { |
|||
(void)src; |
|||
cout << "Animal assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Animal::~Animal (void) { |
|||
|
|||
cout << "Animal default destructor called" << endl; |
|||
} |
|||
string Animal::getType(void) const { |
|||
return (_type); |
|||
} |
|||
void Animal::makeSound(void) const { |
|||
cout << "..." << endl; |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Animal.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:07:53 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::string; |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
class Animal{ |
|||
public: |
|||
Animal(void); |
|||
Animal(string type); |
|||
Animal(Animal const & src); |
|||
virtual ~Animal(void); |
|||
Animal & operator= (Animal const & src); |
|||
string getType(void) const; |
|||
virtual void makeSound(void) const; |
|||
protected: |
|||
string _type; |
|||
}; |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:08:55 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Cat.hpp" |
|||
|
|||
Cat::Cat (void):Animal("Cat") { |
|||
cout << "Cat default constructor called" << endl; |
|||
} |
|||
|
|||
Cat::~Cat (void) { |
|||
cout << "Cat default destructor called" << endl; |
|||
} |
|||
void Cat::makeSound(void) const { |
|||
cout << "Miaou" << endl; |
|||
} |
@ -0,0 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:09:35 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Animal.hpp" |
|||
class Cat: public Animal { |
|||
public: |
|||
Cat(void); |
|||
~Cat(void); |
|||
void makeSound(void) const; |
|||
}; |
|||
|
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:10:00 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
|
|||
Dog::Dog (void):Animal("Dog") { |
|||
cout << "Dog default constructor called" << endl; |
|||
} |
|||
|
|||
Dog::~Dog (void) { |
|||
cout << "Dog default destructor called" << endl; |
|||
} |
|||
void Dog::makeSound(void) const { |
|||
cout << "Waouf" << endl; |
|||
} |
@ -0,0 +1,21 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:09:29 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Animal.hpp" |
|||
class Dog: public Animal { |
|||
public: |
|||
Dog(void); |
|||
~Dog(void); |
|||
void makeSound(void) const; |
|||
}; |
@ -0,0 +1,20 @@ |
|||
NAME = dumb_animals |
|||
SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp WrongAnimal.cpp WrongCat.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(SRCS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,42 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* WrongAnimal.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:22:03 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "WrongAnimal.hpp" |
|||
|
|||
WrongAnimal::WrongAnimal (void) { |
|||
cout << "WrongAnimal default constructor called " << endl; |
|||
} |
|||
|
|||
WrongAnimal::WrongAnimal (string type):_type(type) { |
|||
cout << "WrongAnimal parameter constructor called" << endl; |
|||
} |
|||
|
|||
WrongAnimal::WrongAnimal (WrongAnimal const & src) { |
|||
(void)src; |
|||
cout << "WrongAnimal copy constructor called" << endl; |
|||
} |
|||
|
|||
WrongAnimal & WrongAnimal::operator= (WrongAnimal const & src) { |
|||
(void)src; |
|||
cout << "WrongAnimal assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
WrongAnimal::~WrongAnimal (void) { |
|||
cout << "WrongAnimal default destructor called" << endl; |
|||
} |
|||
string WrongAnimal::getType(void) const { |
|||
return (_type); |
|||
} |
|||
void WrongAnimal::makeSound(void) const { |
|||
cout << "..." << endl; |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* WrongAnimal.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:15:37 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::string; |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
class WrongAnimal{ |
|||
public: |
|||
WrongAnimal(void); |
|||
WrongAnimal(string type); |
|||
WrongAnimal(WrongAnimal const & src); |
|||
virtual ~WrongAnimal(void); |
|||
WrongAnimal & operator= (WrongAnimal const & src); |
|||
string getType(void) const; |
|||
void makeSound(void) const; |
|||
protected: |
|||
string _type; |
|||
}; |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* WrongCat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:15:11 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "WrongCat.hpp" |
|||
|
|||
WrongCat::WrongCat (void):WrongAnimal("WrongCat") { |
|||
cout << "WrongCat default constructor called" << endl; |
|||
} |
|||
|
|||
WrongCat::~WrongCat (void) { |
|||
cout << "WrongCat default destructor called" << endl; |
|||
} |
|||
void WrongCat::makeSound(void) const { |
|||
cout << "Miaou" << endl; |
|||
} |
@ -0,0 +1,22 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* WrongCat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:13:28 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "WrongAnimal.hpp" |
|||
class WrongCat: public WrongAnimal { |
|||
public: |
|||
WrongCat(void); |
|||
~WrongCat(void); |
|||
void makeSound(void) const; |
|||
}; |
|||
|
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:16:31 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
#include "Cat.hpp" |
|||
#include "WrongCat.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
const Animal* meta = new Animal(); |
|||
const Animal* i = new Cat(); |
|||
const Animal* j = new Dog(); |
|||
const WrongAnimal *k = new WrongCat(); |
|||
|
|||
std::cout << i->getType() << " " << std::endl; |
|||
std::cout << j->getType() << " " << std::endl; |
|||
i->makeSound(); //will output the cat sound!
|
|||
j->makeSound(); |
|||
meta->makeSound(); |
|||
|
|||
k->makeSound(); |
|||
return (0); |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Animal.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:23:19 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Animal.hpp" |
|||
|
|||
Animal::Animal (void) { |
|||
cout << "Animal default constructor called " << endl; |
|||
} |
|||
|
|||
Animal::Animal (string type):_type(type) { |
|||
cout << "Animal parameter constructor called" << endl; |
|||
} |
|||
|
|||
Animal::Animal (Animal const & src) { |
|||
(void)src; |
|||
cout << "Animal copy constructor called" << endl; |
|||
} |
|||
|
|||
Animal & Animal::operator= (Animal const & src) { |
|||
(void)src; |
|||
cout << "Animal assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Animal::~Animal (void) { |
|||
|
|||
cout << "Animal default destructor called" << endl; |
|||
} |
|||
string Animal::getType(void) const { |
|||
return (_type); |
|||
} |
|||
void Animal::makeSound(void) const { |
|||
cout << "..." << endl; |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Animal.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 10:07:53 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::string; |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
class Animal{ |
|||
public: |
|||
Animal(void); |
|||
Animal(string type); |
|||
Animal(Animal const & src); |
|||
virtual ~Animal(void); |
|||
Animal & operator= (Animal const & src); |
|||
string getType(void) const; |
|||
virtual void makeSound(void) const; |
|||
protected: |
|||
string _type; |
|||
}; |
@ -0,0 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Brain.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:57:44 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Brain.hpp" |
|||
|
|||
Brain::Brain (void) { |
|||
cout << "Brain default constructor called " << endl; |
|||
} |
|||
|
|||
Brain::Brain (Brain const & src) { |
|||
(void)src; |
|||
cout << "Brain copy constructor called" << endl; |
|||
} |
|||
|
|||
Brain & Brain::operator= (Brain const & src) { |
|||
(void)src; |
|||
cout << "Brain assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Brain::~Brain (void) { |
|||
|
|||
cout << "Brain default destructor called" << endl; |
|||
} |
@ -0,0 +1,28 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Brain.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:56:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Brain{ |
|||
string ideas[100]; |
|||
public: |
|||
Brain(void); |
|||
Brain(Brain const & src); |
|||
virtual ~Brain(void); |
|||
Brain & operator= (Brain const & src); |
|||
}; |
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:47:13 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Cat.hpp" |
|||
|
|||
Cat::Cat (void):Animal("Cat") { |
|||
_brain = new Brain(); |
|||
cout << "Cat default constructor called" << endl; |
|||
} |
|||
|
|||
Cat::~Cat (void) { |
|||
delete _brain; |
|||
cout << "Cat default destructor called" << endl; |
|||
} |
|||
void Cat::makeSound(void) const { |
|||
cout << "Miaou" << endl; |
|||
} |
@ -0,0 +1,25 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:46:12 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Animal.hpp" |
|||
#include "Brain.hpp" |
|||
|
|||
class Cat: public Animal { |
|||
Brain *_brain; |
|||
public: |
|||
Cat(void); |
|||
~Cat(void); |
|||
void makeSound(void) const; |
|||
}; |
|||
|
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:47:22 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
|
|||
Dog::Dog (void):Animal("Dog") { |
|||
_brain = new Brain(); |
|||
cout << "Dog default constructor called" << endl; |
|||
} |
|||
|
|||
Dog::~Dog (void) { |
|||
delete _brain; |
|||
cout << "Dog default destructor called" << endl; |
|||
} |
|||
void Dog::makeSound(void) const { |
|||
cout << "Waouf" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:46:17 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "Animal.hpp" |
|||
#include "Brain.hpp" |
|||
|
|||
class Dog: public Animal { |
|||
Brain *_brain; |
|||
public: |
|||
Dog(void); |
|||
~Dog(void); |
|||
void makeSound(void) const; |
|||
}; |
@ -0,0 +1,20 @@ |
|||
NAME = smart_animals |
|||
SRCS = main.cpp Animal.cpp Dog.cpp Cat.cpp Brain.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(SRCS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:00:44 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
#include "Cat.hpp" |
|||
#define NB_ANIMALS 4 |
|||
|
|||
int main(void) |
|||
{ |
|||
Animal *animals[NB_ANIMALS]; |
|||
|
|||
int i = 0; |
|||
while (i < NB_ANIMALS / 2) |
|||
animals[i++] = new Dog(); |
|||
while (i < NB_ANIMALS) |
|||
animals[i++] = new Cat(); |
|||
i = 0; |
|||
while (i < NB_ANIMALS / 2) |
|||
delete animals[i++]; |
|||
while (i < NB_ANIMALS) |
|||
delete animals[i++]; |
|||
return (0); |
|||
} |
@ -0,0 +1,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* AAnimal.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:11 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:10:54 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "AAnimal.hpp" |
|||
|
|||
AAnimal::AAnimal (void) { |
|||
cout << "AAnimal default constructor called " << endl; |
|||
} |
|||
|
|||
AAnimal::AAnimal (string type):_type(type) { |
|||
cout << "AAnimal parameter constructor called" << endl; |
|||
} |
|||
|
|||
AAnimal::AAnimal (AAnimal const & src) { |
|||
(void)src; |
|||
cout << "AAnimal copy constructor called" << endl; |
|||
} |
|||
|
|||
AAnimal & AAnimal::operator= (AAnimal const & src) { |
|||
(void)src; |
|||
cout << "AAnimal assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
AAnimal::~AAnimal (void) { |
|||
|
|||
cout << "AAnimal default destructor called" << endl; |
|||
} |
|||
string AAnimal::getType(void) const { |
|||
return (_type); |
|||
} |
|||
void AAnimal::makeSound(void) const { |
|||
cout << "..." << endl; |
|||
} |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* AAnimal.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:10 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:14:54 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::string; |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
class AAnimal{ |
|||
public: |
|||
AAnimal(void); |
|||
AAnimal(string type); |
|||
AAnimal(AAnimal const & src); |
|||
virtual ~AAnimal(void); |
|||
AAnimal & operator= (AAnimal const & src); |
|||
string getType(void) const; |
|||
virtual void makeSound(void) const = 0; |
|||
protected: |
|||
string _type; |
|||
}; |
@ -0,0 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Brain.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:57:44 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Brain.hpp" |
|||
|
|||
Brain::Brain (void) { |
|||
cout << "Brain default constructor called " << endl; |
|||
} |
|||
|
|||
Brain::Brain (Brain const & src) { |
|||
(void)src; |
|||
cout << "Brain copy constructor called" << endl; |
|||
} |
|||
|
|||
Brain & Brain::operator= (Brain const & src) { |
|||
(void)src; |
|||
cout << "Brain assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Brain::~Brain (void) { |
|||
|
|||
cout << "Brain default destructor called" << endl; |
|||
} |
@ -0,0 +1,28 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Brain.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 11:24:53 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 11:56:58 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Brain{ |
|||
string ideas[100]; |
|||
public: |
|||
Brain(void); |
|||
Brain(Brain const & src); |
|||
virtual ~Brain(void); |
|||
Brain & operator= (Brain const & src); |
|||
}; |
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Cat.hpp" |
|||
|
|||
Cat::Cat (void):AAnimal("Cat") { |
|||
_brain = new Brain(); |
|||
cout << "Cat default constructor called" << endl; |
|||
} |
|||
|
|||
Cat::~Cat (void) { |
|||
delete _brain; |
|||
cout << "Cat default destructor called" << endl; |
|||
} |
|||
void Cat::makeSound(void) const { |
|||
cout << "Miaou" << endl; |
|||
} |
@ -0,0 +1,25 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Cat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:47 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:11:30 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "AAnimal.hpp" |
|||
#include "Brain.hpp" |
|||
|
|||
class Cat: public AAnimal { |
|||
Brain *_brain; |
|||
public: |
|||
Cat(void); |
|||
~Cat(void); |
|||
void makeSound(void) const; |
|||
}; |
|||
|
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
|
|||
Dog::Dog (void):AAnimal("Dog") { |
|||
_brain = new Brain(); |
|||
cout << "Dog default constructor called" << endl; |
|||
} |
|||
|
|||
Dog::~Dog (void) { |
|||
delete _brain; |
|||
cout << "Dog default destructor called" << endl; |
|||
} |
|||
void Dog::makeSound(void) const { |
|||
cout << "Waouf" << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Dog.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 09:02:36 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:11:18 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include "AAnimal.hpp" |
|||
#include "Brain.hpp" |
|||
|
|||
class Dog: public AAnimal { |
|||
Brain *_brain; |
|||
public: |
|||
Dog(void); |
|||
~Dog(void); |
|||
void makeSound(void) const; |
|||
}; |
@ -0,0 +1,20 @@ |
|||
NAME = abstract_animals |
|||
SRCS = main.cpp AAnimal.cpp Dog.cpp Cat.cpp Brain.cpp |
|||
OBJS = $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(SRCS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 08:28:40 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 12:10:57 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Dog.hpp" |
|||
#include "Cat.hpp" |
|||
#define NB_ANIMALS 4 |
|||
|
|||
int main(void) |
|||
{ |
|||
AAnimal *animals[NB_ANIMALS]; |
|||
|
|||
int i = 0; |
|||
while (i < NB_ANIMALS / 2) |
|||
animals[i++] = new Dog(); |
|||
while (i < NB_ANIMALS) |
|||
animals[i++] = new Cat(); |
|||
i = 0; |
|||
while (i < NB_ANIMALS / 2) |
|||
delete animals[i++]; |
|||
while (i < NB_ANIMALS) |
|||
delete animals[i++]; |
|||
return (0); |
|||
} |
@ -0,0 +1,57 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 17:42:27 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
|
|||
Bureaucrat::Bureaucrat (void) { |
|||
cout << "Bureaucrat default constructor called " << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (string name, size_t grade) throw (char*): _name(name){ |
|||
|
|||
if (grade > 150) |
|||
throw Bureaucrat::GradeTooHighException(""); |
|||
_grade = grade; |
|||
cout << "Bureaucrat parameter constructor called" << endl; |
|||
} |
|||
|
|||
Bureaucrat::Bureaucrat (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat copy constructor called" << endl; |
|||
} |
|||
|
|||
Bureaucrat & Bureaucrat::operator= (Bureaucrat const & src) { |
|||
(void)src; |
|||
cout << "Bureaucrat assignment operator called" << endl; |
|||
return (*this); |
|||
} |
|||
|
|||
Bureaucrat::~Bureaucrat (void) { |
|||
cout << "Bureaucrat default destructor called" << endl; |
|||
} |
|||
|
|||
string Bureaucrat::getName(void) { |
|||
return (_name); |
|||
} |
|||
|
|||
size_t Bureaucrat::getGrade(void) { |
|||
return (_grade); |
|||
} |
|||
|
|||
GTHE::GTHE(void) { |
|||
|
|||
} |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b) { |
|||
out << b._name << ", bureaucrat grade " << b._grade << endl; |
|||
} |
|||
|
@ -0,0 +1,51 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Bureaucrat.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:06:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 16:57:34 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
#include <stdexcept> |
|||
using std::cout; |
|||
using std::endl; |
|||
using std::string; |
|||
|
|||
class Bureaucrat{ |
|||
string _name; |
|||
size_t _grade; |
|||
public: |
|||
Bureaucrat(void); |
|||
Bureaucrat(string name, size_t grade) throw (char*); |
|||
Bureaucrat(Bureaucrat const & src); |
|||
virtual ~Bureaucrat(void); |
|||
Bureaucrat & operator= (Bureaucrat const & src); |
|||
string getName(void); |
|||
size_t getGrade(void); |
|||
|
|||
typedef class GradeTooHighException GTHE; |
|||
class GradeTooHighException: virtual public std::exception |
|||
{ |
|||
GTHE(void); |
|||
~GTHE(void); |
|||
const char *GTHE::what(void); |
|||
}; |
|||
typedef class GradeTooLowException GTLE; |
|||
class GradeTooLowException: virtual public std::exception |
|||
{ |
|||
GTLE(void); |
|||
~GTLE(void); |
|||
const char *GTLE::what(void); |
|||
}; |
|||
|
|||
}; |
|||
|
|||
std::ostream &operator<< (std::ostream &out, Bureaucrat const &b); |
@ -0,0 +1,20 @@ |
|||
NAME = bureau |
|||
SRCS = main.cpp Bureaucrat.cpp |
|||
OBJS= $(SRCS:.cpp=.o) |
|||
|
|||
CXXFLAGS = -std=c++98 -Werror -Wextra -Wall |
|||
|
|||
$(NAME) : $(OBJS) |
|||
c++ $(OBJS) -o $(NAME) |
|||
|
|||
all : $(NAME) |
|||
|
|||
clean : |
|||
rm -rf $(OBJS) |
|||
|
|||
fclean : clean |
|||
rm -rf $(NAME) |
|||
|
|||
re : fclean all |
|||
|
|||
.PHONY : all clean fclean re |
@ -0,0 +1,26 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/24 13:16:27 by narnaud #+# #+# */ |
|||
/* Updated: 2022/06/24 14:38:36 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Bureaucrat.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
try { |
|||
Bureaucrat crat__one("first", 1); |
|||
Bureaucrat crat__two("last", 150); |
|||
Bureaucrat crat__three("trash", 151); |
|||
Bureaucrat crat__four("god", -55); |
|||
} |
|||
catch (std::exception & e) { |
|||
cout << "Issue :" << e.what(); |
|||
} |
|||
} |
Loading…
Reference in new issue