本文整理汇总了C++中Transaction::amount方法的典型用法代码示例。如果您正苦于以下问题:C++ Transaction::amount方法的具体用法?C++ Transaction::amount怎么用?C++ Transaction::amount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::amount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
const std::string
StatementPrinter::generateStatementLine(const Transaction& transaction)
{
std::stringstream ss;
ss << transaction.date()
<< " | "
<< transaction.amount() << ".00"
<< " | "
<< this->runningBalance << ".00";
return ss.str();
}
示例2: processTransactions
void processTransactions(const std::string& name, std::ifstream& in) {
Transaction t;
while(in >> t) {
if(t.operation() == Operation::Deposit) {
// Deposit routine.
if(t.account() == AccountType::Checking) {
std::lock_guard l(checkingLock);
checking += t.amount();
std::cout << name << " deposited $" << t.amount() << ". New "
<< t.account() << " balance: $" << checking << std::endl;
} else if(t.account() == AccountType::Savings) {
std::lock_guard l(savingsLock);
savings += t.amount();
std::cout << name << " deposited $" << t.amount() << ". New "
<< t.account() << " balance: $" << savings << std::endl;
}
} else if(t.operation() == Operation::Withdrawal) {
// Withdraw routine.
// Lock whichever account is being accessed.
if(t.account() == AccountType::Checking) {
std::lock_guard l(checkingLock);
if(t.amount() > checking) {
// Lock both accounts if transfering.
std::lock_guard transferL(transferLock);
std::lock_guard savingsL(savingsLock);
if(savings > 0) {
savings += checking;
checking = 0;
savings -= t.amount();
std::cout << name << " withdrew $" << t.amount() << "." << std::endl;
printBalances();
} else {
std::cout << name << " cannot withdraw $" << t.amount()
<< ". Insufficient funds." << std::endl;
}
} else {
checking -= t.amount();
std::cout << name << " withdrew $" << t.amount() << ". New "
<< t.account() << " balance: $" << checking << std::endl;
}
} else if(t.account() == AccountType::Savings) {
std::lock_guard l(savingsLock);
if(savings > 0) {
savings -= t.amount();
std::cout << name << " withdrew $" << t.amount() << ". New"
<< t.account() << " balance: $" << savings << std::endl;
} else {
std::cout << name << " cannot withdraw $" << t.amount()
<< ". Insufficient funds." << std::endl;
}
}
} else if(t.operation() == Operation::Transfer) {
// Transfer routine.
// Lock both accounts when transfering.
std::lock_guard tLock(transferLock);
std::lock_guard cLock(checkingLock);
std::lock_guard sLock(savingsLock);
if(t.account() == AccountType::Checking) {
if(savings > 0) {
checking += t.amount();
savings -= t.amount();
std::cout << name << " transferred $" << t.amount()
<< " from savings to checking." << std::endl;
printBalances();
} else {
std::cout << name << " cannot transfer $" << t.amount()
<< ". Insufficient funds." << std::endl;
}
} else if(t.account() == AccountType::Savings) {
if(checking > 0) {
checking -= t.amount();
savings += t.amount();
std::cout << name << " transferred $" << t.amount()
<< " from checking to savings." << std::endl;
printBalances();
} else {
std::cout << name << " cannot transfer $" << t.amount()
<< ". Insufficient funds." << std::endl;
}
}
}
}
return;
}