init: ex00-02
This commit is contained in:
commit
f1d178366c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.o
|
25
ex00/Makefile
Normal file
25
ex00/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = zombie
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
re: fclean all
|
BIN
ex00/bin/zombie
Executable file
BIN
ex00/bin/zombie
Executable file
Binary file not shown.
19
ex00/src/Zombie.cpp
Normal file
19
ex00/src/Zombie.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
Zombie::Zombie(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
Zombie::~Zombie()
|
||||
{
|
||||
std::cout << this->name << ": " << "~Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::announce() const
|
||||
{
|
||||
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
}
|
18
ex00/src/Zombie.hpp
Normal file
18
ex00/src/Zombie.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
Zombie(std::string name);
|
||||
~Zombie();
|
||||
|
||||
void announce(void) const;
|
||||
void setName(std::string name);
|
||||
|
||||
};
|
||||
|
||||
Zombie* newZombie(std::string name);
|
||||
void randomChump(std::string name);
|
12
ex00/src/main.cpp
Normal file
12
ex00/src/main.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Zombie* jean;
|
||||
Zombie pierre("Pierre");
|
||||
|
||||
jean = new Zombie("jean");
|
||||
jean->announce();
|
||||
delete jean;
|
||||
randomChump("francois");
|
||||
}
|
9
ex00/src/newZombie.cpp
Normal file
9
ex00/src/newZombie.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
Zombie* newZombie(std::string name)
|
||||
{
|
||||
Zombie* zombie;
|
||||
|
||||
zombie = new Zombie(name);
|
||||
return (zombie);
|
||||
}
|
8
ex00/src/randomChump.cpp
Normal file
8
ex00/src/randomChump.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
void randomChump(std::string name)
|
||||
{
|
||||
Zombie zombie(name);
|
||||
|
||||
zombie.announce();
|
||||
}
|
25
ex01/Makefile
Normal file
25
ex01/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = zombie
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
re: fclean all
|
BIN
ex01/bin/zombie
Executable file
BIN
ex01/bin/zombie
Executable file
Binary file not shown.
30
ex01/src/Zombie.cpp
Normal file
30
ex01/src/Zombie.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
Zombie::Zombie(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
Zombie::Zombie()
|
||||
{
|
||||
this->name = "";
|
||||
std::cout << this->name << ": " << "Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
Zombie::~Zombie()
|
||||
{
|
||||
std::cout << this->name << ": " << "~Zombie()" << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::announce() const
|
||||
{
|
||||
std::cout << this->name << ": " << "BraiiiiiiinnnzzzZ..." << std::endl;
|
||||
}
|
||||
|
||||
void Zombie::setName(std::string name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
18
ex01/src/Zombie.hpp
Normal file
18
ex01/src/Zombie.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <string>
|
||||
|
||||
class Zombie {
|
||||
|
||||
private:
|
||||
std::string name;
|
||||
|
||||
public:
|
||||
Zombie(std::string name);
|
||||
Zombie();
|
||||
~Zombie();
|
||||
|
||||
void setName(std::string name);
|
||||
void announce(void) const;
|
||||
|
||||
};
|
||||
|
||||
Zombie* zombieHorde(int N, std::string name);
|
13
ex01/src/main.cpp
Normal file
13
ex01/src/main.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "Zombie.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
Zombie* jean;
|
||||
Zombie pierre("Pierre");
|
||||
|
||||
jean = new Zombie("jean");
|
||||
jean->announce();
|
||||
delete jean;
|
||||
jean = zombieHorde(3, "jean");
|
||||
delete[] jean;
|
||||
}
|
15
ex01/src/zombieHorde.cpp
Normal file
15
ex01/src/zombieHorde.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include "Zombie.hpp"
|
||||
#include <cstddef>
|
||||
|
||||
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++)
|
||||
zombies[i].setName(name);
|
||||
return (zombies);
|
||||
}
|
25
ex02/Makefile
Normal file
25
ex02/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
CXX = c++
|
||||
CXXFLAGS = -std=c++98 -Wall -Wextra -Werror -g -O0
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
BINDIR = bin
|
||||
EXECUTABLE = ref_vs_ptr
|
||||
|
||||
SRCS = $(wildcard $(SRCDIR)/*.cpp)
|
||||
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
all: $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(BINDIR)/$(EXECUTABLE): $(OBJS)
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR)/*.o
|
||||
|
||||
fclean: clean
|
||||
rm -fr $(BINDIR)/$(EXECUTABLE)
|
||||
|
||||
re: fclean all
|
BIN
ex02/bin/ref_vs_ptr
Executable file
BIN
ex02/bin/ref_vs_ptr
Executable file
Binary file not shown.
0
ex02/main.cpp
Normal file
0
ex02/main.cpp
Normal file
18
ex02/src/main.cpp
Normal file
18
ex02/src/main.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string string = "HI THIS IS BRAIN";
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user