This commit is contained in:
kinou-p 2022-07-22 09:47:20 +02:00
parent 3270f3c4c9
commit 1634211177
33 changed files with 204 additions and 132 deletions

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/04/15 01:47:51 by apommier #+# #+# # # Created: 2022/04/15 01:47:51 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -15,7 +15,7 @@ SRCS = megaphone.cpp
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 10:37:12 by apommier #+# #+# */ /* Created: 2022/04/15 10:37:12 by apommier #+# #+# */
/* Updated: 2022/04/21 18:32:43 by apommier ### ########.fr */ /* Updated: 2022/07/21 09:55:59 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -32,7 +32,7 @@ std::string Contact::GetInfo(int index)
{ {
std::string str; std::string str;
str = this->GetRealInfo(index); str = this->getOneInfo(index);
if (str.size() > 10) if (str.size() > 10)
{ {
str.resize(10); str.resize(10);
@ -41,7 +41,7 @@ std::string Contact::GetInfo(int index)
return (str); return (str);
} }
std::string Contact::GetRealInfo(int index) std::string Contact::getOneInfo(int index)
{ {
if (index == 0) if (index == 0)
return (this->_first_name); return (this->_first_name);

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 10:37:15 by apommier #+# #+# */ /* Created: 2022/04/15 10:37:15 by apommier #+# #+# */
/* Updated: 2022/04/21 18:00:26 by apommier ### ########.fr */ /* Updated: 2022/07/21 09:55:59 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,7 @@ class Contact {
~Contact(void); ~Contact(void);
void FillContact(std::string *info); void FillContact(std::string *info);
std::string GetInfo(int index); std::string GetInfo(int index);
std::string GetRealInfo(int index); std::string getOneInfo(int index);
private: private:

View File

@ -6,18 +6,18 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/04/15 01:47:51 by apommier #+# #+# # # Created: 2022/04/15 01:47:51 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:49:19 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME = a.out NAME = phoneBook
SRCS = main.cpp\ SRCS = main.cpp\
Contact.cpp\ Contact.cpp\
PhoneBook.cpp PhoneBook.cpp
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror -g CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 10:37:20 by apommier #+# #+# */ /* Created: 2022/04/15 10:37:20 by apommier #+# #+# */
/* Updated: 2022/04/21 18:32:32 by apommier ### ########.fr */ /* Updated: 2022/07/21 20:05:15 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,21 +14,20 @@
PhoneBook::PhoneBook(void) PhoneBook::PhoneBook(void)
{ {
int index = 0; this->_NbrContact = -1;
while (this->_NbrContact < 8)
this->_Contact[this->_NbrContact++] = 0;
this->_NbrContact = 0; this->_NbrContact = 0;
while (index < 8)
_Contact[index++] = 0;
return ;
} }
PhoneBook::~PhoneBook(void) PhoneBook::~PhoneBook(void)
{ {
return ;
} }
void PhoneBook::StoreContact(Contact *NewContact) void PhoneBook::StoreContact(Contact *NewContact)
{ {
if (_Contact[this->_NbrContact])
delete _Contact[this->_NbrContact] ;
_Contact[this->_NbrContact] = NewContact; _Contact[this->_NbrContact] = NewContact;
if (this->_NbrContact == 8) if (this->_NbrContact == 8)
this->_NbrContact = 0; this->_NbrContact = 0;
@ -43,11 +42,11 @@ void PhoneBook::PrintContact(int index)
std::cout << "There is no contact at this index" << std::endl; std::cout << "There is no contact at this index" << std::endl;
return ; return ;
} }
std::cout << std::setw(10) << "First name: " << this->_Contact[index]->GetRealInfo(0) << std::endl; std::cout << std::setw(10) << "First name: " << this->_Contact[index]->getOneInfo(0) << std::endl;
std::cout << std::setw(10) << "Last name: " << this->_Contact[index]->GetRealInfo(1) << std::endl; std::cout << std::setw(10) << "Last name: " << this->_Contact[index]->getOneInfo(1) << std::endl;
std::cout << std::setw(10) << "Nickname: " << this->_Contact[index]->GetRealInfo(2) << std::endl; std::cout << std::setw(10) << "Nickname: " << this->_Contact[index]->getOneInfo(2) << std::endl;
std::cout << std::setw(10) << "Phone number: " << this->_Contact[index]->GetRealInfo(3) << std::endl; std::cout << std::setw(10) << "Phone number: " << this->_Contact[index]->getOneInfo(3) << std::endl;
std::cout << std::setw(10) << "Darkest secret: " << this->_Contact[index]->GetRealInfo(4) << std::endl; std::cout << std::setw(10) << "Darkest secret: " << this->_Contact[index]->getOneInfo(4) << std::endl;
} }
void PhoneBook::PrintIndex() void PhoneBook::PrintIndex()
@ -66,7 +65,7 @@ void PhoneBook::PrintIndex()
} }
if (!index) if (!index)
std::cout << "There is no contact\n"; std::cout << "There is no contact\n";
else if (index)
{ {
while (1) while (1)
{ {
@ -76,16 +75,22 @@ void PhoneBook::PrintIndex()
std::cout << "Bad entry" << std::endl; std::cout << "Bad entry" << std::endl;
else else
{ {
index = nbr[0] - 48; index = nbr[0] - '0';
if (!index || index > 8) if (!index || index > 8)
std::cout << "Bad entry" << std::endl; std::cout << "Bad entry" << std::endl;
else else
{ {
std::cout << index << "index \n";
this->PrintContact(index - 1); this->PrintContact(index - 1);
break; return ;
} }
} }
} }
} }
} }
void PhoneBook::deleteContact()
{
for (int i = 0; this->_Contact[i] && i < 8; i++)
delete this->_Contact[i];
}

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/15 10:37:24 by apommier #+# #+# */ /* Created: 2022/04/15 10:37:24 by apommier #+# #+# */
/* Updated: 2022/04/21 17:57:29 by apommier ### ########.fr */ /* Updated: 2022/07/21 19:58:59 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,7 +24,9 @@ class PhoneBook {
void StoreContact(Contact *NewContact); void StoreContact(Contact *NewContact);
void PrintContact(int index); void PrintContact(int index);
void PrintIndex(); void PrintIndex();
private: void deleteContact();
private:
int _NbrContact; int _NbrContact;
class Contact *_Contact[8]; class Contact *_Contact[8];

View File

@ -6,14 +6,15 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/17 15:55:40 by apommier #+# #+# */ /* Created: 2022/04/17 15:55:40 by apommier #+# #+# */
/* Updated: 2022/07/20 12:19:30 by apommier ### ########.fr */ /* Updated: 2022/07/21 20:01:53 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Contact.hpp" #include "Contact.hpp"
#include "PhoneBook.hpp" #include "PhoneBook.hpp"
#include <string>
void PrintMessage(int index) void PrintMessage(int index)
{ {
if (index == 0) if (index == 0)
std::cout << "Enter your fisrt name: "; std::cout << "Enter your fisrt name: ";
@ -27,23 +28,21 @@ void PrintMessage(int index)
std::cout << "Enter your darkest secret: "; std::cout << "Enter your darkest secret: ";
} }
void search_contact(PhoneBook *Book, Contact *Contact) void add_contact(PhoneBook *Book )
{
}
void add_contact(PhoneBook *Book, Contact *Contact)
{ {
int index = 0; int index = 0;
std::string line; std::string line;
std::string info[5]; std::string info[5];
Contact *Contact = new class Contact;
while (index < 5) while (index < 5)
{ {
PrintMessage(index); PrintMessage(index);
std::getline(std::cin, line); std::getline(std::cin, line);
info[index] = line; info[index] = line;
if (!line.empty()) if (index == 3 && line.find_first_not_of("0123456789") != std::string::npos)
index = 3;
else if (!line.empty() && line.find_last_not_of(" ") != std::string::npos )
index++; index++;
} }
Contact->FillContact(info); Contact->FillContact(info);
@ -55,23 +54,28 @@ int main(int ac, char **av)
PhoneBook book; PhoneBook book;
Contact contact; Contact contact;
std::string line; std::string line;
int NbrContact = 0;
(void)av;
if (ac != 1) if (ac != 1)
{ {
std::cout << "too much arguments\n"; std::cout << "Too much arguments\n";
return (0); return (0);
} }
std::cout << "Enter a command : ADD | SEARCH | EXIT" << std::endl; std::cout << "Enter a command : ADD | SEARCH | EXIT" << std::endl;
while (line != "EXIT") while (line != "EXIT")
{ {
std::getline(std::cin, line); std::getline(std::cin, line);
if (line != "SEARCH")
std::cout << "Enter a command : ADD | SEARCH | EXIT1" << std::endl;
if (line == "ADD") if (line == "ADD")
add_contact(&book, &contact); add_contact(&book);
else if (line == "SEARCH") else if (line == "SEARCH")
book.PrintIndex(); book.PrintIndex();
else else if (line != "EXIT" && !line.empty())
std::cout << "Invalid command" << std::endl; std::cout << "Invalid command" << std::endl;
if (line != "SEARCH" && line.size())
std::cout << "Enter a command : ADD | SEARCH | EXIT2" << std::endl;
} }
book.deleteContact();
return (0); return (0);
} }

View File

@ -11,91 +11,121 @@
/* ************************************************************************** */ /* ************************************************************************** */
#include "Account.hpp" #include "Account.hpp"
#include <time.h>
#include <iostream>
#include <string>
int Account::_nbAccounts = 0;
int Account::_totalAmount = 0;
int Account::_totalNbDeposits = 0;
int Account::_totalNbWithdrawals = 0;
int Account::getNbAccounts( void ) int Account::getNbAccounts( void )
{ {
return (this->_nbAccounts); return (Account::_nbAccounts);
} }
int Account::getTotalAmount( void ) int Account::getTotalAmount( void )
{ {
return (this->_totalAmount); return (Account::_totalAmount);
} }
int Account::getNbDeposits( void ) int Account::getNbDeposits( void )
{ {
return (this->_nbDeposits); return (Account::_totalNbDeposits);
} }
int Account::getNbWithdrawals( void ) int Account::getNbWithdrawals( void )
{ {
return (this->_nbWithdrawals); return (Account::_totalNbWithdrawals);
} }
void Account::displayAccountsInfos( void ) void Account::displayAccountsInfos( void )
{ {
Account::_displayTimestamp();
std::cout << " accounts:" << getNbAccounts();
std::cout << ";total:" << getTotalAmount();
std::cout << ";deposits:" << getNbDeposits();
std::cout << ";withdrawals:" << getNbWithdrawals() << std::endl;
} }
Account::Account( int initial_deposit ) Account::Account( int initial_deposit )
{ {
this->_nbAccounts = 0; this->_accountIndex = Account::_nbAccounts++;
this->_totalAmount = initial_deposit; this->_totalAmount += initial_deposit;
this->_totalNbDeposits = 0;
this->_totalNbWithdrawals = 0;
this->_accountIndex = 0;
this->_amount = initial_deposit; this->_amount = initial_deposit;
this->_nbDeposits = 0; this->_nbDeposits = 0;
this->_nbWithdrawals = 0; this->_nbWithdrawals = 0;
} Account::_displayTimestamp();
std::cout << " index:" << this->_accountIndex << ";amount:" << checkAmount() << ";created" << std::endl;
Account::Account()
{
this->_nbAccounts = 0;
this->_totalAmount = 0;
this->_totalNbDeposits = 0;
this->_totalNbWithdrawals = 0;
this->_accountIndex = 0;
this->_amount = 0;
this->_nbDeposits = 0;
this->_nbWithdrawals = 0;
} }
Account::~Account( void ) Account::~Account( void )
{ {
Account::_displayTimestamp();
std::cout << " index:" << this->_accountIndex << ";amount:" << checkAmount() << ";closed" << std::endl;
} }
void Account::makeDeposit( int deposit ) void Account::makeDeposit( int deposit )
{ {
this->_amount += deposit;
this->_nbDeposits = 1; this->_nbDeposits = 1;
this->_totalNbDeposits++; this->_totalNbDeposits++;
Account::_displayTimestamp();
std::cout << " index:" << this->_accountIndex;
std::cout << ";p_amount:" << this->checkAmount();
this->_amount += deposit;
this->_totalAmount += deposit;
std::cout << ";deposit:" << deposit;
std::cout << ";amount:" << this->checkAmount();
std::cout << ";nb_deposits:"<< this->_nbDeposits<< std::endl;
} }
bool Account::makeWithdrawal( int withdrawal ) bool Account::makeWithdrawal( int withdrawal )
{ {
if (this->_totalAmount >= withdrawal) Account::_displayTimestamp();
std::cout << " index:" << this->_accountIndex;
std::cout << ";p_amount:" << this->checkAmount();
std::cout << ";withdrawal:";
if (this->_amount >= withdrawal)
{ {
this->_nbWithdrawals = 1; this->_nbWithdrawals = 1;
this->_totalNbWithdrawals++; this->_totalNbWithdrawals++;
this->_amount -= withdrawal; this->_amount -= withdrawal;
this->_totalAmount -= withdrawal;
std::cout << withdrawal;
std::cout << ";amount:" << this->checkAmount();
std::cout << ";nb_withdrawals:"<< this->_nbWithdrawals << std::endl;
return (1); return (1);
} }
std::cout << "refused\n";
return (0); return (0);
} }
int Account::checkAmount( void ) const int Account::checkAmount( void ) const
{ {
return (this->_amount);
} }
void Account::displayStatus( void ) const void Account::displayStatus( void ) const
{ {
Account::_displayTimestamp();
std::cout << " index:" << this->_accountIndex;
std::cout << ";amount:" << checkAmount();
std::cout << ";deposits:" << this->_nbDeposits;
std::cout << ";withdrawals:" << this->_nbWithdrawals << std::endl;
} }
void Account::_displayTimestamp( void ) void Account::_displayTimestamp( void )
{ {
time_t rawtime;
} struct tm *timeinfo;
char buffer[18];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime (buffer, 20, "[%G%m%d_%H%M%S]", timeinfo);
//const char *buffeer = "[19920104_091532]";
//std::cout << buffeer;
std::cout << buffer;
}

View File

@ -6,17 +6,17 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/04/15 01:47:51 by apommier #+# #+# # # Created: 2022/04/15 01:47:51 by apommier #+# #+# #
# Updated: 2022/07/20 12:51:45 by apommier ### ########.fr # # Updated: 2022/07/22 07:49:56 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
NAME = a.out NAME = account
SRCS = Account.cpp\ SRCS = Account.cpp\
tests.cpp tests.cpp
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/08 16:30:13 by apommier #+# #+# # # Created: 2022/06/08 16:30:13 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -18,7 +18,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/08 16:30:13 by apommier #+# #+# # # Created: 2022/06/08 16:30:13 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/10 14:10:33 by apommier #+# #+# # # Created: 2022/06/10 14:10:33 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -14,7 +14,7 @@ NAME = a.out
SRCS = main.cpp SRCS = main.cpp
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/16 21:39:06 by apommier #+# #+# # # Created: 2022/06/16 21:39:06 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
Weapon.cpp Weapon.cpp
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/19 16:15:23 by apommier #+# #+# # # Created: 2022/06/19 16:15:23 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -15,7 +15,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 22:07:00 by apommier #+# #+# */ /* Created: 2022/06/21 22:07:00 by apommier #+# #+# */
/* Updated: 2022/07/19 10:42:46 by apommier ### ########.fr */ /* Updated: 2022/07/22 09:39:35 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/21 22:05:40 by apommier #+# #+# # # Created: 2022/06/21 22:05:40 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 22:06:54 by apommier #+# #+# */ /* Created: 2022/06/21 22:06:54 by apommier #+# #+# */
/* Updated: 2022/06/21 23:43:26 by apommier ### ########.fr */ /* Updated: 2022/07/22 09:26:27 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 23:39:20 by apommier #+# #+# */ /* Created: 2022/06/21 23:39:20 by apommier #+# #+# */
/* Updated: 2022/06/21 23:44:25 by apommier ### ########.fr */ /* Updated: 2022/07/22 09:40:02 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -34,6 +34,19 @@ void Harl::complain(std::string level)
} }
} }
int Harl::ChooseComplain(std::string level)
{
void (Harl::*complaint[])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
for (int i = 0; i < 4 ; i++)
{
void (Harl::*selectedComplaint)( void ) = complaint[i];
if (level == levelTab[i])
return (i);
}
}
void Harl::debug() void Harl::debug()
{ {
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!\n"; std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!\n";

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 23:39:11 by apommier #+# #+# */ /* Created: 2022/06/21 23:39:11 by apommier #+# #+# */
/* Updated: 2022/06/21 23:44:12 by apommier ### ########.fr */ /* Updated: 2022/07/22 09:41:32 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -24,6 +24,7 @@ class Harl {
Harl(); Harl();
~Harl(); ~Harl();
int chooseComplain(std::string level);
void complain(std::string level); void complain(std::string level);
private: private:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/21 23:38:45 by apommier #+# #+# # # Created: 2022/06/21 23:38:45 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,31 +6,48 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */ /* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/21 23:40:41 by apommier #+# #+# */ /* Created: 2022/06/21 23:40:41 by apommier #+# #+# */
/* Updated: 2022/06/21 23:52:51 by apommier ### ########.fr */ /* Updated: 2022/07/22 09:44:33 by apommier ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Harl.hpp" #include "Harl.hpp"
void harFilter(Harl harl, std::string level)
{
int goodLevel = harl.chooseComplain(level) + 1;
std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
switch (goodLevel)
{
case 1 :
harl.complain("DEBUG");
harl.complain("INFO");
harl.complain("WARNING");
harl.complain("ERROR");
case 2 :
harl.complain("INFO");
harl.complain("WARNING");
harl.complain("ERROR");
case 3 :
harl.complain("WARNING");
harl.complain("ERROR");
case 4 :
harl.complain("ERROR");
default :
std::cout << "[ Probably complaining about insignificant problems ]\n";
}
}
int main(int ac, char **av) int main(int ac, char **av)
{ {
Harl harl; Harl harl;
bool freeHarl = 0;
std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
std::cout << ac << std::endl;
if (ac != 2) if (ac != 2)
return (0);
for (int j = 0; j < 4; j++)
{ {
if (av[1] == levelTab[j]) std::cerr << "Bad entry\n";
freeHarl = 1; return (1);
if (freeHarl == 1)
{
while (j < 4)
{
harl.complain(levelTab[j]);
j++;
}
}
} }
harFilter(harl, av[1]);
return (0);
} }

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/22 00:57:33 by apommier #+# #+# # # Created: 2022/06/22 00:57:33 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/22 15:30:34 by apommier #+# #+# # # Created: 2022/06/22 15:30:34 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/06/22 15:30:34 by apommier #+# #+# # # Created: 2022/06/22 15:30:34 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:44 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/13 05:22:57 by apommier #+# #+# # # Created: 2022/07/13 05:22:57 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/13 05:22:57 by apommier #+# #+# # # Created: 2022/07/13 05:22:57 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/13 05:22:57 by apommier #+# #+# # # Created: 2022/07/13 05:22:57 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -18,7 +18,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/14 02:04:13 by apommier #+# #+# # # Created: 2022/07/14 02:04:13 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -20,7 +20,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/14 02:04:13 by apommier #+# #+# # # Created: 2022/07/14 02:04:13 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -21,7 +21,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/14 02:04:13 by apommier #+# #+# # # Created: 2022/07/14 02:04:13 by apommier #+# #+# #
# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -21,7 +21,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/18 21:34:54 by apommier #+# #+# # # Created: 2022/07/18 21:34:54 by apommier #+# #+# #
# Updated: 2022/07/19 10:52:12 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/18 21:34:54 by apommier #+# #+# # # Created: 2022/07/18 21:34:54 by apommier #+# #+# #
# Updated: 2022/07/19 12:02:15 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o:

View File

@ -6,7 +6,7 @@
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ # # By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/07/18 21:34:54 by apommier #+# #+# # # Created: 2022/07/18 21:34:54 by apommier #+# #+# #
# Updated: 2022/07/19 12:02:15 by apommier ### ########.fr # # Updated: 2022/07/22 07:48:18 by apommier ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -17,7 +17,7 @@ SRCS = main.cpp\
OBJS = ${SRCS:.cpp=.o} OBJS = ${SRCS:.cpp=.o}
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror CFLAGS = -Wall -Wextra -Werror -std=c++98
RM = rm -rf RM = rm -rf
.cpp.o: .cpp.o: