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

.net编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "CreditCardAccount.h"
  3. #using <mscorlib.dll>
  4. using namespace System;
  5. int CreditCardAccount::numberOfAccounts = 0;
  6. CreditCardAccount::CreditCardAccount(long number, double limit)
  7. {
  8.     accountNumber = number;
  9.     creditLimit = limit;
  10.     currentBalance = 0.0;
  11.     
  12. ptrLoyaltyScheme = 0;
  13.     numberOfAccounts++;
  14.     Console::Write("Number of accounts created: ");
  15.     Console::WriteLine(numberOfAccounts);
  16. }
  17. CreditCardAccount::~CreditCardAccount()
  18. {
  19.     Console::Write("Account being destroyed: ");
  20.     Console::WriteLine(accountNumber);
  21.     Console::Write("Closing balance: ");
  22.     Console::WriteLine(currentBalance);
  23. delete ptrLoyaltyScheme;
  24. }
  25. bool CreditCardAccount::MakePurchase(double amount)
  26. {
  27.     if (currentBalance + amount > creditLimit)
  28.     {
  29.         return false;
  30.     }
  31.     else
  32.     {
  33.         currentBalance += amount;
  34.         if (currentBalance >= creditLimit / 2)
  35.         {
  36.             if (ptrLoyaltyScheme == 0)
  37.             {
  38.                 ptrLoyaltyScheme = new LoyaltyScheme();
  39.             }
  40. else
  41. {
  42. ptrLoyaltyScheme->EarnPointsOnAmount(amount);
  43. }
  44.         }
  45.         return true;
  46.     }
  47. }
  48. void CreditCardAccount::MakeRepayment(double amount)
  49. {
  50. currentBalance -= amount;
  51. }
  52. void CreditCardAccount::PrintStatement() 
  53. {
  54. Console::Write("Account number: ");
  55. Console::WriteLine(accountNumber);
  56. Console::Write("Current balance: ");
  57. Console::WriteLine(currentBalance);
  58. }
  59. int CreditCardAccount::GetNumberOfAccounts()
  60. {
  61.     return numberOfAccounts;
  62. }
  63. void CreditCardAccount::RedeemLoyaltyPoints()
  64. {
  65. if (ptrLoyaltyScheme == 0)
  66. {
  67. Console::WriteLine("Sorry, you do not have a loyalty scheme yet");
  68. }
  69. else
  70. {
  71. Console::Write("Points available: ");
  72. Console::Write( ptrLoyaltyScheme->GetPoints() );
  73.         Console::Write(". How many points do you want to redeem? ");
  74. String * input = Console::ReadLine();
  75. int points = input->ToInt32(0);
  76. ptrLoyaltyScheme->RedeemPoints(points);
  77. Console::Write("Points remaining: ");
  78. Console::WriteLine( ptrLoyaltyScheme->GetPoints() );
  79. }
  80. }