Bank.h
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
源码类别:

.net编程

开发平台:

Visual C++

  1. #pragma once
  2. #include "Account.h"
  3. #using <mscorlib.dll>
  4. using namespace System::Collections;
  5. __gc class Bank
  6. {
  7. public:
  8.     Bank(void);
  9. private:
  10.     ArrayList* accts;
  11. public:
  12.     bool Add(Account* pAcc)
  13.     {
  14.         // check if account is in list
  15.         if (accts->Contains(pAcc))
  16.             return false;
  17.         else
  18.             accts->Add(pAcc);
  19.         return true;
  20.     }
  21.     bool Remove(Account* pAcc)
  22.     {
  23.         // check if account is in list
  24.         if (accts->Contains(pAcc))
  25.         {
  26.             accts->Remove(pAcc);
  27.             return true;
  28.         }
  29.         else
  30.             return false;
  31.     }
  32.     __property Account* get_Acct(long number)
  33.     {
  34.         IEnumerator* ie = accts->GetEnumerator();
  35.         while (ie->MoveNext())
  36.         {
  37.             Account* pa = dynamic_cast<Account*>(ie->get_Current());
  38.             if (pa->AccountNumber == number)
  39.                 return pa;
  40.         }
  41.         throw new ArgumentOutOfRangeException("Bad account number");
  42.     }
  43. };