本文整理汇总了C++中Stock::getAmount方法的典型用法代码示例。如果您正苦于以下问题:C++ Stock::getAmount方法的具体用法?C++ Stock::getAmount怎么用?C++ Stock::getAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock::getAmount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stocksBuySell
/************************************************
* STOCKS BUY SELL
* The interactive function allowing the user to
* buy and sell stocks
***********************************************/
void stocksBuySell()
{
// instructions
cout << "This program will allow you to buy and sell stocks. "
<< "The actions are:\n";
cout << " buy 200 $1.57 - Buy 200 shares at $1.57\n";
cout << " sell 150 $2.15 - Sell 150 shares at $2.15\n";
cout << " display - Display your current stock portfolio\n";
cout << " quit - Display a final report and quit the program\n";
// your code here...
string command; //check the command
int amount = 0; //bought stock amount
Dollars price; //bought stock price
int sAmount = 0;//sold stock price
Dollars sPrice; //sold stock price
Dollars total; //bought stock total
Dollars sTotal; //sold stock total
Stock bStock; //one element of the bought stocks
Stock sStock; //one element of the sold stocks
//the check if we have bought or sold at all
bool buy = false;
bool sell = false;
Queue <Stock> bStocks; //one queue for bought stocks
Queue <Stock> sStocks; //one queue for sold stocks
Queue <Dollars> profit; //one queue for profits
do
{
//create a copy for bought stocks
Queue <Stock> stocks1(bStocks);
//create a copy for sold stocks
Queue <Stock> stocks2(sStocks);
cout << "> ";
cin >> command;
if (command == "quit" || command == "display")
{
if (buy && sell)
{
int i;
int j;
cout << "Currently held:\n";
for (i = 0; !stocks1.empty(); i++)
{
bStock = stocks1.front();
cout << "\tBought "
<< bStock.getAmount() << " shares at "
<< bStock.getPrice() << endl;
stocks1.pop();
}
cout << "Sell History:\n";
for (j = 0; !stocks2.empty(); j++)
{
sStock = stocks2.front();
cout << "\tSold "
<< sStock.getAmount() << " shares at "
<< sStock.getPrice() << " for a profit of ";
cout << (sTotal - total) << endl;
stocks2.pop();
}
}
else if(buy)
{
int i;
cout << "Currently held:\n";
for (i = 0; !stocks1.empty(); i++)
{
bStock = stocks1.front();
cout << "\tBought " << bStock.getAmount() << " shares at "
<< bStock.getPrice() << endl;
stocks1.pop();
}
}
else if(sell)
sStock = stocks2.front();
cout << "\nProceeds: " << (sTotal - total) << endl;
}
else if (command == "buy")
{
//get bought amount and price from user
cin >> amount >> price;
//add to bought total
total += (price * amount);
//amount and price of current bought stock transaction
//.........这里部分代码省略.........