Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras » Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/account

Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/account

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1997-10 A.adf » Extras
Filename: Apple][e/PD/BOB/ARMBOB/!ArmBob/progs/h/account
Read OK:
File size: 057B bytes
Load address: 0000
Exec address: 0000
File contents
/* Accounts    GCW    02/03/94  */

class account
{
 balance;        /* An account's state */
 owner;
 password;
 starting_date;

 withdraw(x);   /* An account's methods */
 statement();
 change_password();
 has_owner(name);
}    

account::account(amount,name)
{
 balance = (amount>0)?amount:0;
 owner = name;
 print("Enter ",name,"'s password here: ");
 password = hidden_input('-');
 starting_date = sysvar("Sys$Date");
 return this;
}

account::withdraw(x)
{
 local sum;
 print("Please enter your password :");
 if (password == hidden_input('-'))
   {
    sum = (x < balance)?x:balance;
    balance -= sum;
    print("\n",owner,"'s account has been debited ",sum,".\n");
   }
 else
  {
   sum = 0;
   print("\nSorry! Wrong password.\n");
  }
 return sum;
}

account::statement()
{
 print("Please enter your password :");
 if (password == hidden_input('-'))
    {
     print("\n    Date : ",sysvar("Sys$Date"),".\n");
     print("    Account started ",starting_date,".\n");
     print("    ",owner,"'s balance is ",balance,".\n");
    } 
 else
  print("\nSorry! Wrong password.\n");
}

account::change_password()
{
 print("Please enter your old password :");
 if (password != hidden_input('-'))
    {
      print("\nSorry! Wrong password.\n");
      return nil;
    }
 print("Please enter your new password :");
 password = hidden_input('-');
}

account::has_owner(name)
{
 return (name == owner);
}
00000000  2f 2a 20 41 63 63 6f 75  6e 74 73 20 20 20 20 47  |/* Accounts    G|
00000010  43 57 20 20 20 20 30 32  2f 30 33 2f 39 34 20 20  |CW    02/03/94  |
00000020  2a 2f 0a 0a 63 6c 61 73  73 20 61 63 63 6f 75 6e  |*/..class accoun|
00000030  74 0a 7b 0a 20 62 61 6c  61 6e 63 65 3b 20 20 20  |t.{. balance;   |
00000040  20 20 20 20 20 2f 2a 20  41 6e 20 61 63 63 6f 75  |     /* An accou|
00000050  6e 74 27 73 20 73 74 61  74 65 20 2a 2f 0a 20 6f  |nt's state */. o|
00000060  77 6e 65 72 3b 0a 20 70  61 73 73 77 6f 72 64 3b  |wner;. password;|
00000070  0a 20 73 74 61 72 74 69  6e 67 5f 64 61 74 65 3b  |. starting_date;|
00000080  0a 0a 20 77 69 74 68 64  72 61 77 28 78 29 3b 20  |.. withdraw(x); |
00000090  20 20 2f 2a 20 41 6e 20  61 63 63 6f 75 6e 74 27  |  /* An account'|
000000a0  73 20 6d 65 74 68 6f 64  73 20 2a 2f 0a 20 73 74  |s methods */. st|
000000b0  61 74 65 6d 65 6e 74 28  29 3b 0a 20 63 68 61 6e  |atement();. chan|
000000c0  67 65 5f 70 61 73 73 77  6f 72 64 28 29 3b 0a 20  |ge_password();. |
000000d0  68 61 73 5f 6f 77 6e 65  72 28 6e 61 6d 65 29 3b  |has_owner(name);|
000000e0  0a 7d 20 20 20 20 0a 0a  61 63 63 6f 75 6e 74 3a  |.}    ..account:|
000000f0  3a 61 63 63 6f 75 6e 74  28 61 6d 6f 75 6e 74 2c  |:account(amount,|
00000100  6e 61 6d 65 29 0a 7b 0a  20 62 61 6c 61 6e 63 65  |name).{. balance|
00000110  20 3d 20 28 61 6d 6f 75  6e 74 3e 30 29 3f 61 6d  | = (amount>0)?am|
00000120  6f 75 6e 74 3a 30 3b 0a  20 6f 77 6e 65 72 20 3d  |ount:0;. owner =|
00000130  20 6e 61 6d 65 3b 0a 20  70 72 69 6e 74 28 22 45  | name;. print("E|
00000140  6e 74 65 72 20 22 2c 6e  61 6d 65 2c 22 27 73 20  |nter ",name,"'s |
00000150  70 61 73 73 77 6f 72 64  20 68 65 72 65 3a 20 22  |password here: "|
00000160  29 3b 0a 20 70 61 73 73  77 6f 72 64 20 3d 20 68  |);. password = h|
00000170  69 64 64 65 6e 5f 69 6e  70 75 74 28 27 2d 27 29  |idden_input('-')|
00000180  3b 0a 20 73 74 61 72 74  69 6e 67 5f 64 61 74 65  |;. starting_date|
00000190  20 3d 20 73 79 73 76 61  72 28 22 53 79 73 24 44  | = sysvar("Sys$D|
000001a0  61 74 65 22 29 3b 0a 20  72 65 74 75 72 6e 20 74  |ate");. return t|
000001b0  68 69 73 3b 0a 7d 0a 0a  61 63 63 6f 75 6e 74 3a  |his;.}..account:|
000001c0  3a 77 69 74 68 64 72 61  77 28 78 29 0a 7b 0a 20  |:withdraw(x).{. |
000001d0  6c 6f 63 61 6c 20 73 75  6d 3b 0a 20 70 72 69 6e  |local sum;. prin|
000001e0  74 28 22 50 6c 65 61 73  65 20 65 6e 74 65 72 20  |t("Please enter |
000001f0  79 6f 75 72 20 70 61 73  73 77 6f 72 64 20 3a 22  |your password :"|
00000200  29 3b 0a 20 69 66 20 28  70 61 73 73 77 6f 72 64  |);. if (password|
00000210  20 3d 3d 20 68 69 64 64  65 6e 5f 69 6e 70 75 74  | == hidden_input|
00000220  28 27 2d 27 29 29 0a 20  20 20 7b 0a 20 20 20 20  |('-')).   {.    |
00000230  73 75 6d 20 3d 20 28 78  20 3c 20 62 61 6c 61 6e  |sum = (x < balan|
00000240  63 65 29 3f 78 3a 62 61  6c 61 6e 63 65 3b 0a 20  |ce)?x:balance;. |
00000250  20 20 20 62 61 6c 61 6e  63 65 20 2d 3d 20 73 75  |   balance -= su|
00000260  6d 3b 0a 20 20 20 20 70  72 69 6e 74 28 22 5c 6e  |m;.    print("\n|
00000270  22 2c 6f 77 6e 65 72 2c  22 27 73 20 61 63 63 6f  |",owner,"'s acco|
00000280  75 6e 74 20 68 61 73 20  62 65 65 6e 20 64 65 62  |unt has been deb|
00000290  69 74 65 64 20 22 2c 73  75 6d 2c 22 2e 5c 6e 22  |ited ",sum,".\n"|
000002a0  29 3b 0a 20 20 20 7d 0a  20 65 6c 73 65 0a 20 20  |);.   }. else.  |
000002b0  7b 0a 20 20 20 73 75 6d  20 3d 20 30 3b 0a 20 20  |{.   sum = 0;.  |
000002c0  20 70 72 69 6e 74 28 22  5c 6e 53 6f 72 72 79 21  | print("\nSorry!|
000002d0  20 57 72 6f 6e 67 20 70  61 73 73 77 6f 72 64 2e  | Wrong password.|
000002e0  5c 6e 22 29 3b 0a 20 20  7d 0a 20 72 65 74 75 72  |\n");.  }. retur|
000002f0  6e 20 73 75 6d 3b 0a 7d  0a 0a 61 63 63 6f 75 6e  |n sum;.}..accoun|
00000300  74 3a 3a 73 74 61 74 65  6d 65 6e 74 28 29 0a 7b  |t::statement().{|
00000310  0a 20 70 72 69 6e 74 28  22 50 6c 65 61 73 65 20  |. print("Please |
00000320  65 6e 74 65 72 20 79 6f  75 72 20 70 61 73 73 77  |enter your passw|
00000330  6f 72 64 20 3a 22 29 3b  0a 20 69 66 20 28 70 61  |ord :");. if (pa|
00000340  73 73 77 6f 72 64 20 3d  3d 20 68 69 64 64 65 6e  |ssword == hidden|
00000350  5f 69 6e 70 75 74 28 27  2d 27 29 29 0a 20 20 20  |_input('-')).   |
00000360  20 7b 0a 20 20 20 20 20  70 72 69 6e 74 28 22 5c  | {.     print("\|
00000370  6e 20 20 20 20 44 61 74  65 20 3a 20 22 2c 73 79  |n    Date : ",sy|
00000380  73 76 61 72 28 22 53 79  73 24 44 61 74 65 22 29  |svar("Sys$Date")|
00000390  2c 22 2e 5c 6e 22 29 3b  0a 20 20 20 20 20 70 72  |,".\n");.     pr|
000003a0  69 6e 74 28 22 20 20 20  20 41 63 63 6f 75 6e 74  |int("    Account|
000003b0  20 73 74 61 72 74 65 64  20 22 2c 73 74 61 72 74  | started ",start|
000003c0  69 6e 67 5f 64 61 74 65  2c 22 2e 5c 6e 22 29 3b  |ing_date,".\n");|
000003d0  0a 20 20 20 20 20 70 72  69 6e 74 28 22 20 20 20  |.     print("   |
000003e0  20 22 2c 6f 77 6e 65 72  2c 22 27 73 20 62 61 6c  | ",owner,"'s bal|
000003f0  61 6e 63 65 20 69 73 20  22 2c 62 61 6c 61 6e 63  |ance is ",balanc|
00000400  65 2c 22 2e 5c 6e 22 29  3b 0a 20 20 20 20 7d 20  |e,".\n");.    } |
00000410  0a 20 65 6c 73 65 0a 20  20 70 72 69 6e 74 28 22  |. else.  print("|
00000420  5c 6e 53 6f 72 72 79 21  20 57 72 6f 6e 67 20 70  |\nSorry! Wrong p|
00000430  61 73 73 77 6f 72 64 2e  5c 6e 22 29 3b 0a 7d 0a  |assword.\n");.}.|
00000440  0a 61 63 63 6f 75 6e 74  3a 3a 63 68 61 6e 67 65  |.account::change|
00000450  5f 70 61 73 73 77 6f 72  64 28 29 0a 7b 0a 20 70  |_password().{. p|
00000460  72 69 6e 74 28 22 50 6c  65 61 73 65 20 65 6e 74  |rint("Please ent|
00000470  65 72 20 79 6f 75 72 20  6f 6c 64 20 70 61 73 73  |er your old pass|
00000480  77 6f 72 64 20 3a 22 29  3b 0a 20 69 66 20 28 70  |word :");. if (p|
00000490  61 73 73 77 6f 72 64 20  21 3d 20 68 69 64 64 65  |assword != hidde|
000004a0  6e 5f 69 6e 70 75 74 28  27 2d 27 29 29 0a 20 20  |n_input('-')).  |
000004b0  20 20 7b 0a 20 20 20 20  20 20 70 72 69 6e 74 28  |  {.      print(|
000004c0  22 5c 6e 53 6f 72 72 79  21 20 57 72 6f 6e 67 20  |"\nSorry! Wrong |
000004d0  70 61 73 73 77 6f 72 64  2e 5c 6e 22 29 3b 0a 20  |password.\n");. |
000004e0  20 20 20 20 20 72 65 74  75 72 6e 20 6e 69 6c 3b  |     return nil;|
000004f0  0a 20 20 20 20 7d 0a 20  70 72 69 6e 74 28 22 50  |.    }. print("P|
00000500  6c 65 61 73 65 20 65 6e  74 65 72 20 79 6f 75 72  |lease enter your|
00000510  20 6e 65 77 20 70 61 73  73 77 6f 72 64 20 3a 22  | new password :"|
00000520  29 3b 0a 20 70 61 73 73  77 6f 72 64 20 3d 20 68  |);. password = h|
00000530  69 64 64 65 6e 5f 69 6e  70 75 74 28 27 2d 27 29  |idden_input('-')|
00000540  3b 0a 7d 0a 0a 61 63 63  6f 75 6e 74 3a 3a 68 61  |;.}..account::ha|
00000550  73 5f 6f 77 6e 65 72 28  6e 61 6d 65 29 0a 7b 0a  |s_owner(name).{.|
00000560  20 72 65 74 75 72 6e 20  28 6e 61 6d 65 20 3d 3d  | return (name ==|
00000570  20 6f 77 6e 65 72 29 3b  0a 7d 0a                 | owner);.}.|
0000057b