This commit is contained in:
Ladebeze66 2024-02-20 15:35:19 +01:00
parent a5816720e4
commit 93c619a3c7
267 changed files with 10113 additions and 0 deletions

61
cpp00/ex00/Makefile Normal file
View File

@ -0,0 +1,61 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/23 16:15:46 by fgras-ca #+# #+# #
# Updated: 2023/12/23 16:39:11 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = megaphone
SRC = megaphone.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation megaphone... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./megaphone" with arguments or not!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

BIN
cpp00/ex00/a.out Executable file

Binary file not shown.

BIN
cpp00/ex00/megaphone Executable file

Binary file not shown.

35
cpp00/ex00/megaphone.cpp Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* megaphone.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 16:14:56 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 16:28:52 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <cctype>
#include <string>
int main(int argc, char **argv)
{
if (argc == 1)
{
std::cout << "* LOUD AND UNBEARABLE FEEDBACK NOISE *" << std::endl;
return (0);
}
for (int i = 1; i < argc; i++)
{
char *str = argv[i];
for (int j = 0; str[j]; j++)
{
std::cout << (char)toupper(str[j]);
}
std::cout << " ";
}
std::cout << std::endl;
return (0);
}

BIN
cpp00/ex00/megaphone.o Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp00/ex01/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex01/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

108
cpp00/ex01/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,108 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

97
cpp00/ex01/Contact.cpp Normal file
View File

@ -0,0 +1,97 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Contact.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 17:17:14 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 20:52:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Contact.hpp"
Contact::Contact() {}
void Contact::SetDetails()
{
std::cout << "First Name: ";
std::cin >> _first_name;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Last Name: ";
std::cin >> _last_name;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Nickname: ";
std::cin >> _nickname;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
while (true)
{
std::cout << "Phone Number: ";
std::cin >> _phone_number;
bool isValid = true;
for (char c : _phone_number)
{
if (!std::isdigit(c))
{
isValid = false;
break;
}
}
if (isValid)
{
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
break;
}
else
{
std::cout << "Invalid input. A phone number should contain only digits (0-9)." << std::endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
}
std::cout << "Darkest Secret: ";
std::getline(std::cin, _darkest_secret);
}
Contact::~Contact() {}
void Contact::DisplaySummary(int index) const
{
std::string redBar = "\033[31m|\033[0m";
std::cout << std::setw(8) << index << redBar;
if (_first_name.length() > 10)
{
std::cout << std::setw(10) << _first_name.substr(0,9) + "." << redBar;
}
else
{
std::cout << std::setw(10) << _first_name << redBar;
}
if (_last_name.length() > 10)
{
std::cout << std::setw(10) << _last_name.substr(0,9) + "." << redBar;
}
else
{
std::cout << std::setw(10) << _last_name << redBar;
}
if (_nickname.length() > 10)
{
std::cout << std::setw(10) << _nickname.substr(0,9) + "." << redBar;
}
else
{
std::cout << std::setw(10) << _nickname << redBar;
}
std::cout << std::endl;
}
void Contact::DisplayDetails() const
{
std::cout << "First Name: " << _first_name << std::endl;
std::cout << "Last Name: " << _last_name << std::endl;
std::cout << "Nickname: " << _nickname << std::endl;
std::cout << "Phone Number: " << _phone_number << std::endl;
std::cout << "Darkest Secret: " << _darkest_secret << std::endl;
}

38
cpp00/ex01/Contact.hpp Normal file
View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Contact.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 16:56:55 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 19:49:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CONTACT_HPP
# define CONTACT_HPP
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>
class Contact
{
public:
Contact();
~Contact();
void SetDetails();
void DisplaySummary(int index) const;
void DisplayDetails() const;
private:
std::string _first_name;
std::string _last_name;
std::string _nickname;
std::string _phone_number;
std::string _darkest_secret;
};
#endif

BIN
cpp00/ex01/Contact.o Normal file

Binary file not shown.

63
cpp00/ex01/Makefile Normal file
View File

@ -0,0 +1,63 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/23 18:31:36 by fgras-ca #+# #+# #
# Updated: 2023/12/23 19:06:37 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = phonebook
SRC = PhoneBook.cpp \
Contact.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation bookphone... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./phonebook"!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

69
cpp00/ex01/PhoneBook.cpp Normal file
View File

@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 18:01:39 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 20:52:57 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "PhoneBook.hpp"
PhoneBook::PhoneBook() : next_index(0), total_contacts(0) {}
PhoneBook::~PhoneBook() {}
void PhoneBook::AddContact()
{
contacts[next_index].SetDetails();
next_index = (next_index + 1) % 8;
if (total_contacts < 8)
{
total_contacts++;
}
std::cout << "Contact added successfully!" << std::endl;
}
void PhoneBook::SearchContact() const
{
std::cout << "\033[31m";
std::cout << "------------------------------------------" << std::endl;
std::cout << std::setw(8) << "Index" << "|"
<< std::setw(10) << "First" << "|"
<< std::setw(10) << "Last" << "|"
<< std::setw(10) << "Nickname" << "|" << std::endl;
std::cout << "------------------------------------------" << std::endl;
std::cout << "\033[0m";
for (int i = 0; i < total_contacts; ++i)
{
contacts[i].DisplaySummary(i + 1);
}
std::cout << "\033[31m";
std::cout << "------------------------------------------" << std::endl;
std::cout << "\033[0m";
while (true)
{
std::cout << "Enter the index of the contact to display: ";
int index;
std::cin >> index;
if (std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << "Invalid input. Please enter a number." << std::endl;
}
else if (index < 1 || index > total_contacts)
{
std::cout << "Invalid index. Please enter a number between 1 and " << total_contacts << "." << std::endl;
}
else
{
contacts[index - 1].DisplayDetails();
break;
}
}
}

37
cpp00/ex01/PhoneBook.hpp Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PhoneBook.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 17:55:10 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 19:52:34 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PHONEBOOK_HPP
# define PHONEBOOK_HPP
#include "Contact.hpp"
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
class PhoneBook
{
public:
PhoneBook();
~PhoneBook();
void AddContact();
void SearchContact() const;
private:
Contact contacts[8];
int next_index;
int total_contacts;
};
#endif

BIN
cpp00/ex01/PhoneBook.o Normal file

Binary file not shown.

44
cpp00/ex01/main.cpp Normal file
View File

@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/23 18:16:58 by fgras-ca #+# #+# */
/* Updated: 2023/12/23 18:31:05 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Contact.hpp"
#include "PhoneBook.hpp"
int main()
{
PhoneBook phonebook;
std::string command;
while (true)
{
std::cout << "Enter command (ADD, SEARCH, or EXIT): ";
std::cin >> command;
if (command == "ADD")
{
phonebook.AddContact();
}
else if (command == "SEARCH")
{
phonebook.SearchContact();
}
else if (command == "EXIT")
{
break;
}
else
{
std::cout << "Command not recognized." << std::endl;
}
}
return (0);
}

BIN
cpp00/ex01/main.o Normal file

Binary file not shown.

BIN
cpp00/ex01/phonebook Executable file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp00/ex02/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex02",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp00/ex02/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp00/ex02/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

View File

@ -0,0 +1,59 @@
[19920104_091532] index:0;amount:42;created
[19920104_091532] index:1;amount:54;created
[19920104_091532] index:2;amount:957;created
[19920104_091532] index:3;amount:432;created
[19920104_091532] index:4;amount:1234;created
[19920104_091532] index:5;amount:0;created
[19920104_091532] index:6;amount:754;created
[19920104_091532] index:7;amount:16576;created
[19920104_091532] accounts:8;total:20049;deposits:0;withdrawals:0
[19920104_091532] index:0;amount:42;deposits:0;withdrawals:0
[19920104_091532] index:1;amount:54;deposits:0;withdrawals:0
[19920104_091532] index:2;amount:957;deposits:0;withdrawals:0
[19920104_091532] index:3;amount:432;deposits:0;withdrawals:0
[19920104_091532] index:4;amount:1234;deposits:0;withdrawals:0
[19920104_091532] index:5;amount:0;deposits:0;withdrawals:0
[19920104_091532] index:6;amount:754;deposits:0;withdrawals:0
[19920104_091532] index:7;amount:16576;deposits:0;withdrawals:0
[19920104_091532] index:0;p_amount:42;deposit:5;amount:47;nb_deposits:1
[19920104_091532] index:1;p_amount:54;deposit:765;amount:819;nb_deposits:1
[19920104_091532] index:2;p_amount:957;deposit:564;amount:1521;nb_deposits:1
[19920104_091532] index:3;p_amount:432;deposit:2;amount:434;nb_deposits:1
[19920104_091532] index:4;p_amount:1234;deposit:87;amount:1321;nb_deposits:1
[19920104_091532] index:5;p_amount:0;deposit:23;amount:23;nb_deposits:1
[19920104_091532] index:6;p_amount:754;deposit:9;amount:763;nb_deposits:1
[19920104_091532] index:7;p_amount:16576;deposit:20;amount:16596;nb_deposits:1
[19920104_091532] accounts:8;total:21524;deposits:8;withdrawals:0
[19920104_091532] index:0;amount:47;deposits:1;withdrawals:0
[19920104_091532] index:1;amount:819;deposits:1;withdrawals:0
[19920104_091532] index:2;amount:1521;deposits:1;withdrawals:0
[19920104_091532] index:3;amount:434;deposits:1;withdrawals:0
[19920104_091532] index:4;amount:1321;deposits:1;withdrawals:0
[19920104_091532] index:5;amount:23;deposits:1;withdrawals:0
[19920104_091532] index:6;amount:763;deposits:1;withdrawals:0
[19920104_091532] index:7;amount:16596;deposits:1;withdrawals:0
[19920104_091532] index:0;p_amount:47;withdrawal:refused
[19920104_091532] index:1;p_amount:819;withdrawal:34;amount:785;nb_withdrawals:1
[19920104_091532] index:2;p_amount:1521;withdrawal:657;amount:864;nb_withdrawals:1
[19920104_091532] index:3;p_amount:434;withdrawal:4;amount:430;nb_withdrawals:1
[19920104_091532] index:4;p_amount:1321;withdrawal:76;amount:1245;nb_withdrawals:1
[19920104_091532] index:5;p_amount:23;withdrawal:refused
[19920104_091532] index:6;p_amount:763;withdrawal:657;amount:106;nb_withdrawals:1
[19920104_091532] index:7;p_amount:16596;withdrawal:7654;amount:8942;nb_withdrawals:1
[19920104_091532] accounts:8;total:12442;deposits:8;withdrawals:6
[19920104_091532] index:0;amount:47;deposits:1;withdrawals:0
[19920104_091532] index:1;amount:785;deposits:1;withdrawals:1
[19920104_091532] index:2;amount:864;deposits:1;withdrawals:1
[19920104_091532] index:3;amount:430;deposits:1;withdrawals:1
[19920104_091532] index:4;amount:1245;deposits:1;withdrawals:1
[19920104_091532] index:5;amount:23;deposits:1;withdrawals:0
[19920104_091532] index:6;amount:106;deposits:1;withdrawals:1
[19920104_091532] index:7;amount:8942;deposits:1;withdrawals:1
[19920104_091532] index:0;amount:47;closed
[19920104_091532] index:1;amount:785;closed
[19920104_091532] index:2;amount:864;closed
[19920104_091532] index:3;amount:430;closed
[19920104_091532] index:4;amount:1245;closed
[19920104_091532] index:5;amount:23;closed
[19920104_091532] index:6;amount:106;closed
[19920104_091532] index:7;amount:8942;closed

119
cpp00/ex02/Account.cpp Normal file
View File

@ -0,0 +1,119 @@
// ************************************************************************** //
// //
// Account.cpp for GlobalBanksters United //
// Created on : Sat Dec 23 19:43:15 2023 //
// //
// Made by : fgras-ca //
// //
// ************************************************************************** //
#include "Account.hpp"
#include <iostream>
#include <string>
#include <ctime>
#include <iomanip>
// Initialisation des variables statiques
int Account::_nbAccounts = 0;
int Account::_totalAmount = 0;
int Account::_totalNbDeposits = 0;
int Account::_totalNbWithdrawals = 0;
// Constructeur : Initialise un compte avec un dépôt initial et met à jour les informations globales
Account::Account(int initial_deposit) : _amount(initial_deposit), _nbDeposits(0), _nbWithdrawals(0)
{
_accountIndex = _nbAccounts++; // Assignation d'un index unique au compte et incrémentation du nombre total de comptes
_totalAmount += _amount; // Mise à jour du montant total détenu par tous les comptes
_displayTimestamp(); // Affichage de l'horodatage de la création du compte
std::cout << "index:" << _accountIndex << ";amount:" << _amount << ";created\n"; // Enregistrement de la création du compte
}
// Destructeur : Met à jour les informations globales lors de la fermeture d'un compte
Account::~Account()
{
_nbAccounts--; // Décrémentation du nombre total de comptes
_totalAmount -= _amount; // Mise à jour du montant total détenu par tous les comptes
_displayTimestamp(); // Affichage de l'horodatage de la fermeture du compte
std::cout << "index:" << _accountIndex << ";amount:" << _amount << ";closed\n"; // Enregistrement de la fermeture du compte
}
// Dépôts : Ajoute un montant au compte et met à jour les informations globales
void Account::makeDeposit(int deposit)
{
_displayTimestamp(); // Affichage de l'horodatage de l'opération
std::cout << "index:" << _accountIndex << ";p_amount:" << _amount << ";deposit:" << deposit;
_amount += deposit; // Mise à jour du montant dans le compte
_nbDeposits++; // Incrémentation du nombre de dépôts pour ce compte
_totalAmount += deposit; // Mise à jour du montant total détenu par tous les comptes
_totalNbDeposits++; // Incrémentation du nombre total de dépôts effectués sur tous les comptes
std::cout << ";amount:" << _amount << ";nb_deposits:" << _nbDeposits << "\n"; // Enregistrement de l'opération de dépôt
}
// Retraits : Diminue le montant du compte si possible et met à jour les informations globales
bool Account::makeWithdrawal(int withdrawal)
{
_displayTimestamp(); // Affichage de l'horodatage de l'opération
std::cout << "index:" << _accountIndex << ";p_amount:" << _amount << ";withdrawal:";
if (withdrawal > _amount)
{ // Vérification si le retrait est possible (fonds suffisants)
std::cout << "refused\n"; // Enregistrement d'un retrait refusé
return (false);
}
_amount -= withdrawal; // Mise à jour du montant dans le compte
_nbWithdrawals++; // Incrémentation du nombre de retraits pour ce compte
_totalAmount -= withdrawal; // Mise à jour du montant total détenu par tous les comptes
_totalNbWithdrawals++; // Incrémentation du nombre total de retraits effectués sur tous les comptes
std::cout << withdrawal << ";amount:" << _amount << ";nb_withdrawals:" << _nbWithdrawals << "\n"; // Enregistrement de l'opération de retrait
return (true);
}
// Vérifier le montant : Retourne le montant actuel du compte
int Account::checkAmount() const
{
return (_amount);
}
// Afficher le statut du compte : Affiche les informations détaillées sur le compte
void Account::displayStatus() const
{
_displayTimestamp(); // Affichage de l'horodatage de l'opération
std::cout << "index:" << _accountIndex << ";amount:" << _amount
<< ";deposits:" << _nbDeposits << ";withdrawals:" << _nbWithdrawals << "\n"; // Enregistrement de l'état actuel du compte
}
// Retourner le nombre total de comptes
int Account::getNbAccounts() { return _nbAccounts; }
// Retourner le montant total détenu par tous les comptes
int Account::getTotalAmount() { return _totalAmount; }
// Retourner le nombre total de dépôts effectués sur tous les comptes
int Account::getNbDeposits() { return _totalNbDeposits; }
// Retourner le nombre total de retraits effectués sur tous les comptes
int Account::getNbWithdrawals() { return _totalNbWithdrawals; }
// Afficher les informations globales de tous les comptes
void Account::displayAccountsInfos()
{
_displayTimestamp(); // Affichage de l'horodatage de l'opération
std::cout << "accounts:" << getNbAccounts() << ";total:" << getTotalAmount()
<< ";deposits:" << getNbDeposits() << ";withdrawals:" << getNbWithdrawals() << "\n"; // Enregistrement des informations globales
}
void Account::_displayTimestamp()
{
// Obtenir l'heure et la date actuelles
std::time_t now = std::time(nullptr);
std::tm *ltm = std::localtime(&now);
std::cout << "["
<< 1900 + ltm->tm_year // Ajouter 1900 pour obtenir l'année complète
<< std::setw(2) << std::setfill('0') << 1 + ltm->tm_mon // Mois (0-11 donc +1 pour 1-12)
<< std::setw(2) << std::setfill('0') << ltm->tm_mday // Jour (1-31)
<< "_"
<< std::setw(2) << std::setfill('0') << ltm->tm_hour // Heures (0-23)
<< std::setw(2) << std::setfill('0') << ltm->tm_min // Minutes (0-59)
<< std::setw(2) << std::setfill('0') << ltm->tm_sec // Secondes (0-59)
<< "] ";
}

69
cpp00/ex02/Account.hpp Normal file
View File

@ -0,0 +1,69 @@
// ************************************************************************** //
// //
// Account.hpp for GlobalBanksters United //
// Created on : Thu Nov 20 19:43:15 1989 //
// Last update : Wed Jan 04 14:54:06 1992 //
// Made by : Brad "Buddy" McLane <bm@gbu.com> //
// //
// ************************************************************************** //
#pragma once
#ifndef __ACCOUNT_H__
#define __ACCOUNT_H__
// ************************************************************************** //
// Account Class //
// ************************************************************************** //
class Account {
public:
typedef Account t;
static int getNbAccounts( void );
static int getTotalAmount( void );
static int getNbDeposits( void );
static int getNbWithdrawals( void );
static void displayAccountsInfos( void );
Account( int initial_deposit );
~Account( void );
void makeDeposit( int deposit );
bool makeWithdrawal( int withdrawal );
int checkAmount( void ) const;
void displayStatus( void ) const;
private:
static int _nbAccounts;
static int _totalAmount;
static int _totalNbDeposits;
static int _totalNbWithdrawals;
static void _displayTimestamp( void );
int _accountIndex;
int _amount;
int _nbDeposits;
int _nbWithdrawals;
Account( void );
};
// ************************************************************************** //
// vim: set ts=4 sw=4 tw=80 noexpandtab: //
// -*- indent-tabs-mode:t; -*-
// -*- mode: c++-mode; -*-
// -*- fill-column: 75; comment-column: 75; -*-
// ************************************************************************** //
#endif /* __ACCOUNT_H__ */

BIN
cpp00/ex02/Account.o Normal file

Binary file not shown.

50
cpp00/ex02/Makefile Normal file
View File

@ -0,0 +1,50 @@
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = bank
SRC = Account.cpp \
tests.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation Account Bank... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./bank"$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

BIN
cpp00/ex02/bank Executable file

Binary file not shown.

72
cpp00/ex02/tests.cpp Normal file
View File

@ -0,0 +1,72 @@
// ************************************************************************** //
// //
// tests.cpp for GlobalBanksters United //
// Created on : Thu Nov 20 23:45:02 1989 //
// Last update : Wed Jan 04 09:23:52 1992 //
// Made by : Brad "Buddy" McLane <bm@gbu.com> //
// //
// ************************************************************************** //
#include <vector>
#include <algorithm>
#include <functional>
#include "Account.hpp"
int main( void ) {
typedef std::vector<Account::t> accounts_t;
typedef std::vector<int> ints_t;
typedef std::pair<accounts_t::iterator, ints_t::iterator> acc_int_t;
int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 };
size_t const amounts_size( sizeof(amounts) / sizeof(int) );
accounts_t accounts( amounts, amounts + amounts_size );
accounts_t::iterator acc_begin = accounts.begin();
accounts_t::iterator acc_end = accounts.end();
int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 };
size_t const d_size( sizeof(d) / sizeof(int) );
ints_t deposits( d, d + d_size );
ints_t::iterator dep_begin = deposits.begin();
ints_t::iterator dep_end = deposits.end();
int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 };
size_t const w_size( sizeof(w) / sizeof(int) );
ints_t withdrawals( w, w + w_size );
ints_t::iterator wit_begin = withdrawals.begin();
ints_t::iterator wit_end = withdrawals.end();
Account::displayAccountsInfos();
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
for ( acc_int_t it( acc_begin, dep_begin );
it.first != acc_end && it.second != dep_end;
++(it.first), ++(it.second) ) {
(*(it.first)).makeDeposit( *(it.second) );
}
Account::displayAccountsInfos();
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
for ( acc_int_t it( acc_begin, wit_begin );
it.first != acc_end && it.second != wit_end;
++(it.first), ++(it.second) ) {
(*(it.first)).makeWithdrawal( *(it.second) );
}
Account::displayAccountsInfos();
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
return 0;
}
// ************************************************************************** //
// vim: set ts=4 sw=4 tw=80 noexpandtab: //
// -*- indent-tabs-mode:t; -*-
// -*- mode: c++-mode; -*-
// -*- fill-column: 75; comment-column: 75; -*-
// ************************************************************************** //

BIN
cpp00/ex02/tests.o Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex00/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex00",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex00/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp01/ex00/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

64
cpp01/ex00/Makefile Normal file
View File

@ -0,0 +1,64 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/24 13:59:56 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = zombie
SRC = newZombie.cpp \
main.cpp \
randomChump.cpp \
Zombie.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation zombie... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./zombie" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

37
cpp01/ex00/Zombie.cpp Normal file
View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:31:01 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 14:06:52 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie::Zombie(void)
{
std::cout << "\033[32m";
std::cout << "Constructor called" << std::endl;
std::cout << "\033[0m";
}
Zombie::~Zombie(void)
{
std::cout << "\033[31m";
std::cout << "Destructor called" << std::endl;
std::cout << "\033[0m";
}
void Zombie::announce(void)
{
std::cout << this->name << ": BraiiiiiiinnnZ..." << std::endl;
}
void Zombie::setname(std::string name)
{
this->name = name;
}

33
cpp01/ex00/Zombie.hpp Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:23:44 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 13:30:20 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
#include <iostream>
class Zombie
{
public:
Zombie(void);
~Zombie(void);
void announce(void);
void setname(std::string name);
private:
std::string name;
};
Zombie* newZombie(std::string name);
void randomChump(std::string name);
#endif

BIN
cpp01/ex00/Zombie.o Normal file

Binary file not shown.

26
cpp01/ex00/main.cpp Normal file
View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:52:26 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 14:04:53 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main()
{
Zombie *heapZombie = newZombie("HeapZombie");
heapZombie->announce();
delete heapZombie;
std::cout << "\033[31m";
std::cout << "HeapZombie Deleted!!" << std::endl << std::endl;
std::cout << "\033[0m";
randomChump("StackZombie");
return (0);
}

BIN
cpp01/ex00/main.o Normal file

Binary file not shown.

20
cpp01/ex00/newZombie.cpp Normal file
View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* newZombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:38:34 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 13:46:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* newZombie(std::string name)
{
Zombie *z = new Zombie();
z->setname(name);
return (z);
}

BIN
cpp01/ex00/newZombie.o Normal file

Binary file not shown.

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* randomChump.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:23:25 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 13:50:16 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
void randomChump(std::string name)
{
Zombie z;
z.setname(name);
z.announce();
}

BIN
cpp01/ex00/randomChump.o Normal file

Binary file not shown.

BIN
cpp01/ex00/zombie Executable file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex01/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex01",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex01/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

105
cpp01/ex01/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,105 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

63
cpp01/ex01/Makefile Normal file
View File

@ -0,0 +1,63 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/24 15:34:53 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = horde
SRC = zombieHorde.cpp \
main.cpp \
Zombie.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation horde... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./horde" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

39
cpp01/ex01/Zombie.cpp Normal file
View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:31:01 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 15:30:35 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int Zombie::count = 0;
Zombie::Zombie(void) : id(++count)
{
std::cout << "\033[32m";
std::cout << "Constructor called for zombie [" << id << "]" << std::endl;
std::cout << "\033[0m";
}
Zombie::~Zombie(void)
{
std::cout << "\033[31m";
std::cout << "Destructor called for zombie [" << id << "]" << std::endl;
std::cout << "\033[0m";
}
void Zombie::announce(void)
{
std::cout << this->name << ": BraiiiiiiinnnZ..." << std::endl;
}
void Zombie::setname(std::string name)
{
this->name = name;
}

35
cpp01/ex01/Zombie.hpp Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Zombie.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 13:23:44 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 15:24:50 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ZOMBIE_HPP
# define ZOMBIE_HPP
#include <iostream>
#include <string>
class Zombie
{
public:
Zombie(void);
~Zombie(void);
void announce(void);
void setname(std::string name);
private:
std::string name;
int id;
static int count;
};
Zombie* zombieHorde(int N, std::string name);
#endif

BIN
cpp01/ex01/Zombie.o Normal file

Binary file not shown.

BIN
cpp01/ex01/horde Executable file

Binary file not shown.

36
cpp01/ex01/main.cpp Normal file
View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 15:17:37 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 15:32:08 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
int main()
{
int N;
std::cout << "\033[32m";
std::cout << "Entrez le nombre de zombies à créer: ";
std::cout << "\033[0m";
std::cin >> N;
if(std::cin.fail() || N < 1)
{
std::cerr << "\033[31m";
std::cerr << "Entrée invalide. Veuillez entrer un nombre entier positif!!" << std::endl;
std::cerr << "\033[0m";
return (1);
}
Zombie* horde = zombieHorde(N, "Zombie");
for (int i = 0; i < N; i++)
{
horde[i].announce();
}
delete[] horde;
return (0);
}

BIN
cpp01/ex01/main.o Normal file

Binary file not shown.

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* zombieHorde.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 15:05:45 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 15:17:10 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Zombie.hpp"
Zombie* zombieHorde(int N, std::string name)
{
Zombie *horde = new Zombie[N];
for(int i = 0; i < N; i++)
horde[i].setname(name);
return (horde);
}

BIN
cpp01/ex01/zombieHorde.o Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex02/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex02",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex02/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp01/ex02/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

61
cpp01/ex02/Makefile Normal file
View File

@ -0,0 +1,61 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/24 15:52:26 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = brain
SRC = main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation brain... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./brain" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

BIN
cpp01/ex02/brain Executable file

Binary file not shown.

31
cpp01/ex02/main.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 15:41:21 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 15:50:11 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <string>
#include <iostream>
int main()
{
std::string str = "HI THIS IS BRAIN";
std::string *stringPTR = &str;
std::string &stringREF = str;
std::cout << "Adresse de str : " << &str << std::endl;
std::cout << "Adresse contenue dans stringPTR : " << stringPTR << std::endl;
std::cout << "Adresse contenue dans stringREF : " << &stringREF << std::endl << std::endl;
std::cout << "Valeur de str : " << str << std::endl;
std::cout << "Valeur pointée par stringPTR : " << *stringPTR << std::endl;
std::cout << "Valeur pointée par stringREF : " << stringREF << std::endl;
return (0);
}

BIN
cpp01/ex02/main.o Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex03/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex03",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex03/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp01/ex03/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

23
cpp01/ex03/HumanA.cpp Normal file
View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 17:25:06 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 17:47:18 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon) {}
void HumanA::attack(void)
{
const std::string type = this->_weapon.getType();
std::cout << this->_name << " attack with their " << type << std::endl;
}
HumanA::~HumanA(void) {}

30
cpp01/ex03/HumanA.hpp Normal file
View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanA.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 16:13:39 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 18:01:21 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANA_HPP
# define HUMANA_HPP
#include "Weapon.hpp"
class HumanA
{
public:
HumanA(std::string name, Weapon &weapon);
~HumanA(void);
void attack(void);
private:
std::string _name;
Weapon &_weapon;
};
#endif

BIN
cpp01/ex03/HumanA.o Normal file

Binary file not shown.

28
cpp01/ex03/HumanB.cpp Normal file
View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 17:48:26 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 17:54:54 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanB.hpp"
HumanB::HumanB(std::string name) : _name(name) {}
void HumanB::attack(void)
{
const std::string type = this->_weapon->getType();
std::cout << this->_name << " attacks with their " << type << std::endl;
}
void HumanB::setWeapon(Weapon &weapon)
{
this->_weapon = &weapon;
}
HumanB::~HumanB(void) {}

31
cpp01/ex03/HumanB.hpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* HumanB.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 16:18:38 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 17:58:53 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HUMANB_HPP
# define HUMANB_HPP
#include "Weapon.hpp"
class HumanB
{
public:
HumanB(std::string name);
~HumanB(void);
void attack(void);
void setWeapon(Weapon &weapon);
private:
std::string _name;
Weapon *_weapon;
};
#endif

BIN
cpp01/ex03/HumanB.o Normal file

Binary file not shown.

64
cpp01/ex03/Makefile Normal file
View File

@ -0,0 +1,64 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/24 18:04:10 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = weapon
SRC = Weapon.cpp \
HumanB.cpp \
HumanA.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation weapon... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./weapon" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

31
cpp01/ex03/Weapon.cpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 17:16:10 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 17:24:34 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
const std::string &Weapon::getType(void)
{
const std::string &type = this->_type;
return (type);
}
void Weapon::setType(std::string type)
{
this->_type = type;
}
Weapon::Weapon(std::string type)
{
this->_type = type;
}
Weapon::~Weapon(void) {}

31
cpp01/ex03/Weapon.hpp Normal file
View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Weapon.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 16:02:52 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 18:03:55 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef WEAPON_HPP
# define WEAPON_HPP
#include <iostream>
#include <string>
class Weapon
{
public:
Weapon(std::string type);
~Weapon(void);
const std::string &getType(void);
void setType(std::string type);
private:
std::string _type;
};
#endif

BIN
cpp01/ex03/Weapon.o Normal file

Binary file not shown.

35
cpp01/ex03/main.cpp Normal file
View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/24 15:58:41 by fgras-ca #+# #+# */
/* Updated: 2023/12/24 18:05:04 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Weapon.hpp"
#include "HumanA.hpp"
#include "HumanB.hpp"
int main()
{
{
Weapon club = Weapon("crude spiked club");
HumanA bob("Bob", club);
bob.attack();
club.setType("some other type of club");
bob.attack();
}
{
Weapon club = Weapon("crude spiked club");
HumanB jim("Jim");
jim.setWeapon(club);
jim.attack();
club.setType("some other type of club");
jim.attack();
}
return (0);
}

BIN
cpp01/ex03/main.o Normal file

Binary file not shown.

BIN
cpp01/ex03/weapon Executable file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex04/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex04",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex04/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

107
cpp01/ex04/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,107 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"files.associations": {
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}

61
cpp01/ex04/Makefile Normal file
View File

@ -0,0 +1,61 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/27 14:52:31 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = replace
SRC = main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation replace... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./replace" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

65
cpp01/ex04/main.cpp Normal file
View File

@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/27 14:20:39 by fgras-ca #+# #+# */
/* Updated: 2023/12/27 14:55:50 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <iostream>
#include <fstream>
#include <sstream>
int main(int argc, char **argv)
{
if (argc != 4)
{
std::cerr << "\033[32m";
std::cerr << "Usage: " << argv[0] << " <filename> <s1> <s2>" << std::endl;
std::cerr << "\033[0m";
return (1);
}
std::string filename = argv[1];
std::string s1 = argv[2];
std::string s2 = argv[3];
std::ifstream inputFile(filename);
if (!inputFile.is_open())
{
std::cerr << "\031[33m";
std::cerr << "Impossible d'ouvrir le fichier " << filename << std::endl;
std::cerr << "\033[0m";
return (1);
}
std::stringstream buffer;
buffer << inputFile.rdbuf();
std::string content = buffer.str();
inputFile.close();
size_t pos = 0;
while ((pos = content.find(s1, pos)) != std::string::npos)
{
content.replace(pos, s1.length(), s2);
pos += s2.length();
}
std::ofstream outputFile(filename + ".replace");
if (!outputFile.is_open())
{
std::cerr << "\033[33m";
std::cerr << "Impossible de céer le fichier " << filename + ".replace" << std::endl;
std::cerr << "\033[30m";
return (1);
}
outputFile << content;
outputFile.close();
return (0);
}

BIN
cpp01/ex04/main.o Normal file

Binary file not shown.

BIN
cpp01/ex04/replace Executable file

Binary file not shown.

4
cpp01/ex04/test Normal file
View File

@ -0,0 +1,4 @@
Bonjour les amis.
Les bons comptes font les bon amis
Les meilleurs amis sont ceux qui excitent à bien faire.
Avoir des amis, c'est être riche.

4
cpp01/ex04/test.replace Normal file
View File

@ -0,0 +1,4 @@
Bonjour les poulets.
Les bons comptes font les bon poulets
Les meilleurs poulets sont ceux qui excitent à bien faire.
Avoir des poulets, c'est être riche.

View File

@ -0,0 +1,4 @@
Bonjour les poulets.
Les bons comptes font les bon poulets
Les meilleurs poulets sont ceux qui excitent à bien faire.
Avoir des poulets, c'est être riche.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex05/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex05",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex05/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

59
cpp01/ex05/.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}

52
cpp01/ex05/Harl.cpp Normal file
View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/27 15:12:29 by fgras-ca #+# #+# */
/* Updated: 2023/12/27 16:41:15 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
Harl::Harl() {}
void Harl::debug(void)
{
std::cout << "[DEBUG]\nI love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger.\nI really do!" << std::endl;
}
void Harl::info(void)
{
std::cout << "[INFO]\nI cannot believe adding extra bacon costs more money. You didnt put enough bacon in my burger!\nIf you did, I wouldnt be asking for more!" << std::endl;
}
void Harl::warning(void)
{
std::cout << "[WARNING]\nI think I deserve to have some extra bacon for free.\nIve been coming for years whereas you started working here since last month." << std::endl;
}
void Harl::error(void)
{
std::cout << "[ERROR]\nThis is unacceptable! I want to speak to the manager now." << std::endl;
}
void Harl::complain(std::string level)
{
void (Harl::*complaints[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
std::string levels[] = {"DEBUG", "INFO", "WARNING", "ERROR"};
for (int i = 0; i < 4; i++)
{
if (level == levels[i])
{
(this->*complaints[i])();
break;
}
}
}
Harl::~Harl() {}

33
cpp01/ex05/Harl.hpp Normal file
View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Harl.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/27 15:08:34 by fgras-ca #+# #+# */
/* Updated: 2023/12/27 15:11:58 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef HARL_HPP
# define HARL_HPP
#include <string>
#include <iostream>
class Harl
{
public:
Harl();
~Harl();
void complain(std::string level);
private:
void debug(void);
void info(void);
void warning(void);
void error(void);
};
#endif

BIN
cpp01/ex05/Harl.o Normal file

Binary file not shown.

62
cpp01/ex05/Makefile Normal file
View File

@ -0,0 +1,62 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/12/24 13:55:45 by fgras-ca #+# #+# #
# Updated: 2023/12/27 15:39:55 by fgras-ca ### ########.fr #
# #
# **************************************************************************** #
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
echo "( ( ( ( ( ( ( ("
DEF_COLOR = \033[0m
GRAY = \033[0;90m
RED = \033[0;91m
GREEN = \033[0;92m
YELLOW = \033[0;93m
BLUE = \033[0;94m
MAGENTA = \033[0;95m
CYAN = \033[0;96m
WHITE = \033[0;97m
ORANGE = \033[38;5;214m
NAME = harl
SRC = Harl.cpp \
main.cpp \
OBJS = ${SRC:.cpp=.o}
CC = c++
CFLAGS = -Wall -Werror -Wextra -std=c++98
RM = rm -f
all : $(NAME)
$(NAME) : $(OBJS)
@echo "$(RED)Compilation harl... $(DEF_COLOR)"
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./harl" to execute the program!!$(DEF_COLOR)"
$(LOGO)
clean :
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
$(RM) $(OBJS)
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
$(LOGO)
fclean : clean
@echo "$(RED)Delete program name... $(DEF_COLOR)"
$(RM) $(NAME)
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
$(LOGO)
re : fclean all
.PHONY : all clean fclean re

BIN
cpp01/ex05/harl Executable file

Binary file not shown.

32
cpp01/ex05/main.cpp Normal file
View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/27 15:34:03 by fgras-ca #+# #+# */
/* Updated: 2023/12/27 15:38:28 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "Harl.hpp"
int main()
{
Harl harl;
std::cout << "Calling with DEBUG:" << std::endl;
harl.complain("DEBUG");
std::cout << "\nCalling with INFO:" << std::endl;
harl.complain("INFO");
std::cout << "\nCalling with WARNING:" << std::endl;
harl.complain("WARNING");
std::cout << "\nCalling with ERROR:" << std::endl;
harl.complain("ERROR");
return (0);
}

BIN
cpp01/ex05/main.o Normal file

Binary file not shown.

View File

@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "linux-gcc-x64",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [
""
]
}
],
"version": 4
}

24
cpp01/ex06/.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex06",
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp01/ex06/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

Some files were not shown because too many files have changed in this diff Show More