ex02 ok
This commit is contained in:
@@ -1,46 +1,119 @@
|
||||
#include "Account.hpp"
|
||||
#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 ) {
|
||||
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 ) {
|
||||
|
||||
this->_displayTimestamp();
|
||||
std::cout << "index:" << this->_accountIndex << ";";
|
||||
std::cout << "amount:" << this->_amount << ";";
|
||||
std::cout << "closed" << std::endl;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef Account t;
|
||||
void Account::makeDeposit( int deposit ) {
|
||||
|
||||
static int getNbAccounts( void );
|
||||
static int getTotalAmount( void );
|
||||
static int getNbDeposits( void );
|
||||
static int getNbWithdrawals( void );
|
||||
static void displayAccountsInfos( void );
|
||||
this->_displayTimestamp();
|
||||
std::cout << "index:" << this->_accountIndex << ";";
|
||||
std::cout << "p_amount:" << this->_amount << ";";
|
||||
std::cout << "deposit:" << deposit << ";";
|
||||
|
||||
Account( int initial_deposit );
|
||||
~Account( void );
|
||||
this->_totalNbDeposits++;
|
||||
this->_nbDeposits++;
|
||||
this->_amount += deposit;
|
||||
this->_totalAmount += deposit;
|
||||
|
||||
void makeDeposit( int deposit );
|
||||
bool makeWithdrawal( int withdrawal );
|
||||
int checkAmount( void ) const;
|
||||
void displayStatus( void ) const;
|
||||
std::cout << "amount:" << this->_amount << ";";
|
||||
std::cout << "nb_deposits:" << this->_nbDeposits << std::endl;
|
||||
}
|
||||
|
||||
bool Account::makeWithdrawal( int withdrawal ) {
|
||||
|
||||
private:
|
||||
this->_displayTimestamp();
|
||||
std::cout << "index:" << this->_accountIndex << ";";
|
||||
std::cout << "p_amount:" << this->_amount << ";";
|
||||
|
||||
static int _nbAccounts;
|
||||
static int _totalAmount;
|
||||
static int _totalNbDeposits;
|
||||
static int _totalNbWithdrawals;
|
||||
if (withdrawal > this->_amount)
|
||||
{
|
||||
std::cout << "withdrawal:refused" << std::endl;
|
||||
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;
|
||||
int _amount;
|
||||
int _nbDeposits;
|
||||
int _nbWithdrawals;
|
||||
return true;
|
||||
}
|
||||
|
||||
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 );
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user