first
This commit is contained in:
parent
3270f3c4c9
commit
1634211177
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
str = this->GetRealInfo(index);
|
||||
str = this->getOneInfo(index);
|
||||
if (str.size() > 10)
|
||||
{
|
||||
str.resize(10);
|
||||
@ -41,7 +41,7 @@ std::string Contact::GetInfo(int index)
|
||||
return (str);
|
||||
}
|
||||
|
||||
std::string Contact::GetRealInfo(int index)
|
||||
std::string Contact::getOneInfo(int index)
|
||||
{
|
||||
if (index == 0)
|
||||
return (this->_first_name);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
void FillContact(std::string *info);
|
||||
std::string GetInfo(int index);
|
||||
std::string GetRealInfo(int index);
|
||||
std::string getOneInfo(int index);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@ -6,18 +6,18 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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\
|
||||
Contact.cpp\
|
||||
PhoneBook.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror -g
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
this->_NbrContact = -1;
|
||||
while (this->_NbrContact < 8)
|
||||
this->_Contact[this->_NbrContact++] = 0;
|
||||
this->_NbrContact = 0;
|
||||
while (index < 8)
|
||||
_Contact[index++] = 0;
|
||||
return ;
|
||||
}
|
||||
|
||||
PhoneBook::~PhoneBook(void)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
|
||||
void PhoneBook::StoreContact(Contact *NewContact)
|
||||
{
|
||||
if (_Contact[this->_NbrContact])
|
||||
delete _Contact[this->_NbrContact] ;
|
||||
_Contact[this->_NbrContact] = NewContact;
|
||||
if (this->_NbrContact == 8)
|
||||
this->_NbrContact = 0;
|
||||
@ -43,11 +42,11 @@ void PhoneBook::PrintContact(int index)
|
||||
std::cout << "There is no contact at this index" << std::endl;
|
||||
return ;
|
||||
}
|
||||
std::cout << std::setw(10) << "First name: " << this->_Contact[index]->GetRealInfo(0) << std::endl;
|
||||
std::cout << std::setw(10) << "Last name: " << this->_Contact[index]->GetRealInfo(1) << std::endl;
|
||||
std::cout << std::setw(10) << "Nickname: " << this->_Contact[index]->GetRealInfo(2) << std::endl;
|
||||
std::cout << std::setw(10) << "Phone number: " << this->_Contact[index]->GetRealInfo(3) << std::endl;
|
||||
std::cout << std::setw(10) << "Darkest secret: " << this->_Contact[index]->GetRealInfo(4) << 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]->getOneInfo(1) << 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]->getOneInfo(3) << std::endl;
|
||||
std::cout << std::setw(10) << "Darkest secret: " << this->_Contact[index]->getOneInfo(4) << std::endl;
|
||||
}
|
||||
|
||||
void PhoneBook::PrintIndex()
|
||||
@ -66,7 +65,7 @@ void PhoneBook::PrintIndex()
|
||||
}
|
||||
if (!index)
|
||||
std::cout << "There is no contact\n";
|
||||
else
|
||||
if (index)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
@ -76,16 +75,22 @@ void PhoneBook::PrintIndex()
|
||||
std::cout << "Bad entry" << std::endl;
|
||||
else
|
||||
{
|
||||
index = nbr[0] - 48;
|
||||
index = nbr[0] - '0';
|
||||
if (!index || index > 8)
|
||||
std::cout << "Bad entry" << std::endl;
|
||||
else
|
||||
{
|
||||
std::cout << index << "index \n";
|
||||
this->PrintContact(index - 1);
|
||||
break;
|
||||
return ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PhoneBook::deleteContact()
|
||||
{
|
||||
for (int i = 0; this->_Contact[i] && i < 8; i++)
|
||||
delete this->_Contact[i];
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,6 +24,8 @@ class PhoneBook {
|
||||
void StoreContact(Contact *NewContact);
|
||||
void PrintContact(int index);
|
||||
void PrintIndex();
|
||||
void deleteContact();
|
||||
|
||||
private:
|
||||
|
||||
int _NbrContact;
|
||||
|
||||
@ -6,12 +6,13 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 "PhoneBook.hpp"
|
||||
#include <string>
|
||||
|
||||
void PrintMessage(int index)
|
||||
{
|
||||
@ -27,23 +28,21 @@ void PrintMessage(int index)
|
||||
std::cout << "Enter your darkest secret: ";
|
||||
}
|
||||
|
||||
void search_contact(PhoneBook *Book, Contact *Contact)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void add_contact(PhoneBook *Book, Contact *Contact)
|
||||
void add_contact(PhoneBook *Book )
|
||||
{
|
||||
int index = 0;
|
||||
std::string line;
|
||||
std::string info[5];
|
||||
Contact *Contact = new class Contact;
|
||||
|
||||
while (index < 5)
|
||||
{
|
||||
PrintMessage(index);
|
||||
std::getline(std::cin, 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++;
|
||||
}
|
||||
Contact->FillContact(info);
|
||||
@ -55,23 +54,28 @@ int main(int ac, char **av)
|
||||
PhoneBook book;
|
||||
Contact contact;
|
||||
std::string line;
|
||||
int NbrContact = 0;
|
||||
|
||||
(void)av;
|
||||
if (ac != 1)
|
||||
{
|
||||
std::cout << "too much arguments\n";
|
||||
std::cout << "Too much arguments\n";
|
||||
return (0);
|
||||
}
|
||||
std::cout << "Enter a command : ADD | SEARCH | EXIT" << std::endl;
|
||||
while (line != "EXIT")
|
||||
{
|
||||
std::getline(std::cin, line);
|
||||
if (line != "SEARCH")
|
||||
std::cout << "Enter a command : ADD | SEARCH | EXIT1" << std::endl;
|
||||
if (line == "ADD")
|
||||
add_contact(&book, &contact);
|
||||
add_contact(&book);
|
||||
else if (line == "SEARCH")
|
||||
book.PrintIndex();
|
||||
else
|
||||
else if (line != "EXIT" && !line.empty())
|
||||
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);
|
||||
}
|
||||
@ -11,91 +11,121 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#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 )
|
||||
{
|
||||
return (this->_nbAccounts);
|
||||
return (Account::_nbAccounts);
|
||||
}
|
||||
|
||||
int Account::getTotalAmount( void )
|
||||
{
|
||||
return (this->_totalAmount);
|
||||
return (Account::_totalAmount);
|
||||
}
|
||||
|
||||
int Account::getNbDeposits( void )
|
||||
{
|
||||
return (this->_nbDeposits);
|
||||
return (Account::_totalNbDeposits);
|
||||
}
|
||||
|
||||
int Account::getNbWithdrawals( void )
|
||||
{
|
||||
return (this->_nbWithdrawals);
|
||||
return (Account::_totalNbWithdrawals);
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
this->_nbAccounts = 0;
|
||||
this->_totalAmount = initial_deposit;
|
||||
this->_totalNbDeposits = 0;
|
||||
this->_totalNbWithdrawals = 0;
|
||||
this->_accountIndex = 0;
|
||||
this->_accountIndex = Account::_nbAccounts++;
|
||||
this->_totalAmount += initial_deposit;
|
||||
this->_amount = initial_deposit;
|
||||
this->_nbDeposits = 0;
|
||||
this->_nbWithdrawals = 0;
|
||||
}
|
||||
|
||||
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::_displayTimestamp();
|
||||
std::cout << " index:" << this->_accountIndex << ";amount:" << checkAmount() << ";created" << std::endl;
|
||||
}
|
||||
|
||||
Account::~Account( void )
|
||||
{
|
||||
|
||||
Account::_displayTimestamp();
|
||||
std::cout << " index:" << this->_accountIndex << ";amount:" << checkAmount() << ";closed" << std::endl;
|
||||
}
|
||||
|
||||
void Account::makeDeposit( int deposit )
|
||||
{
|
||||
this->_amount += deposit;
|
||||
|
||||
this->_nbDeposits = 1;
|
||||
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 )
|
||||
{
|
||||
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->_totalNbWithdrawals++;
|
||||
this->_amount -= withdrawal;
|
||||
this->_totalAmount -= withdrawal;
|
||||
std::cout << withdrawal;
|
||||
std::cout << ";amount:" << this->checkAmount();
|
||||
std::cout << ";nb_withdrawals:"<< this->_nbWithdrawals << std::endl;
|
||||
return (1);
|
||||
}
|
||||
std::cout << "refused\n";
|
||||
return (0);
|
||||
}
|
||||
|
||||
int Account::checkAmount( void ) const
|
||||
{
|
||||
|
||||
return (this->_amount);
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
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;
|
||||
}
|
||||
@ -6,17 +6,17 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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\
|
||||
tests.cpp
|
||||
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
OBJS = ${SRCS:.cpp=.o}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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()
|
||||
{
|
||||
std::cout << "I love having extra bacon for my 7XL-double-cheese-triple-pickle-specialketchup burger. I really do!\n";
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
|
||||
int chooseComplain(std::string level);
|
||||
void complain(std::string level);
|
||||
|
||||
private:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,31 +6,48 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
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)
|
||||
{
|
||||
Harl harl;
|
||||
bool freeHarl = 0;
|
||||
std::string levelTab[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
|
||||
|
||||
std::cout << ac << std::endl;
|
||||
if (ac != 2)
|
||||
{
|
||||
std::cerr << "Bad entry\n";
|
||||
return (1);
|
||||
}
|
||||
harFilter(harl, av[1]);
|
||||
return (0);
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (av[1] == levelTab[j])
|
||||
freeHarl = 1;
|
||||
if (freeHarl == 1)
|
||||
{
|
||||
while (j < 4)
|
||||
{
|
||||
harl.complain(levelTab[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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}
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
CFLAGS = -Wall -Wextra -Werror -std=c++98
|
||||
RM = rm -rf
|
||||
|
||||
.cpp.o:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user