diff --git a/cpp00/ex01/main.cpp b/cpp00/ex01/main.cpp index d4fe0b6..0898e41 100644 --- a/cpp00/ex01/main.cpp +++ b/cpp00/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/04/17 15:55:40 by apommier #+# #+# */ -/* Updated: 2022/04/21 18:58:19 by apommier ### ########.fr */ +/* Updated: 2022/07/20 12:19:30 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,6 @@ int main(int ac, char **av) std::cout << "too much arguments\n"; return (0); } - //line = "nothing"; std::cout << "Enter a command : ADD | SEARCH | EXIT" << std::endl; while (line != "EXIT") { @@ -74,6 +73,5 @@ int main(int ac, char **av) else std::cout << "Invalid command" << std::endl; } - //std::cout << "exit\n"; return (0); } \ No newline at end of file diff --git a/cpp00/ex02/Account.cpp b/cpp00/ex02/Account.cpp new file mode 100644 index 0000000..3c58104 --- /dev/null +++ b/cpp00/ex02/Account.cpp @@ -0,0 +1,101 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Account.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apommier +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/07/20 12:23:50 by apommier #+# #+# */ +/* Updated: 2022/07/20 12:48:54 by apommier ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Account.hpp" + +int Account::getNbAccounts( void ) +{ + return (this->_nbAccounts); +} + +int Account::getTotalAmount( void ) +{ + return (this->_totalAmount); +} + +int Account::getNbDeposits( void ) +{ + return (this->_nbDeposits); +} + +int Account::getNbWithdrawals( void ) +{ + return (this->_nbWithdrawals); +} + +void Account::displayAccountsInfos( void ) +{ + +} + +Account::Account( int initial_deposit ) +{ + this->_nbAccounts = 0; + this->_totalAmount = initial_deposit; + this->_totalNbDeposits = 0; + this->_totalNbWithdrawals = 0; + this->_accountIndex = 0; + 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::~Account( void ) +{ + +} + +void Account::makeDeposit( int deposit ) +{ + this->_amount += deposit; + this->_nbDeposits = 1; + this->_totalNbDeposits++; +} + +bool Account::makeWithdrawal( int withdrawal ) +{ + if (this->_totalAmount >= withdrawal) + { + this->_nbWithdrawals = 1; + this->_totalNbWithdrawals++; + this->_amount -= withdrawal; + return (1); + } + return (0); +} + +int Account::checkAmount( void ) const +{ + +} + +void Account::displayStatus( void ) const +{ + +} + +void Account::_displayTimestamp( void ) +{ + +} diff --git a/cpp00/ex02/Account.hpp b/cpp00/ex02/Account.hpp new file mode 100644 index 0000000..a49f9c5 --- /dev/null +++ b/cpp00/ex02/Account.hpp @@ -0,0 +1,69 @@ +// ************************************************************************** // +// // +// Account.hpp for GlobalBanksters United // +// Created on : Thu Nov 20 19:43:15 1989 // +// Last update : Wed Jan 04 14:54:06 1992 // +// Made by : Brad "Buddy" McLane // +// // +// ************************************************************************** // + + +#pragma once +#ifndef __ACCOUNT_H__ +#define __ACCOUNT_H__ + +// ************************************************************************** // +// Account Class // +// ************************************************************************** // + +class Account { + + +public: + + typedef Account t; + + static int getNbAccounts( void ); + static int getTotalAmount( void ); + static int getNbDeposits( void ); + static int getNbWithdrawals( void ); + static void displayAccountsInfos( void ); + + Account( int initial_deposit ); + ~Account( void ); + + void makeDeposit( int deposit ); + bool makeWithdrawal( int withdrawal ); + int checkAmount( void ) const; + void displayStatus( void ) const; + + +private: + + static int _nbAccounts; + static int _totalAmount; + static int _totalNbDeposits; + static int _totalNbWithdrawals; + + static void _displayTimestamp( void ); + + int _accountIndex; + int _amount; + int _nbDeposits; + int _nbWithdrawals; + + Account( void ); + +}; + + + +// ************************************************************************** // +// vim: set ts=4 sw=4 tw=80 noexpandtab: // +// -*- indent-tabs-mode:t; -*- +// -*- mode: c++-mode; -*- +// -*- fill-column: 75; comment-column: 75; -*- +// ************************************************************************** // + + +#endif /* __ACCOUNT_H__ */ \ No newline at end of file diff --git a/cpp00/ex02/Makefile b/cpp00/ex02/Makefile index 72b2288..faea912 100644 --- a/cpp00/ex02/Makefile +++ b/cpp00/ex02/Makefile @@ -6,12 +6,13 @@ # By: apommier +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/04/15 01:47:51 by apommier #+# #+# # -# Updated: 2022/07/18 20:52:38 by apommier ### ########.fr # +# Updated: 2022/07/20 12:51:45 by apommier ### ########.fr # # # # **************************************************************************** # -NAME = megaphone -SRCS = megaphone.cpp +NAME = a.out +SRCS = Account.cpp\ + tests.cpp OBJS = ${SRCS:.cpp=.o} CC = c++ diff --git a/cpp00/ex02/tests.cpp b/cpp00/ex02/tests.cpp new file mode 100644 index 0000000..816987a --- /dev/null +++ b/cpp00/ex02/tests.cpp @@ -0,0 +1,72 @@ +// ************************************************************************** // +// // +// tests.cpp for GlobalBanksters United // +// Created on : Thu Nov 20 23:45:02 1989 // +// Last update : Wed Jan 04 09:23:52 1992 // +// Made by : Brad "Buddy" McLane // +// // +// ************************************************************************** // + +#include +#include +#include +#include "Account.hpp" + + +int main( void ) { + + typedef std::vector accounts_t; + typedef std::vector ints_t; + typedef std::pair acc_int_t; + + int const amounts[] = { 42, 54, 957, 432, 1234, 0, 754, 16576 }; + size_t const amounts_size( sizeof(amounts) / sizeof(int) ); + accounts_t accounts( amounts, amounts + amounts_size ); + accounts_t::iterator acc_begin = accounts.begin(); + accounts_t::iterator acc_end = accounts.end(); + + int const d[] = { 5, 765, 564, 2, 87, 23, 9, 20 }; + size_t const d_size( sizeof(d) / sizeof(int) ); + ints_t deposits( d, d + d_size ); + ints_t::iterator dep_begin = deposits.begin(); + ints_t::iterator dep_end = deposits.end(); + + int const w[] = { 321, 34, 657, 4, 76, 275, 657, 7654 }; + size_t const w_size( sizeof(w) / sizeof(int) ); + ints_t withdrawals( w, w + w_size ); + ints_t::iterator wit_begin = withdrawals.begin(); + ints_t::iterator wit_end = withdrawals.end(); + + Account::displayAccountsInfos(); + std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); + + for ( acc_int_t it( acc_begin, dep_begin ); + it.first != acc_end && it.second != dep_end; + ++(it.first), ++(it.second) ) { + + (*(it.first)).makeDeposit( *(it.second) ); + } + + Account::displayAccountsInfos(); + std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); + + for ( acc_int_t it( acc_begin, wit_begin ); + it.first != acc_end && it.second != wit_end; + ++(it.first), ++(it.second) ) { + + (*(it.first)).makeWithdrawal( *(it.second) ); + } + + Account::displayAccountsInfos(); + std::for_each( acc_begin, acc_end, std::mem_fun_ref( &Account::displayStatus ) ); + + return 0; +} + + +// ************************************************************************** // +// vim: set ts=4 sw=4 tw=80 noexpandtab: // +// -*- indent-tabs-mode:t; -*- +// -*- mode: c++-mode; -*- +// -*- fill-column: 75; comment-column: 75; -*- +// ************************************************************************** // \ No newline at end of file