ouverture ex02
This commit is contained in:
46
d00/ex02/Account.cpp
Normal file
46
d00/ex02/Account.cpp
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "Account.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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 );
|
||||||
|
*/
|
||||||
69
d00/ex02/Account.hpp
Normal file
69
d00/ex02/Account.hpp
Normal file
@@ -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 <bm@gbu.com> //
|
||||||
|
// //
|
||||||
|
// ************************************************************************** //
|
||||||
|
|
||||||
|
|
||||||
|
#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__ */
|
||||||
62
d00/ex02/Makefile
Normal file
62
d00/ex02/Makefile
Normal file
@@ -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
|
||||||
72
d00/ex02/tests.cpp
Normal file
72
d00/ex02/tests.cpp
Normal file
@@ -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 <bm@gbu.com> //
|
||||||
|
// //
|
||||||
|
// ************************************************************************** //
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include "Account.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
int main( void ) {
|
||||||
|
|
||||||
|
// typedef std::vector<Account::t> accounts_t;
|
||||||
|
// typedef std::vector<int> ints_t;
|
||||||
|
// typedef std::pair<accounts_t::iterator, ints_t::iterator> 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; -*-
|
||||||
|
// ************************************************************************** //
|
||||||
Reference in New Issue
Block a user