扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:谢启东编译 来源:天极开发 2007年11月12日
关键字:
using namespace System; public ref class Withdrawal sealed : Transaction { Decimal amount; int fromAccount; public: Withdrawal(double amount, int fromAccount) : Transaction(TransactionType::Withdrawal) { WithdrawalAmount = Decimal(amount); WithdrawalFromAccount = fromAccount; } Withdrawal(Decimal amount, int fromAccount) : Transaction(TransactionType::Withdrawal) { WithdrawalAmount = amount; WithdrawalFromAccount = fromAccount; } property Decimal WithdrawalAmount { Decimal get() { return amount; }; private: void set(Decimal value) { amount = value; }; } property int WithdrawalFromAccount { int get() { return fromAccount; }; private: void set(int value) { fromAccount = value; }; } void PostTransaction() { Console::WriteLine("{0} -- {1}", DateTimeOfTransaction, this); } virtual String^ ToString() override { return String::Format("With: {0,10:0.00} {1,10}", WithdrawalAmount, WithdrawalFromAccount); } }; |
using namespace System; public ref class Transfer sealed : Transaction { Decimal amount; int fromAccount; int toAccount; public: Transfer(double amount, int fromAccount, int toAccount): Transaction(TransactionType::Transfer) { TransferAmount = Decimal(amount); TransferFromAccount = fromAccount; TransferToAccount = toAccount; } Transfer(Decimal amount, int fromAccount, int toAccount): Transaction(TransactionType::Transfer) { TransferAmount = amount; TransferFromAccount = fromAccount; TransferToAccount = toAccount; } property Decimal TransferAmount { Decimal get() { return amount; }; private: void set(Decimal value) { amount = value; }; } property int TransferFromAccount { int get() { return fromAccount; }; private: void set(int value) { fromAccount = value; }; } property int TransferToAccount { int get() { return toAccount; }; private: void set(int value) { toAccount = value; }; } void Transfer::PostTransaction() { Console::WriteLine("{0} -- {1}", DateTimeOfTransaction, this); } virtual String^ ToString() override { return String::Format("Xfer: {0,10:0.00} {1,10} {2,10}", TransferAmount, TransferToAccount, TransferFromAccount); } }; |
using namespace System; int main() { array<Transaction^>^ list = gcnew array<Transaction^> { gcnew Deposit(123.05, 12345), gcnew Transfer(Decimal::Parse("1256.40"), 1111, 222), gcnew Withdrawal(34.54, 232323), gcnew Deposit(56.12, 14321) }; for each (Transaction^ t in list) { t->PostTransaction(); } } |
3/20/2005 12:36:16 AM -- Dep: 123.05 12345 3/20/2005 12:36:18 AM -- Xfer: 1256.40 222 1111 3/20/2005 12:36:19 AM -- With: 34.54 232323 3/20/2005 12:36:21 AM -- Dep: 56.12 14321 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者