Merge branch 'master' of bitbucket.org:hugogogo/piscine_cpp
This commit is contained in:
@@ -1,46 +1,119 @@
|
|||||||
#include "Account.hpp"
|
#include "Account.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
void Account::displayAccountsInfos( void ) {
|
||||||
|
|
||||||
|
_displayTimestamp();
|
||||||
|
std::cout << "accounts:" << _nbAccounts << ";";
|
||||||
|
std::cout << "total:" << _totalAmount << ";";
|
||||||
|
std::cout << "deposits:" << _totalNbDeposits << ";";
|
||||||
|
std::cout << "withdrawals:" << _totalNbWithdrawals << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
Account::Account( int initial_deposit ) {
|
Account::Account( int initial_deposit ) {
|
||||||
std::cout << "hello" << std::endl;
|
|
||||||
return 1;
|
this->_accountIndex = this->_nbAccounts;
|
||||||
|
this->_nbAccounts++;
|
||||||
|
this->_amount = initial_deposit;
|
||||||
|
this->_totalAmount += initial_deposit;
|
||||||
|
this->_nbDeposits = 0;
|
||||||
|
this->_nbWithdrawals = 0;
|
||||||
|
|
||||||
|
this->_displayTimestamp();
|
||||||
|
std::cout << "index:" << this->_accountIndex << ";";
|
||||||
|
std::cout << "amount:" << this->_amount << ";";
|
||||||
|
std::cout << "created" << std::endl;
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Account::~Account( void ) {
|
Account::~Account( void ) {
|
||||||
|
|
||||||
|
this->_displayTimestamp();
|
||||||
|
std::cout << "index:" << this->_accountIndex << ";";
|
||||||
|
std::cout << "amount:" << this->_amount << ";";
|
||||||
|
std::cout << "closed" << std::endl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
void Account::makeDeposit( int deposit ) {
|
||||||
typedef Account t;
|
|
||||||
|
|
||||||
static int getNbAccounts( void );
|
this->_displayTimestamp();
|
||||||
static int getTotalAmount( void );
|
std::cout << "index:" << this->_accountIndex << ";";
|
||||||
static int getNbDeposits( void );
|
std::cout << "p_amount:" << this->_amount << ";";
|
||||||
static int getNbWithdrawals( void );
|
std::cout << "deposit:" << deposit << ";";
|
||||||
static void displayAccountsInfos( void );
|
|
||||||
|
|
||||||
Account( int initial_deposit );
|
this->_totalNbDeposits++;
|
||||||
~Account( void );
|
this->_nbDeposits++;
|
||||||
|
this->_amount += deposit;
|
||||||
|
this->_totalAmount += deposit;
|
||||||
|
|
||||||
void makeDeposit( int deposit );
|
std::cout << "amount:" << this->_amount << ";";
|
||||||
bool makeWithdrawal( int withdrawal );
|
std::cout << "nb_deposits:" << this->_nbDeposits << std::endl;
|
||||||
int checkAmount( void ) const;
|
}
|
||||||
void displayStatus( void ) const;
|
|
||||||
|
|
||||||
|
bool Account::makeWithdrawal( int withdrawal ) {
|
||||||
|
|
||||||
private:
|
this->_displayTimestamp();
|
||||||
|
std::cout << "index:" << this->_accountIndex << ";";
|
||||||
|
std::cout << "p_amount:" << this->_amount << ";";
|
||||||
|
|
||||||
static int _nbAccounts;
|
if (withdrawal > this->_amount)
|
||||||
static int _totalAmount;
|
{
|
||||||
static int _totalNbDeposits;
|
std::cout << "withdrawal:refused" << std::endl;
|
||||||
static int _totalNbWithdrawals;
|
return false;
|
||||||
|
}
|
||||||
|
this->_totalNbWithdrawals++;
|
||||||
|
this->_nbWithdrawals++;
|
||||||
|
this->_amount -= withdrawal;
|
||||||
|
this->_totalAmount -= withdrawal;
|
||||||
|
|
||||||
static void _displayTimestamp( void );
|
std::cout << "withdrawal:" << withdrawal << ";";
|
||||||
|
std::cout << "amount:" << this->_amount << ";";
|
||||||
|
std::cout << "nb_withdrawals:" << this->_nbWithdrawals << std::endl;
|
||||||
|
|
||||||
int _accountIndex;
|
return true;
|
||||||
int _amount;
|
}
|
||||||
int _nbDeposits;
|
|
||||||
int _nbWithdrawals;
|
void Account::displayStatus( void ) const {
|
||||||
|
|
||||||
|
this->_displayTimestamp();
|
||||||
|
std::cout << "index:" << this->_accountIndex << ";";
|
||||||
|
std::cout << "amount:" << this->_amount << ";";
|
||||||
|
std::cout << "deposits:" << this->_nbDeposits << ";";
|
||||||
|
std::cout << "withdrawals:" << this->_nbWithdrawals << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Account::_displayTimestamp( void ) {
|
||||||
|
|
||||||
|
time_t rawtime = time(NULL);
|
||||||
|
struct tm *stamp = localtime(&rawtime);
|
||||||
|
std::cout << "[";
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_year + 1900;
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_mon;
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_mday << "_";
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_hour;
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_min;
|
||||||
|
std::cout << std::setfill('0') << std::setw(2) << stamp->tm_sec;
|
||||||
|
std::cout << "] ";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int Account::_totalAmount = 0;
|
||||||
|
int Account::_nbAccounts = 0;
|
||||||
|
int Account::_totalNbDeposits = 0;
|
||||||
|
int Account::_totalNbWithdrawals = 0;
|
||||||
|
|
||||||
|
int Account::checkAmount( void ) const {return 0;}
|
||||||
|
int Account::getNbAccounts( void ) {return 0;}
|
||||||
|
int Account::getTotalAmount( void ) {return 0;}
|
||||||
|
int Account::getNbDeposits( void ) {return 0;}
|
||||||
|
int Account::getNbWithdrawals( void ) {return 0;}
|
||||||
|
|
||||||
|
Account::Account( void ) {return;}
|
||||||
|
|
||||||
Account( void );
|
|
||||||
*/
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
NAME = account
|
NAME = account
|
||||||
|
|
||||||
CC = clang++
|
CC = clang++
|
||||||
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98
|
CFLAGS = -Wall -Wextra -Wno-unused -Werror $(INCLUDES) -std=c++98
|
||||||
|
|
||||||
VPATH = $(D_SRCS)
|
VPATH = $(D_SRCS)
|
||||||
|
|
||||||
|
|||||||
@@ -12,53 +12,52 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include "Account.hpp"
|
#include "Account.hpp"
|
||||||
|
|
||||||
|
|
||||||
int main( void ) {
|
int main( void ) {
|
||||||
|
|
||||||
// typedef std::vector<Account::t> accounts_t;
|
typedef std::vector<Account::t> accounts_t;
|
||||||
// typedef std::vector<int> ints_t;
|
typedef std::vector<int> ints_t;
|
||||||
// typedef std::pair<accounts_t::iterator, ints_t::iterator> acc_int_t;
|
typedef std::pair<accounts_t::iterator, ints_t::iterator> acc_int_t;
|
||||||
|
|
||||||
// int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 };
|
int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 };
|
||||||
// size_t const amounts_size( sizeof(amounts) / sizeof(int) );
|
size_t const amounts_size( sizeof(amounts) / sizeof(int) );
|
||||||
// accounts_t accounts( amounts, amounts + amounts_size );
|
accounts_t accounts( amounts, amounts + amounts_size );
|
||||||
// accounts_t::iterator acc_begin = accounts.begin();
|
accounts_t::iterator acc_begin = accounts.begin();
|
||||||
// accounts_t::iterator acc_end = accounts.end();
|
accounts_t::iterator acc_end = accounts.end();
|
||||||
|
|
||||||
// int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 };
|
int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 };
|
||||||
// size_t const d_size( sizeof(d) / sizeof(int) );
|
size_t const d_size( sizeof(d) / sizeof(int) );
|
||||||
// ints_t deposits( d, d + d_size );
|
ints_t deposits( d, d + d_size );
|
||||||
// ints_t::iterator dep_begin = deposits.begin();
|
ints_t::iterator dep_begin = deposits.begin();
|
||||||
// ints_t::iterator dep_end = deposits.end();
|
ints_t::iterator dep_end = deposits.end();
|
||||||
|
|
||||||
// int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 };
|
int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 };
|
||||||
// size_t const w_size( sizeof(w) / sizeof(int) );
|
size_t const w_size( sizeof(w) / sizeof(int) );
|
||||||
// ints_t withdrawals( w, w + w_size );
|
ints_t withdrawals( w, w + w_size );
|
||||||
// ints_t::iterator wit_begin = withdrawals.begin();
|
ints_t::iterator wit_begin = withdrawals.begin();
|
||||||
// ints_t::iterator wit_end = withdrawals.end();
|
ints_t::iterator wit_end = withdrawals.end();
|
||||||
|
|
||||||
// Account::displayAccountsInfos();
|
Account::displayAccountsInfos();
|
||||||
// std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||||
|
|
||||||
// for ( acc_int_t it( acc_begin, dep_begin );
|
for ( acc_int_t it( acc_begin, dep_begin );
|
||||||
// it.first != acc_end && it.second != dep_end;
|
it.first != acc_end && it.second != dep_end;
|
||||||
// ++(it.first), ++(it.second) ) {
|
++(it.first), ++(it.second) ) {
|
||||||
|
|
||||||
// (*(it.first)).makeDeposit( *(it.second) );
|
(*(it.first)).makeDeposit( *(it.second) );
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Account::displayAccountsInfos();
|
Account::displayAccountsInfos();
|
||||||
// std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||||
|
|
||||||
// for ( acc_int_t it( acc_begin, wit_begin );
|
for ( acc_int_t it( acc_begin, wit_begin );
|
||||||
// it.first != acc_end && it.second != wit_end;
|
it.first != acc_end && it.second != wit_end;
|
||||||
// ++(it.first), ++(it.second) ) {
|
++(it.first), ++(it.second) ) {
|
||||||
|
|
||||||
// (*(it.first)).makeWithdrawal( *(it.second) );
|
(*(it.first)).makeWithdrawal( *(it.second) );
|
||||||
// }
|
}
|
||||||
|
|
||||||
// Account::displayAccountsInfos();
|
Account::displayAccountsInfos();
|
||||||
// std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user