Compare commits
19 Commits
84b0db8c9c
...
master
Author | SHA1 | Date | |
---|---|---|---|
35cbcfd02d | |||
cebe9f6ea7 | |||
cc5928a671 | |||
5522ebf3ba | |||
a7e4a9cd75 | |||
7a10311d56 | |||
42a06c46cd | |||
efa91c0cb5 | |||
eb2b035b75 | |||
636365d65c | |||
5d687d7c28 | |||
3ef324e5e1 | |||
98ece4839e | |||
76d822b831 | |||
095cc3dc18 | |||
ea247970e4 | |||
cfee0e2ec4 | |||
55a7c73656 | |||
dcfb2af057 |
@ -1,25 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = zombie
|
||||
NAME = ex00
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
@ -1,19 +1,24 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <string>
|
||||
#include "./Zombie.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
Zombie::Zombie(std::string name)
|
||||
Zombie::Zombie()
|
||||
{
|
||||
this->name = name;
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
std::cout << "Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
Zombie::Zombie(const std::string& name)
|
||||
{
|
||||
std::cout << "Zombie(" << name << ")" << std::endl;
|
||||
this->_name = name;
|
||||
}
|
||||
|
||||
Zombie::~Zombie()
|
||||
{
|
||||
std::cout << this->name << ": " << "~Zombie()" << std::endl;
|
||||
std::cout << "~Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::announce() const
|
||||
void Zombie::announce()
|
||||
{
|
||||
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
class Zombie
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
Zombie(std::string name);
|
||||
Zombie(const std::string& name);
|
||||
Zombie();
|
||||
~Zombie();
|
||||
|
||||
void announce(void) const;
|
||||
void setName(std::string name);
|
||||
|
||||
void announce(void);
|
||||
};
|
||||
|
||||
Zombie* newZombie(std::string name);
|
||||
void randomChump(std::string name);
|
||||
Zombie* newZombie(std::string name);
|
||||
|
@ -2,11 +2,11 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
Zombie* jean;
|
||||
Zombie pierre("Pierre");
|
||||
|
||||
jean = new Zombie("jean");
|
||||
Zombie* jean = newZombie("jean");
|
||||
jean->announce();
|
||||
delete jean;
|
||||
randomChump("francois");
|
||||
|
||||
Zombie no_name;
|
||||
no_name.announce();
|
||||
return 0;
|
||||
}
|
||||
|
@ -2,8 +2,5 @@
|
||||
|
||||
Zombie* newZombie(std::string name)
|
||||
{
|
||||
Zombie* zombie;
|
||||
|
||||
zombie = new Zombie(name);
|
||||
return (zombie);
|
||||
return new Zombie(name);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <string>
|
||||
|
||||
void randomChump(std::string name)
|
||||
{
|
||||
Zombie zombie(name);
|
||||
|
||||
zombie.announce();
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = zombie
|
||||
NAME = ex01
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
BIN
ex01/bin/zombie
BIN
ex01/bin/zombie
Binary file not shown.
@ -1,30 +1,29 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <string>
|
||||
#include "./Zombie.hpp"
|
||||
#include <iostream>
|
||||
|
||||
Zombie::Zombie(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
}
|
||||
#include <string>
|
||||
|
||||
Zombie::Zombie()
|
||||
{
|
||||
this->name = "";
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
std::cout << "Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
Zombie::Zombie(const std::string& name)
|
||||
{
|
||||
std::cout << "Zombie(" << name << ")" << std::endl;
|
||||
this->_name = name;
|
||||
}
|
||||
|
||||
Zombie::~Zombie()
|
||||
{
|
||||
std::cout << this->name << ": " << "~Zombie()" << std::endl;
|
||||
std::cout << "~Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::announce() const
|
||||
void Zombie::announce()
|
||||
{
|
||||
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
std::cout << this->_name << ": BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::setName(std::string name)
|
||||
void Zombie::setName(const std::string &name)
|
||||
{
|
||||
this->name = name;
|
||||
this->_name = name;
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
class Zombie
|
||||
{
|
||||
private:
|
||||
std::string name;
|
||||
std::string _name;
|
||||
|
||||
public:
|
||||
Zombie(std::string name);
|
||||
Zombie();
|
||||
Zombie(const std::string& name);
|
||||
~Zombie();
|
||||
|
||||
void setName(std::string name);
|
||||
void announce(void) const;
|
||||
|
||||
void announce(void);
|
||||
void setName(const std::string& name);
|
||||
};
|
||||
|
||||
Zombie* zombieHorde(int N, std::string name);
|
||||
|
@ -1,13 +1,17 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
int main()
|
||||
{
|
||||
Zombie* jean;
|
||||
Zombie pierre("Pierre");
|
||||
|
||||
jean = new Zombie("jean");
|
||||
jean->announce();
|
||||
delete jean;
|
||||
jean = zombieHorde(3, "jean");
|
||||
Zombie* jean = zombieHorde(2, "jean");
|
||||
delete[] jean;
|
||||
|
||||
Zombie* bob = zombieHorde(4, "bob");
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
bob[i].announce();
|
||||
delete[] bob;
|
||||
Zombie* pierre = zombieHorde(-1, "pierre");
|
||||
if (pierre == NULL)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
Zombie* zombieHorde(int N, std::string name)
|
||||
{
|
||||
size_t i;
|
||||
Zombie *zombies;
|
||||
|
||||
if (0 > N)
|
||||
return (NULL);
|
||||
zombies = new Zombie[N];
|
||||
for (i = 0; i < (size_t) N; i++)
|
||||
return NULL;
|
||||
Zombie* zombies = new Zombie[N];
|
||||
for (int i = 0; i < N; i++)
|
||||
zombies[i].setName(name);
|
||||
return (zombies);
|
||||
return zombies;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = ref_vs_ptr
|
||||
NAME = ex02
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
Binary file not shown.
@ -1,4 +1,3 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
@ -8,11 +7,13 @@ int main()
|
||||
std::string* stringPTR = &string;
|
||||
std::string& stringREF = string;
|
||||
|
||||
std::cout << &string << std::endl;
|
||||
std::cout << stringPTR << std::endl;
|
||||
std::cout << &stringREF << std::endl;
|
||||
|
||||
std::cout << string << std::endl;
|
||||
std::cout << *stringPTR << std::endl;
|
||||
std::cout << stringREF << std::endl;
|
||||
std::cout << "ADDRESS" << std::endl;
|
||||
std::cout << "original: " << &string << std::endl;
|
||||
std::cout << "pointer: " << stringPTR << std::endl;
|
||||
std::cout << "reference: " << &stringREF << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << "VALUE" << std::endl;
|
||||
std::cout << "original: " << string << std::endl;
|
||||
std::cout << "pointer: " << *stringPTR << std::endl;
|
||||
std::cout << "reference: " << stringREF << std::endl;
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = Weapon
|
||||
NAME = ex03
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
@ -1,17 +1,21 @@
|
||||
#include "HumanA.hpp"
|
||||
#include "Weapon.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
HumanA::HumanA(std::string name, Weapon &weapon) : weapon(weapon)
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
HumanA::HumanA(const std::string& name, const Weapon& weapon):
|
||||
_weapon(weapon)
|
||||
{
|
||||
this->name = name;
|
||||
this->_name = name;
|
||||
std::cout << "HumanA()" << std::endl;
|
||||
}
|
||||
|
||||
HumanA::~HumanA()
|
||||
{}
|
||||
{
|
||||
std::cout << "~HumanA()" << std::endl;
|
||||
}
|
||||
|
||||
void HumanA::attack()
|
||||
{
|
||||
std::cout << this->name << " attacks with their " << this->weapon.getType() << std::endl;
|
||||
std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl;
|
||||
}
|
||||
|
@ -1,19 +1,18 @@
|
||||
#ifndef HUMANA_HPP
|
||||
# define HUMANA_HPP
|
||||
#pragma once
|
||||
|
||||
#include "Weapon.hpp"
|
||||
#include <string>
|
||||
|
||||
class HumanA
|
||||
{
|
||||
private:
|
||||
Weapon &weapon;
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
HumanA(std::string name, Weapon &weapon);
|
||||
HumanA(const std::string& name, const Weapon& weapon);
|
||||
~HumanA();
|
||||
|
||||
void attack();
|
||||
};
|
||||
|
||||
#endif
|
||||
private:
|
||||
const Weapon& _weapon;
|
||||
std::string _name;
|
||||
|
||||
};
|
||||
|
@ -1,29 +1,33 @@
|
||||
#include "HumanB.hpp"
|
||||
#include "Weapon.hpp"
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
HumanB::HumanB(std::string name)
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
HumanB::HumanB(const std::string& name)
|
||||
{
|
||||
this->weapon = NULL;
|
||||
this->name = name;
|
||||
std::cout << "HumanB()" << std::endl;
|
||||
this->_name = name;
|
||||
this->_weapon = NULL;
|
||||
}
|
||||
|
||||
HumanB::~HumanB()
|
||||
{}
|
||||
{
|
||||
std::cout << "~HumanB()" << std::endl;
|
||||
}
|
||||
|
||||
void HumanB::attack()
|
||||
{
|
||||
if (this->weapon == NULL)
|
||||
{
|
||||
std::cerr << this->name << " can't attack without weapon" << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << this->name << " attacks with their " << this->weapon->getType() << std::endl;
|
||||
std::cout << this->_name << " attacks with their ";
|
||||
if (this->_weapon == NULL)
|
||||
std::cout << "hands";
|
||||
else
|
||||
std::cout << this->_weapon->getType();
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void HumanB::setWeapon(Weapon& new_weapon)
|
||||
void HumanB::setWeapon(const Weapon &weapon)
|
||||
{
|
||||
this->weapon = &new_weapon;
|
||||
this->_weapon = &weapon;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
#ifndef HUMANB_HPP
|
||||
# define HUMANB_HPP
|
||||
#pragma once
|
||||
|
||||
#include "Weapon.hpp"
|
||||
#include <string>
|
||||
|
||||
class HumanB
|
||||
{
|
||||
private:
|
||||
Weapon* weapon;
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
HumanB(std::string name);
|
||||
HumanB(const std::string& name);
|
||||
~HumanB();
|
||||
|
||||
void setWeapon(Weapon& new_weapon);
|
||||
void attack();
|
||||
void setWeapon(const Weapon& weapon);
|
||||
|
||||
private:
|
||||
const Weapon* _weapon;
|
||||
std::string _name;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
@ -1,24 +1,42 @@
|
||||
#include "Weapon.hpp"
|
||||
#include <string>
|
||||
|
||||
Weapon::Weapon(std::string type)
|
||||
{
|
||||
this->type = type;
|
||||
}
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
Weapon::Weapon()
|
||||
{
|
||||
std::cout << "Weapon()" << std::endl;
|
||||
}
|
||||
|
||||
Weapon::Weapon(const Weapon& src)
|
||||
{
|
||||
std::cout << "Weapon()" << std::endl;
|
||||
this->_type = src._type;
|
||||
}
|
||||
|
||||
Weapon::Weapon(const std::string& type)
|
||||
{
|
||||
std::cout << "Weapon()" << std::endl;
|
||||
this->_type = type;
|
||||
}
|
||||
|
||||
Weapon::~Weapon()
|
||||
{}
|
||||
|
||||
std::string Weapon::getType()
|
||||
{
|
||||
return (this->type);
|
||||
std::cout << "~Weapon()" << std::endl;
|
||||
}
|
||||
|
||||
void Weapon::setType(std::string new_type)
|
||||
Weapon& Weapon::operator=(const Weapon &src)
|
||||
{
|
||||
this->type = new_type;
|
||||
this->_type = src._type;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Weapon::setType(const std::string& newType)
|
||||
{
|
||||
this->_type = newType;
|
||||
}
|
||||
|
||||
const std::string& Weapon::getType() const
|
||||
{
|
||||
return this->_type;
|
||||
}
|
||||
|
@ -1,18 +1,20 @@
|
||||
#ifndef WEAPON_HPP
|
||||
# define WEAPON_HPP
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Weapon
|
||||
{
|
||||
private:
|
||||
std::string type;
|
||||
|
||||
public:
|
||||
Weapon(std::string type);
|
||||
Weapon();
|
||||
Weapon(const Weapon& src);
|
||||
Weapon(const std::string& type);
|
||||
~Weapon();
|
||||
|
||||
std::string getType();
|
||||
void setType(std::string new_type);
|
||||
Weapon& operator=(const Weapon& src);
|
||||
|
||||
const std::string& getType() const;
|
||||
void setType(const std::string& newType);
|
||||
|
||||
private:
|
||||
std::string _type;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "Weapon.hpp"
|
||||
#include "HumanA.hpp"
|
||||
#include "HumanB.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@ -19,5 +17,7 @@ int main()
|
||||
club.setType("some other type of club");
|
||||
jim.attack();
|
||||
}
|
||||
HumanB jim("Jim");
|
||||
jim.attack();
|
||||
return 0;
|
||||
}
|
||||
|
25
ex04/Makefile
Normal file
25
ex04/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
NAME = sed
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
@ -8,17 +8,13 @@
|
||||
static int get_text(const char *path, std::string &text)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
std::string line;
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cerr << "sed: file error" << std::endl;
|
||||
return (1);
|
||||
}
|
||||
while (std::getline(file, line))
|
||||
text += line + "\n";
|
||||
if (text.size() != 0)
|
||||
text.erase(text.size() - 1);
|
||||
std::getline(file, text, '\0');
|
||||
file.close();
|
||||
return (0);
|
||||
}
|
||||
@ -60,7 +56,12 @@ int main(int ac, char **av)
|
||||
}
|
||||
if (get_text(av[1], text))
|
||||
return (2);
|
||||
std::cout << text << std::endl;
|
||||
replaced = replace_text(text.c_str(), av[2], av[3]);
|
||||
std::cout << replaced << std::endl;
|
||||
std::ofstream file((std::string(av[1]) + std::string(".replace")).c_str());
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cerr << "sed: file error" << std::endl;
|
||||
return (1);
|
||||
}
|
||||
file << replaced;
|
||||
}
|
||||
|
25
ex05/Makefile
Normal file
25
ex05/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
NAME = ex05
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
46
ex05/src/Harl.cpp
Normal file
46
ex05/src/Harl.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "Harl.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void Harl::complain(std::string level)
|
||||
{
|
||||
static const HarlMethod methods[4] = {
|
||||
&Harl::debug,
|
||||
&Harl::info,
|
||||
&Harl::warning,
|
||||
&Harl::error,
|
||||
};
|
||||
static const std::string strings[4] = {
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"ERROR"
|
||||
};
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
{
|
||||
if (strings[i] == level)
|
||||
{
|
||||
(this->*methods[i])();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Harl::debug()
|
||||
{
|
||||
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do !" << std::endl;
|
||||
}
|
||||
|
||||
void Harl::info()
|
||||
{
|
||||
std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger ! If you did, I wouldn’t be asking for more !" << std::endl;
|
||||
}
|
||||
|
||||
void Harl::warning()
|
||||
{
|
||||
std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years whereas you started working here since last month." << std::endl;
|
||||
}
|
||||
|
||||
void Harl::error()
|
||||
{
|
||||
std::cout << "This is unacceptable ! I want to speak to the manager now." << std::endl;
|
||||
}
|
17
ex05/src/Harl.hpp
Normal file
17
ex05/src/Harl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Harl
|
||||
{
|
||||
private:
|
||||
void debug();
|
||||
void info();
|
||||
void warning();
|
||||
void error();
|
||||
|
||||
public:
|
||||
void complain(std::string level);
|
||||
};
|
||||
|
||||
typedef void (Harl::*HarlMethod)();
|
19
ex05/src/main.cpp
Normal file
19
ex05/src/main.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "Harl.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Harl harl;
|
||||
static const std::string levels[] = {
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"GOLEM",
|
||||
"ERROR",
|
||||
"PASLU",
|
||||
"FLEMME",
|
||||
"PANIC"
|
||||
};
|
||||
for (int i = 0; i < 6; i++)
|
||||
harl.complain(levels[i]);
|
||||
return 0;
|
||||
}
|
25
ex06/Makefile
Normal file
25
ex06/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CPPFLAGS = -std=c++98 -Wall -Wextra -Werror -g
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
NAME = ex06
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
mkdir -p obj
|
||||
$(CXX) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CXX) $(CPPFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(NAME)
|
||||
|
||||
re: fclean all
|
51
ex06/src/Harl.cpp
Normal file
51
ex06/src/Harl.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "Harl.hpp"
|
||||
#include <iostream>
|
||||
|
||||
void Harl::complain(std::string level)
|
||||
{
|
||||
static const std::string strings[4] = {
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"ERROR"
|
||||
};
|
||||
|
||||
size_t i = 0;
|
||||
for (; i < 4; i++)
|
||||
if (strings[i] == level)
|
||||
break;
|
||||
switch(i) {
|
||||
case 0:
|
||||
debug();
|
||||
case 1:
|
||||
info();
|
||||
case 2:
|
||||
warning();
|
||||
case 3:
|
||||
error();
|
||||
break;
|
||||
default:
|
||||
std::cout << "Not a level" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Harl::debug()
|
||||
{
|
||||
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-special-ketchup burger. I really do !" << std::endl;
|
||||
}
|
||||
|
||||
void Harl::info()
|
||||
{
|
||||
std::cout << "I cannot believe adding extra bacon costs more money. You didn’t put enough bacon in my burger ! If you did, I wouldn’t be asking for more !" << std::endl;
|
||||
}
|
||||
|
||||
void Harl::warning()
|
||||
{
|
||||
std::cout << "I think I deserve to have some extra bacon for free. I’ve been coming for years whereas you started working here since last month." << std::endl;
|
||||
}
|
||||
|
||||
void Harl::error()
|
||||
{
|
||||
std::cout << "This is unacceptable ! I want to speak to the manager now." << std::endl;
|
||||
}
|
17
ex06/src/Harl.hpp
Normal file
17
ex06/src/Harl.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
class Harl
|
||||
{
|
||||
private:
|
||||
void debug();
|
||||
void info();
|
||||
void warning();
|
||||
void error();
|
||||
|
||||
public:
|
||||
void complain(std::string level);
|
||||
};
|
||||
|
||||
typedef void (Harl::*HarlMethod)();
|
10
ex06/src/main.cpp
Normal file
10
ex06/src/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "Harl.hpp"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc <= 1)
|
||||
return 1;
|
||||
Harl harl;
|
||||
harl.complain(argv[1]);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user