narnaud
2 years ago
53 changed files with 769 additions and 102 deletions
Binary file not shown.
Binary file not shown.
@ -0,0 +1,96 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ClapTrap.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 10:53:50 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:26:32 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ClapTrap.hpp" |
|||
|
|||
int ClapTrap::amount = 0; |
|||
ClapTrap *ClapTrap::registery[128] = {NULL}; |
|||
|
|||
|
|||
ClapTrap::ClapTrap (void) { |
|||
|
|||
std::cout << "ClapTrap default constructor called " << endl; |
|||
} |
|||
|
|||
ClapTrap::ClapTrap (std::string name) |
|||
: _name(name), _health(10), _energy(10), _attack(0) { |
|||
if (ClapTrap::amount >= 128) |
|||
{ |
|||
delete ClapTrap::registery[amount % 128]; |
|||
cout << "There are too many Traps " << ClapTrap::registery[amount % 128]->getName() << " destroyed\n"; |
|||
} |
|||
cout << "ClapTrap " << name << " was created" << endl; |
|||
_id = ClapTrap::amount % 128; |
|||
ClapTrap::registery[ClapTrap::amount % 128] = this; |
|||
ClapTrap::amount++; |
|||
} |
|||
|
|||
ClapTrap::ClapTrap (ClapTrap const & src) { |
|||
_name = src.getName(); |
|||
} |
|||
|
|||
ClapTrap & ClapTrap::operator= (ClapTrap const & src) { |
|||
std::cout << "ClapTrap assignment operator called" << endl; |
|||
_name = src.getName(); |
|||
return (*this); |
|||
} |
|||
|
|||
ClapTrap::~ClapTrap (void) { |
|||
|
|||
std::cout << "ClapTrap " << _name << " was destroyed" << endl; |
|||
} |
|||
|
|||
void ClapTrap::attack(const std::string& target) { |
|||
if (_energy == 0 || _health == 0) |
|||
cout << _name << " is no more able to attack anyone" << endl; |
|||
else |
|||
{ |
|||
cout << _name << " attacked " << target << endl; |
|||
getClapTrap(target)->takeDamage(_attack); |
|||
_energy--; |
|||
} |
|||
} |
|||
|
|||
void ClapTrap::takeDamage(unsigned int amount) { |
|||
if (_health == 0) |
|||
cout << _name << " is already death" << endl; |
|||
else |
|||
cout << _name << " lose " << amount << " hp" << endl; |
|||
if (amount >= _health) |
|||
_health = 0; |
|||
else |
|||
_health -= amount; |
|||
} |
|||
|
|||
void ClapTrap::beRepaired(unsigned int amount) { |
|||
if (_energy == 0 || _health == 0) |
|||
cout << _name << " is no more able to repair anyone" << endl; |
|||
else |
|||
{ |
|||
cout << _name << " was repaired for " << amount << " hp" << endl; |
|||
_health += amount; |
|||
_energy--; |
|||
} |
|||
} |
|||
|
|||
std::string ClapTrap::getName(void) const { |
|||
return (_name); |
|||
} |
|||
|
|||
ClapTrap *ClapTrap::getClapTrap(std::string name) { |
|||
for (int i = 0; i < 128; i++) |
|||
{ |
|||
if (name == ClapTrap::registery[i]->getName()) |
|||
return (ClapTrap::registery[i]); |
|||
} |
|||
return (NULL); |
|||
} |
@ -0,0 +1,45 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ClapTrap.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:49:28 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
|
|||
#include <string> |
|||
#include <iostream> |
|||
using std::cout; |
|||
using std::endl; |
|||
|
|||
class ClapTrap { |
|||
|
|||
public: |
|||
static ClapTrap *registery[128]; |
|||
static int amount; |
|||
|
|||
ClapTrap (void); |
|||
ClapTrap (std::string name); |
|||
ClapTrap (ClapTrap const & src); |
|||
virtual ~ClapTrap (void); |
|||
|
|||
ClapTrap & operator= (ClapTrap const & src); |
|||
|
|||
virtual void attack(const std::string& target); |
|||
void takeDamage(unsigned int amount); |
|||
void beRepaired(unsigned int amount); |
|||
std::string getName(void) const; |
|||
static ClapTrap *getClapTrap(std::string name); |
|||
|
|||
protected: |
|||
std::string _name; |
|||
unsigned int _health; |
|||
unsigned int _energy; |
|||
unsigned int _attack; |
|||
unsigned int _id; |
|||
}; |
@ -0,0 +1,42 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* DiamondTrap.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ |
|||
/* Updated: 2022/08/03 10:30:43 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "DiamondTrap.hpp" |
|||
|
|||
DiamondTrap::DiamondTrap (std::string name): ScavTrap(name), FragTrap(name){ |
|||
cout << ScavTrap::_energy << endl; |
|||
ClapTrap::_name = name + "_clap_name"; |
|||
_name = name; |
|||
_health = FragTrap::_health; |
|||
_energy = ScavTrap::_energy; |
|||
_attack = FragTrap::_attack; |
|||
cout << name << "is now a DiamondTrap" << endl; |
|||
} |
|||
|
|||
DiamondTrap::~DiamondTrap (void) { |
|||
cout << "DiamondTrap " << _name << " was destroyed" << endl; |
|||
} |
|||
|
|||
void DiamondTrap::attack(const std::string& target) { |
|||
if (_energy == 0 || _health == 0) |
|||
cout << _name << " is no more able to attack" << endl; |
|||
else |
|||
{ |
|||
cout << _name << " heavily attacked " << target << endl; |
|||
getClapTrap(target)->takeDamage(_attack); |
|||
_energy--; |
|||
} |
|||
} |
|||
|
|||
void DiamondTrap::whoAmI(void) { |
|||
cout << "Name: " << _name << " - Clap name: " << ClapTrap::_name << endl; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* DiamondTrap.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:52:31 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include "ScavTrap.hpp" |
|||
#include "FragTrap.hpp" |
|||
|
|||
class DiamondTrap : public ScavTrap, public FragTrap { |
|||
std::string _name; |
|||
public: |
|||
DiamondTrap (std::string name); |
|||
~DiamondTrap (void); |
|||
void attack(const std::string& target); |
|||
void whoAmI(void); |
|||
}; |
@ -0,0 +1,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* FragTrap.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:29:38 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "FragTrap.hpp" |
|||
|
|||
FragTrap::FragTrap (std::string name):ClapTrap(name){ |
|||
_health = 100; |
|||
_energy = 100; |
|||
_attack = 30; |
|||
cout << "ClapTrap " << name << " evolved to FragTrap" << endl; |
|||
} |
|||
|
|||
FragTrap::~FragTrap (void) { |
|||
cout << "FragTrap " << _name << " was destroyed" << endl; |
|||
} |
|||
|
|||
void FragTrap::attack(const std::string& target) { |
|||
if (_energy == 0 || _health == 0) |
|||
cout << _name << " is no more able to attack anyone"; |
|||
else |
|||
{ |
|||
cout << _name << " hardly attacked " << target << endl; |
|||
getClapTrap(target)->takeDamage(_attack); |
|||
_energy--; |
|||
} |
|||
} |
|||
|
|||
void FragTrap::highFivesGuys(void) { |
|||
for (int i = 0; i < 128; i++) |
|||
{ |
|||
if (ClapTrap::registery[i]) |
|||
cout << _name << " high five " << ClapTrap::registery[i]->getName() << endl; |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* FragTrap.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:49:59 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include "ClapTrap.hpp" |
|||
|
|||
class FragTrap : virtual public ClapTrap { |
|||
|
|||
public: |
|||
FragTrap (std::string name); |
|||
~FragTrap (void); |
|||
void attack(const std::string& target); |
|||
void highFivesGuys(void); |
|||
}; |
@ -0,0 +1,20 @@ |
|||
NAME = diamondtrap |
|||
SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp DiamondTrap.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,43 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ScavTrap.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:27:49 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ScavTrap.hpp" |
|||
|
|||
ScavTrap::ScavTrap (std::string name) |
|||
:ClapTrap(name){ |
|||
_health = 100; |
|||
_energy = 50; |
|||
_attack = 20; |
|||
cout << "ClapTrap " << name << " evolved to ScavTrap" << endl; |
|||
} |
|||
|
|||
ScavTrap::~ScavTrap (void) { |
|||
cout << "ScavTrap " << _name << " was destroyed" << endl; |
|||
} |
|||
|
|||
void ScavTrap::attack(const std::string& target) { |
|||
if (_energy == 0 || _health == 0) |
|||
cout << _name << " is no more able to attack" << endl; |
|||
else |
|||
{ |
|||
cout << _name << " heavily attacked " << target << endl; |
|||
getClapTrap(target)->takeDamage(_attack); |
|||
_energy--; |
|||
} |
|||
} |
|||
|
|||
void ScavTrap::guardGate(void) { |
|||
if (_health == 0) |
|||
cout << _name << " is no more able to guard" << endl; |
|||
else |
|||
cout << _name << " is now in guard gate mode.\n"; |
|||
} |
@ -0,0 +1,24 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* ScavTrap.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:27:07 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#pragma once |
|||
#include "ClapTrap.hpp" |
|||
|
|||
class ScavTrap : virtual public ClapTrap { |
|||
|
|||
public: |
|||
|
|||
ScavTrap (std::string name); |
|||
~ScavTrap (void); |
|||
void attack(const std::string& target); |
|||
void guardGate(void); |
|||
}; |
@ -0,0 +1,30 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/06/23 10:53:16 by narnaud #+# #+# */ |
|||
/* Updated: 2022/07/19 02:47:30 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "ScavTrap.hpp" |
|||
#include "FragTrap.hpp" |
|||
#include "DiamondTrap.hpp" |
|||
|
|||
int main(void) |
|||
{ |
|||
ClapTrap a("A"); |
|||
ScavTrap b("B"); |
|||
FragTrap c("C"); |
|||
DiamondTrap d("D"); |
|||
|
|||
a.attack("B"); |
|||
b.attack("C"); |
|||
c.attack("B"); |
|||
c.highFivesGuys(); |
|||
d.attack("C"); |
|||
d.whoAmI(); |
|||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@ |
|||
NAME = templates |
|||
SRCS = main.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,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:05:29 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 08:13:45 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "main.hpp" |
|||
#include <iostream> |
|||
|
|||
int main( void ) { |
|||
int a = 2; |
|||
int b = 3; |
|||
std::cout << "a = " << a << ", b = " << b << std::endl; |
|||
::swap( a, b ); |
|||
std::cout << "a = " << a << ", b = " << b << std::endl; |
|||
std::cout << "min( a, b ) = " << ::min( a, b ) << std::endl; |
|||
std::cout << "max( a, b ) = " << ::max( a, b ) << std::endl; |
|||
std::string c = "chaine1"; |
|||
std::string d = "chaine2"; |
|||
::swap(c, d); |
|||
std::cout << "c = " << c << ", d = " << d << std::endl; |
|||
std::cout << "min( c, d ) = " << ::min( c, d ) << std::endl; |
|||
std::cout << "max( c, d ) = " << ::max( c, d ) << std::endl; |
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,29 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:05:52 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 08:13:08 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
template <class T> |
|||
void swap (T &t1, T &t2) { |
|||
T tmp; |
|||
tmp = t1; |
|||
t1 = t2; |
|||
t2 = tmp; |
|||
} |
|||
|
|||
template <class T> |
|||
T min (T &t1, T &t2) { |
|||
return (t1 < t2 ? t1 : t2); |
|||
} |
|||
|
|||
template <class T> |
|||
T max (T &t1, T &t2) { |
|||
return (t1 > t2 ? t1 : t2); |
|||
} |
@ -0,0 +1,21 @@ |
|||
NAME = iter |
|||
SRCS = main.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,19 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* iter.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:14:42 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 08:33:06 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
|
|||
template <class T> |
|||
void iter(T *arr, int length, void (*fct)(T)) { |
|||
for (int i = 0; i < length; i++) { |
|||
fct(arr[i]); |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:14:45 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 08:43:03 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include <iostream> |
|||
#include "iter.hpp" |
|||
|
|||
template <class T> |
|||
void put_t(T t) { |
|||
std::cout << t << std::endl; |
|||
} |
|||
|
|||
template <class T> |
|||
void put_square(T t) { |
|||
put_t(t * t); |
|||
} |
|||
|
|||
int main(void) { |
|||
int nbrs[5] = {1, 2, 3 , 4, 5}; |
|||
char words[5][4] = {"the", "one", "two", "get", "any"}; |
|||
|
|||
iter(nbrs, 5, put_t); |
|||
iter(nbrs, 3, put_square); |
|||
iter(words, 5, put_t); |
|||
} |
@ -0,0 +1,61 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* Array.hpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:50:55 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 11:23:19 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include <iostream> |
|||
|
|||
template <class T> class Array { |
|||
T *tab; |
|||
int nbr; |
|||
public: |
|||
Array() { |
|||
tab = new T[0]; |
|||
}; |
|||
|
|||
Array(int n) { |
|||
tab = new T[nbr = n]; |
|||
}; |
|||
|
|||
Array(const Array<T> &a) { |
|||
tab = new T[nbr = a.size()]; |
|||
for (int i = 0; i < nbr; i++) { |
|||
tab[i] = a[i]; |
|||
} |
|||
}; |
|||
|
|||
~Array() { |
|||
delete [] tab; |
|||
}; |
|||
|
|||
Array<T> &operator= (const Array<T> &a) { |
|||
delete [] tab; |
|||
nbr = a.size(); |
|||
tab = new T[nbr]; |
|||
for (int i = 0; i < nbr; i++) { |
|||
tab[i] = a[i]; |
|||
} |
|||
return (*this); |
|||
}; |
|||
|
|||
T &operator[] (int i) { |
|||
if (i >= nbr) throw (std::runtime_error("error: Array index out of bound.")); |
|||
return (tab[i]); |
|||
}; |
|||
|
|||
T operator[] (int i) const { |
|||
if (i >= nbr) throw (std::runtime_error("error: Array index out of bound.")); |
|||
return (tab[i]); |
|||
}; |
|||
|
|||
int size() const{ |
|||
return (nbr); |
|||
}; |
|||
}; |
@ -0,0 +1,20 @@ |
|||
NAME = array |
|||
SRCS = main.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,32 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* main.cpp :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/09/05 08:49:45 by narnaud #+# #+# */ |
|||
/* Updated: 2022/09/05 11:00:32 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#include "Array.hpp" |
|||
|
|||
int main(void) { |
|||
Array<char> a; |
|||
Array<char> b(10); |
|||
Array<char> c(b); |
|||
|
|||
b[3] = 'b'; |
|||
std::cout << b[3] << std::endl; |
|||
std::cout << b.size() << std::endl; |
|||
std::cout << c[3] << std::endl; |
|||
c = b; |
|||
std::cout << c[3] << std::endl; |
|||
|
|||
try { |
|||
std::cout << b[12] << std::endl; |
|||
} catch (std::exception &e) { |
|||
std::cout << e.what() << std::endl; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
NAME = easy_find |
|||
SRCS = |
|||
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 |
|||
|
Loading…
Reference in new issue