#include <cstdio>
#include <cstdlib>
#include <iostream>
#include "AccountLinkedList.h"
using namespace std ;
using namespace Lists ;
/* Account — абстрактный класс, включающий общие свойства различных счетов */
class Account
{
public :
Account::Account( AccountLinkedList* pList , int accNo )
: node( pList , this )
{
/* Инициализация данных-членов */
accountNumber = accNo ;
balance = 0 ;
count++ ;
}
_________________
358 стр. Часть 6. Великолепная десятка
/* Функции доступа */
int accountNo( ) { return accountNumber ; }
double acntBalance( ) { return balance ; }
static int noAccounts( ) { return count ; }
/* Функции транзакций */
void deposit( double amount ) { balance += amount ; }
virtual bool withdrawal( double amount )
{
if ( balance < amount )
{
cout << "Недостаточно денег: на счету " << balance
<<", снимаем " << amount
<< endl ;
return false ;
}
balance -= amount ;
return true ;
}
/* Функция вывода на экран */
void display( )
{
cout << type( )
<< " счёт " << accountNumber
<< " = " << balance
<< endl ;
}
virtual char* type( ) = 0 ;
protected :
/* Информация о связанном списке */
Node node ;
static int count ; /* Количество счетов */
unsigned accountNumber ;
double balance ;
} ;
/* Переменная для сбора статистики */
int Account::count = 0 ;
/* Checking — свойства, уникальные для чекового счёта */
class Checking : public Account
{
public :
Checking::Checking( AccountLinkedList* pLL ,
unsigned accNo ) :
Account( pLL , accNo )
{ }
/* Перегрузка чисто виртуальных функций */
virtual bool withdrawal( double amount ) ;
virtual char* type( ) { return "Чековый" ; }
} ;
/* withdrawal — перегрузка Account::withdrawal( ) */
_________________
359 стр. Глава 31. Программа BUDGET
bool Checking::withdrawal( double amount )
{
bool success = Account::withdrawal( amount ) ;
if ( success && balance < 500.00 )
{
balance -= 0.20 ;
}
return success ;
}
/* Savings — свойства, уникальные для сберегательного счёта */
class Savings : public Account
{
public :
Savings::Savings( AccountLinkedList* pLL ,
unsigned accNo ) :
Account( pLL , accNo )
{ noWithdrawals = 0 ; }
/* Функции транзакций */
virtual bool withdrawal( double amount ) ;
virtual char* type( ) { return "Сберегательный" ; }
protected :
int noWithdrawals ;
} ;
/* withdrawal — перегрузка Account::withdrawal( ) */
bool Savings::withdrawal( double amount )
{
if ( ++noWithdrawals > 1 )
{
balance -= 5.00 ;