CreditCardAccount.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:2k
- #include "stdafx.h"
- #include "CreditCardAccount.h"
- #using <mscorlib.dll>
- using namespace System;
- int CreditCardAccount::numberOfAccounts = 0;
- CreditCardAccount::CreditCardAccount(long number, double limit)
- {
- accountNumber = number;
- creditLimit = limit;
- currentBalance = 0.0;
-
- ptrLoyaltyScheme = 0;
- numberOfAccounts++;
- Console::Write("Number of accounts created: ");
- Console::WriteLine(numberOfAccounts);
- }
- CreditCardAccount::~CreditCardAccount()
- {
- Console::Write("Account being destroyed: ");
- Console::WriteLine(accountNumber);
- Console::Write("Closing balance: ");
- Console::WriteLine(currentBalance);
- delete ptrLoyaltyScheme;
- }
- bool CreditCardAccount::MakePurchase(double amount)
- {
- if (currentBalance + amount > creditLimit)
- {
- return false;
- }
- else
- {
- currentBalance += amount;
- if (currentBalance >= creditLimit / 2)
- {
- if (ptrLoyaltyScheme == 0)
- {
- ptrLoyaltyScheme = new LoyaltyScheme();
- }
- else
- {
- ptrLoyaltyScheme->EarnPointsOnAmount(amount);
- }
- }
- return true;
- }
- }
- void CreditCardAccount::MakeRepayment(double amount)
- {
- currentBalance -= amount;
- }
- void CreditCardAccount::PrintStatement()
- {
- Console::Write("Account number: ");
- Console::WriteLine(accountNumber);
- Console::Write("Current balance: ");
- Console::WriteLine(currentBalance);
- }
- int CreditCardAccount::GetNumberOfAccounts()
- {
- return numberOfAccounts;
- }
- void CreditCardAccount::RedeemLoyaltyPoints()
- {
- if (ptrLoyaltyScheme == 0)
- {
- Console::WriteLine("Sorry, you do not have a loyalty scheme yet");
- }
- else
- {
- Console::Write("Points available: ");
- Console::Write( ptrLoyaltyScheme->GetPoints() );
- Console::Write(". How many points do you want to redeem? ");
- String * input = Console::ReadLine();
- int points = input->ToInt32(0);
- ptrLoyaltyScheme->RedeemPoints(points);
-
- Console::Write("Points remaining: ");
- Console::WriteLine( ptrLoyaltyScheme->GetPoints() );
- }
- }