本文整理汇总了C++中Transaction::GetDate方法的典型用法代码示例。如果您正苦于以下问题:C++ Transaction::GetDate方法的具体用法?C++ Transaction::GetDate怎么用?C++ Transaction::GetDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::GetDate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Builds transaction history
vector <Page> UI::BuildTransactionHistory(stack<Transaction> *listOfTransactions)
{
// Prepare a vector which stores the lines
// to be written to the page which is currently
// "in progress"
vector <string> linesToPage;
// This vector is what is built over the course
// of the function and eventually returned.
vector <Page> transactionHistory;
// While their are still lines "waiting to be written" on the stack, loop.
while (listOfTransactions->size() > 0)
{
/******************************************************************************
*The following code is all about getting the format correct for each line.
******************************************************************************/
// We want to work with the transaction on the top of the stack.
Transaction workingTransaction = listOfTransactions->top();
// Get the length of the transactionNumber (it could be a single digit, two digits,
// three digits, etc.)
int sizeOfTransactionNumber = std::to_string(workingTransaction.GetTransactionNumber()).length();
string transactionNumColumnPadding = ""; // string variable to store the "padding"
// Build a string comprised of spaces. The number of spaces is determined by the
// difference between the "length" of the transaction number (in digits) and the number
// 6. Why 6? Because it looks nice.
for (sizeOfTransactionNumber; sizeOfTransactionNumber < 6; sizeOfTransactionNumber++)
{
transactionNumColumnPadding += " ";
}
// Format the transactionAmount. It's currency, so we only want
// two places after the decimal.
string retTransAmt = std::to_string(workingTransaction.GetTransactionAmount()); // Turn it into a string
size_t dotIndex = retTransAmt.find("."); // Find out where the "." is
retTransAmt = retTransAmt.substr(0, dotIndex + 3); // Trim the string
int sizeOfTransactionAmt = retTransAmt.length(); // Get the length of the string
string transactionAmtColumnPadding = ""; // string variable to store the padding.
// Build a string comprised of spaces in the same we as we did for the transactionNumber
// column above.
for (sizeOfTransactionAmt; sizeOfTransactionAmt < 10; sizeOfTransactionAmt++)
{
transactionAmtColumnPadding += " ";
}
// Build the line by concatenating the various strings created so far.
string additionalLine = "\t " + std::to_string(workingTransaction.GetTransactionNumber()) +
transactionNumColumnPadding + " | $" +
transactionAmtColumnPadding +
retTransAmt + " | " +
workingTransaction.GetTransactionType() + " | " +
workingTransaction.GetDate();
// Add the completed line to the vector representing the
// collection of lines on the page.
linesToPage.push_back(additionalLine);
// Reduce the size of the stack by one
listOfTransactions->pop();
}
// This variable stores the number of lines (transactions)
// which have been written.
unsigned int numberOfLinesWritten = 0;
// As long as there are still lines that need to be written, loop
while (numberOfLinesWritten < linesToPage.size())
{
// Create a new page with room for 10 total lines.
Page page;
// While there is still room to write on the page, add an additional line from the vector
// made above. Be sure to increment the numberOfLinesWritten as we add to each page.
for (unsigned int i = 0; i < page.GetMaximumNumberOfLines() && numberOfLinesWritten < linesToPage.size(); i++, numberOfLinesWritten++)
{
page.AddLine(linesToPage[numberOfLinesWritten]);
}
// Once the maximum number of lines has been reached for the page, add the page to the
// transactionHistory vector.
transactionHistory.push_back(page);
}
// Return the newly-made transactionHistory
return transactionHistory;
}