update: finishing the ex02

This commit is contained in:
Raphael 2024-11-04 15:39:36 +01:00
parent 223b7ee66c
commit 99295d66a3
4 changed files with 202 additions and 80 deletions

View file

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

View file

@ -1,4 +1,4 @@
/* ************************************************************************** */ /* ************************************************************************* */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* Account.cpp :+: :+: :+: */ /* Account.cpp :+: :+: :+: */
@ -6,15 +6,21 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */ /* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/23 16:11:46 by rparodi #+# #+# */ /* Created: 2024/10/23 16:11:46 by rparodi #+# #+# */
/* Updated: 2024/10/25 14:11:27 by rparodi ### ########.fr */ /* Updated: 2024/11/04 15:38:22 by rparodi ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "Account.hpp" #include "Account.hpp"
#include <ctime> #include <ctime>
#include <iostream> #include <iostream>
#include <ostream>
static void _displayTimestamp( void ) int Account::_nbAccounts = 0;
int Account::_totalAmount = 0;
int Account::_totalNbDeposits = 0;
int Account::_totalNbWithdrawals = 0;
void Account::_displayTimestamp( void )
{ {
time_t raw_time = time(0); time_t raw_time = time(0);
tm *time = localtime(&raw_time); tm *time = localtime(&raw_time);
@ -25,42 +31,99 @@ static void _displayTimestamp( void )
/// [19920104_091532] index:0;amount:42;created /// [19920104_091532] index:0;amount:42;created
Account::Account( int initial_deposit ) Account::Account( int initial_deposit )
{ {
_nbAccounts += 1; _accountIndex = _nbAccounts;
_totalAmount = initial_deposit; _amount = initial_deposit;
_totalNbDeposits = 0; _totalAmount += _amount;
_totalNbWithdrawals = 0; _nbDeposits = 0;
_nbWithdrawals = 0;
_displayTimestamp(); _displayTimestamp();
std::cout << "index:" << _accountIndex << ";"; std::cout << "index:" << _accountIndex << ";";
std::cout << "amount:" << _totalAmount << ";"; std::cout << "amount:" << _amount << ";";
std::cout << "created" << std::endl; std::cout << "created" << std::endl;
_nbAccounts++;
} }
// index:0;amount:47;closed
Account::~Account() Account::~Account()
{ {
_accountIndex--;
_displayTimestamp(); _displayTimestamp();
std::cout << "index:" << _accountIndex << ";"; std::cout << "index:" << _accountIndex << ";";
std::cout << "amount:" << _totalAmount << ";"; std::cout << "amount:" << _amount << ";";
std::cout << "closed" << std::endl; std::cout << "closed" << std::endl;
_nbAccounts--;
} }
// [19920104_091532] index:1;p_amount:54;deposit:765;amount:819;nb_deposits:1
void Account::makeDeposit(int deposit)
{
_displayTimestamp();
std::cout << "index:" << _accountIndex << ";";
std::cout << "p_amount:" << _amount << ";";
std::cout << "deposit:" << deposit << ";";
_amount += deposit;
_totalAmount += deposit;
std::cout << "amount:" << _amount << ";";
_totalNbDeposits++;
_nbDeposits++;
std::cout << "nb_deposits:" << _nbDeposits << std::endl;
}
// [19920104_091532] index:1;p_amount:819;withdrawal:34;amount:785;nb_withdrawals:1
bool Account::makeWithdrawal(int withdrawal)
{
_displayTimestamp();
std::cout << "index:" << _accountIndex << ";";
std::cout << "p_amount:" << _amount << ";";
if (withdrawal > _amount)
{
std::cout << "withdrawal:refused" << std::endl;
return false;
}
std::cout << "withdrawal:" << withdrawal << ";";
_totalAmount -= withdrawal;
_amount -= withdrawal;
std::cout << "amount:" << _amount << ";";
_totalNbWithdrawals++;
_nbWithdrawals++;
std::cout << "nb_withdrawals:" << _nbWithdrawals << std::endl;
return true;
}
int Account::getNbAccounts() int Account::getNbAccounts()
{ {
return (1); return (_nbAccounts);
} }
int Account::getTotalAmount(); int Account::getTotalAmount()
{
return (Account::_totalAmount);
}
static int Account::getNbDeposits(); int Account::getNbDeposits()
{
return (Account::_totalNbDeposits);
}
static int Account::getNbWithdrawals(); int Account::getNbWithdrawals()
{
return (Account::_totalNbWithdrawals);
}
/// [19920104_091532] index:2;p_amount:957;deposit:564;amount:1521;nb_deposits:1 void Account::displayAccountsInfos() {
static void Account::displayAccountsInfos() _displayTimestamp();
std::cout << "accounts:" << _nbAccounts
<< ";total:" << _totalAmount
<< ";deposits:" << _totalNbDeposits
<< ";withdrawals:" << _totalNbWithdrawals
<< std::endl;
}
//[19920104_091532] index:0;amount:42;deposits:0;withdrawals:0
void Account::displayStatus() const
{ {
_displayTimestamp(); _displayTimestamp();
std::cout << "index:" << _accountIndex << ";"; std::cout << "index:" << _accountIndex << ";";
std::cout << "amount:" << _totalAmount << ";"; std::cout << "amount:" << _amount << ";";
std::cout << "deposit:" << _totalNbDeposits << ";"; std::cout << "deposits:" << _nbDeposits << ";";
std::cout << "withdrawals:" << _nbWithdrawals << std::endl;
} }

View file

@ -6,14 +6,14 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ # # By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2024/10/25 13:20:21 by rparodi ### ########.fr # # Updated: 2024/11/04 15:01:43 by rparodi ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
# Variables # Variables
# Name # Name
NAME = phonebook NAME = job_of_dream
# Commands # Commands
CXX = c++ CXX = c++

59
cpp00/ex02/test.log Normal file
View file

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