当前位置: 首页>>代码示例>>C++>>正文


C++ Transaction::amount方法代码示例

本文整理汇总了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();
}
开发者ID:iainhemstock,项目名称:Katas,代码行数:12,代码来源:StatementPrinter.cpp

示例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;
}
开发者ID:jschueths,项目名称:p_thread-practice,代码行数:84,代码来源:thread_practice.cpp


注:本文中的Transaction::amount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。