d04 correction deux erreurs
This commit is contained in:
@@ -1,22 +1,18 @@
|
|||||||
#include "HumanB.hpp"
|
#include "HumanB.hpp"
|
||||||
|
|
||||||
HumanB::HumanB( std::string name ) {
|
HumanB::HumanB( std::string name ) {
|
||||||
|
|
||||||
this->_name = name;
|
this->_name = name;
|
||||||
|
|
||||||
}
|
}
|
||||||
HumanB::~HumanB() {}
|
HumanB::~HumanB() {}
|
||||||
|
|
||||||
void HumanB::setWeapon( Weapon &weapon ) {
|
void HumanB::setWeapon( Weapon &weapon ) {
|
||||||
|
|
||||||
this->_weapon = &weapon;
|
this->_weapon = &weapon;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HumanB::attack( void ) {
|
void HumanB::attack( void ) {
|
||||||
|
if (!this->_weapon)
|
||||||
|
return;
|
||||||
std::cout << this->_name << " attacks with their ";
|
std::cout << this->_name << " attacks with their ";
|
||||||
std::cout << this->_weapon->getType() << std::endl;
|
std::cout << this->_weapon->getType() << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
#include "Weapon.hpp"
|
#include "Weapon.hpp"
|
||||||
|
|
||||||
Weapon::Weapon( std::string type ) {
|
Weapon::Weapon( std::string type ) {
|
||||||
|
|
||||||
this->_type = type;
|
this->_type = type;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
Weapon::~Weapon() {}
|
Weapon::~Weapon() {}
|
||||||
|
|
||||||
std::string const & Weapon::getType( void ) const {
|
std::string const & Weapon::getType( void ) const {
|
||||||
|
|
||||||
return this->_type;
|
return this->_type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Weapon::setType( std::string type ) {
|
void Weapon::setType( std::string type ) {
|
||||||
|
|
||||||
this->_type = type;
|
this->_type = type;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ int main()
|
|||||||
{
|
{
|
||||||
Weapon club = Weapon("crude spiked club");
|
Weapon club = Weapon("crude spiked club");
|
||||||
HumanB jim("Jim");
|
HumanB jim("Jim");
|
||||||
|
jim.attack();
|
||||||
jim.setWeapon(club);
|
jim.setWeapon(club);
|
||||||
jim.attack();
|
jim.attack();
|
||||||
club.setType("some other type of club");
|
club.setType("some other type of club");
|
||||||
|
|||||||
BIN
d01/ex03/war
Executable file
BIN
d01/ex03/war
Executable file
Binary file not shown.
66
d01/ex04/Makefile.replace
Normal file
66
d01/ex04/Makefile.replace
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
# . name = value . name is case sensitive #
|
||||||
|
# VARIABLES . or name = value \ . use VPATH only for .c #
|
||||||
|
# . value . or .cpp #
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
|
||||||
|
NAME = sed
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 -g3
|
||||||
|
|
||||||
|
VPATH = $(D_SRCS)
|
||||||
|
|
||||||
|
LIBS =
|
||||||
|
|
||||||
|
INCLUDES = -I$(D_HEADERS)
|
||||||
|
|
||||||
|
D_SRCS = .
|
||||||
|
SRCS = main.cpp \
|
||||||
|
Sed.cpp
|
||||||
|
|
||||||
|
D_HEADERS = .
|
||||||
|
HEADERS = Sed.hpp
|
||||||
|
|
||||||
|
D_OBJS = builds
|
||||||
|
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||||
|
|
||||||
|
RM_D_OBJS = rm -rf $(D_OBJS)
|
||||||
|
ifeq "$(D_OBJS)" "."
|
||||||
|
RM_D_OBJS =
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
# . target: prerequisites . $@ : target #
|
||||||
|
# RULES . recipe . $< : 1st prerequisite #
|
||||||
|
# . recipe . $^ : all prerequisites #
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(D_OBJS)/%.o: %.cpp | $(D_OBJS)
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
$(D_OBJS):
|
||||||
|
mkdir $@
|
||||||
|
|
||||||
|
$(OBJS): $(HEADERS:%=$(D_HEADERS)/%)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
$(CC) $(OBJS) -o $@ $(LIBS)
|
||||||
|
|
||||||
|
leaks: $(NAME)
|
||||||
|
valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) Makefile OBJS BANANE
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f $(OBJS)
|
||||||
|
rm -f *.replace
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
rm -f $(NAME)
|
||||||
|
$(RM_D_OBJS)
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY : all clean fclean re bonus run valgrind
|
||||||
@@ -16,20 +16,23 @@ void Sed::replace() {
|
|||||||
std::ofstream new_file(this->_new_file.c_str());
|
std::ofstream new_file(this->_new_file.c_str());
|
||||||
int len = this->_find.length();
|
int len = this->_find.length();
|
||||||
std::string str;
|
std::string str;
|
||||||
char c_str[len + 1];
|
char cstr[len + 1];
|
||||||
|
|
||||||
if (file.fail() || new_file.fail())
|
if (file.fail() || new_file.fail())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file.get(c_str, len + 1, EOF);
|
if (len)
|
||||||
str.assign(c_str);
|
file.get(cstr, len + 1, EOF);
|
||||||
|
else
|
||||||
|
file.get(cstr, len + 2, EOF);
|
||||||
|
str.assign(cstr);
|
||||||
while (!file.eof())
|
while (!file.eof())
|
||||||
{
|
{
|
||||||
if (this->_find.compare(str) == 0)
|
if (len && this->_find.compare(str) == 0)
|
||||||
{
|
{
|
||||||
new_file << this->_replacement;
|
new_file << this->_replacement;
|
||||||
file.get(c_str, len + 1, EOF);
|
file.get(cstr, len + 1, EOF);
|
||||||
str.assign(c_str);
|
str.assign(cstr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -39,6 +42,4 @@ void Sed::replace() {
|
|||||||
}
|
}
|
||||||
str.erase(str.end() - 1);
|
str.erase(str.end() - 1);
|
||||||
new_file << str;
|
new_file << str;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
d01/ex04/sed
Executable file
BIN
d01/ex04/sed
Executable file
Binary file not shown.
@@ -213,3 +213,43 @@ EOF
|
|||||||
)
|
)
|
||||||
run_tests
|
run_tests
|
||||||
|
|
||||||
|
# TEST 9 ########################################
|
||||||
|
TESTNAME="test9"
|
||||||
|
FIND=""
|
||||||
|
REPLACEMENT="p"
|
||||||
|
CONTENT=$(cat << EOF
|
||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
RESULT=$(cat << EOF
|
||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
run_tests
|
||||||
|
|
||||||
|
# TEST 10 ########################################
|
||||||
|
TESTNAME="test10"
|
||||||
|
FIND=""
|
||||||
|
REPLACEMENT=""
|
||||||
|
CONTENT=$(cat << EOF
|
||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
RESULT=$(cat << EOF
|
||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
run_tests
|
||||||
|
|
||||||
|
|||||||
4
d01/ex04/unitests/test_log/test9
Normal file
4
d01/ex04/unitests/test_log/test9
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
4
d01/ex04/unitests/test_log/test9.replace
Normal file
4
d01/ex04/unitests/test_log/test9.replace
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
No more tears, my heart is dry
|
||||||
|
I don't laugh and I don't cry
|
||||||
|
I don't think about you all the time
|
||||||
|
But when I do - I wonder why
|
||||||
Reference in New Issue
Block a user