From a30edf91ab5534504a073eb56e10f456f058b829 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 4 Feb 2022 15:33:13 +0100 Subject: [PATCH] ouverture ex02 --- d00/ex02/Account.cpp | 46 ++++++++++++++++++++++++++++ d00/ex02/Account.hpp | 69 ++++++++++++++++++++++++++++++++++++++++++ d00/ex02/Makefile | 62 ++++++++++++++++++++++++++++++++++++++ d00/ex02/tests.cpp | 72 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 d00/ex02/Account.cpp create mode 100644 d00/ex02/Account.hpp create mode 100644 d00/ex02/Makefile create mode 100644 d00/ex02/tests.cpp diff --git a/d00/ex02/Account.cpp b/d00/ex02/Account.cpp new file mode 100644 index 0000000..4adb3ea --- /dev/null +++ b/d00/ex02/Account.cpp @@ -0,0 +1,46 @@ +#include "Account.hpp" +#include + +Account::Account( int initial_deposit ) { + std::cout << "hello" << std::endl; + return 1; +} + +Account::~Account( void ) { + return; +} + +/* + 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 ); +*/ diff --git a/d00/ex02/Account.hpp b/d00/ex02/Account.hpp new file mode 100644 index 0000000..cd31e06 --- /dev/null +++ b/d00/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__ */ diff --git a/d00/ex02/Makefile b/d00/ex02/Makefile new file mode 100644 index 0000000..80da725 --- /dev/null +++ b/d00/ex02/Makefile @@ -0,0 +1,62 @@ +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value . name is case sensitive # +# VARIABLES . or name = value \ . use VPATH only for .c # +# . value . or .cpp # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +NAME = account + +CC = clang++ +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 + +VPATH = $(D_SRCS) + +LIBS = + +INCLUDES = -I$(D_HEADERS) + +D_SRCS = . +SRCS = tests.cpp \ + Account.cpp + +D_HEADERS = . +HEADERS = Account.hpp + +D_OBJS = builds +OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) + +RM_D_OBJS = rm -rf $(D_OBJS) +ifeq "$(D_OBJS)" "." +RM_D_OBJS = +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +$(D_OBJS)/%.o: %.cpp | $(D_OBJS) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(HEADERS:%=$(D_HEADERS)/%) + +$(NAME): $(OBJS) + $(CC) $(OBJS) -o $@ $(LIBS) + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(NAME) + $(RM_D_OBJS) + +re: fclean all + +.PHONY : all clean fclean re bonus run valgrind diff --git a/d00/ex02/tests.cpp b/d00/ex02/tests.cpp new file mode 100644 index 0000000..40ae348 --- /dev/null +++ b/d00/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; -*- +// ************************************************************************** //