Yurttas/PL/IL/Ada-95/F/04/02/00/transactions p.adb

  1--
  2-- Copyright(C) 1998
  3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
  4--
  5-- Permission to use, copy, modify, and distribute this
  6-- software and its documentation for EDUCATIONAL purposes
  7-- and without fee is hereby granted provided that this
  8-- copyright notice appears in all copies.
  9--
 10 
 11-- date   : September 1, 1999.
 12-- authorĀ : Salih Yurttas.
 13--          adapted from John English's book.
 14
 15-- transactions_p.adb
 16
 17
 18package body Transactions_P is
 19
 20  procedure P_A is
 21    Someone   : Interest_Account;
 22    Obtain : Money;
 23  begin
 24    Statement(Someone);
 25
 26    Withdraw(Someone,
 27             100.00,
 28             Obtain);       -- Withdraw some money
 29
 30    Statement(Someone);
 31
 32    Deposit(Someone,
 33            300.00);        -- In credit
 34
 35    Statement(Someone);
 36  end P_A;
 37
 38  procedure P_B is
 39    Someone   : Account_Ltd;
 40    Obtain : Money;
 41  begin
 42    Deposit(Someone,
 43            300.00);        -- In credit
 44
 45    Statement(Someone);
 46
 47    Withdraw(Someone,
 48             100.00,
 49             Obtain);       -- Withdraw some money
 50
 51    Withdraw(Someone,
 52             10.00,
 53             Obtain);       -- Withdraw some money
 54
 55    Withdraw(Someone,
 56             10.00,
 57             Obtain);       -- Withdraw some money
 58
 59    Withdraw(Someone,
 60             20.00,
 61             Obtain);       -- Withdraw some money
 62
 63    Statement(Someone);
 64  end P_B;
 65
 66  procedure P_C is
 67    Someone   : Account_Ltd;
 68    Obtain : Money;
 69  begin
 70    Deposit(Someone,
 71            300.00);        -- In credit
 72
 73    Statement(Someone);
 74
 75    Withdraw(Someone,
 76             100.00,
 77             Obtain);       -- Withdraw some money
 78
 79    Statement(Someone);
 80
 81    Withdraw(Someone,
 82             10.00,
 83             Obtain);       -- Withdraw some money
 84
 85    Statement(Someone);
 86
 87    Withdraw(Someone,
 88             10.00,
 89             Obtain);       -- Withdraw some money
 90
 91    Statement(Someone);
 92
 93    Withdraw(Account(Someone),
 94             20.00,
 95             Obtain);       -- Cheat
 96
 97    Statement(Someone);
 98  end P_C;
 99
100  procedure P_D is
101    MAX_ACCOUNTS : CONSTANT := 5;
102
103    type P_Account is access all Account'Class;
104
105    type Bank_Index is range 1 .. MAX_ACCOUNTS;
106
107    subtype Bank_Range is Bank_Index;
108
109    type Bank_Array is array(Bank_Range) of P_Account;
110
111    procedure Print_Statement(No : in Bank_Range;
112                              A  : in Account'Class) is
113    begin
114      Put("Account number #");
115      Put(Integer'Image(Integer(No)));
116      New_Line;
117      Statement(A);
118    end Print_Statement;
119
120    Piggy    : Bank_Array;
121    Obtained : Money;
122
123  begin
124    Piggy(1) := new Account;
125    Piggy(2) := new Account_Ltd;
126    Piggy(3) := new Interest_Account;
127    Piggy(4) := new Interest_Account;
128    Piggy(5) := new Account;
129
130    Deposit(Piggy(1).all,
131            100.00);        -- Deposit $100 #1
132
133    Deposit(Piggy(3).all,
134            100.00);        -- Deposit $100 #3
135
136    Withdraw(Piggy(2).all,
137             50.00,
138             Obtained);     -- Withdraw $50 #2
139
140    Withdraw(Piggy(4).all,
141             50.00,
142             Obtained);     -- Withdraw $50 #4
143
144    for I in Bank_Range
145    loop
146      Print_Statement(I,
147                      Piggy(I).all);
148    end loop;
149  end P_D;
150
151end Transactions_P;