本文整理汇总了C++中Stock::setPrice方法的典型用法代码示例。如果您正苦于以下问题:C++ Stock::setPrice方法的具体用法?C++ Stock::setPrice怎么用?C++ Stock::setPrice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stock
的用法示例。
在下文中一共展示了Stock::setPrice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getStock
Stock PgsqlDataProvider::getStock(uint32_t id)
{
nontransaction command(*conn);
string query = "SELECT id, price FROM get_stock(" + to_string(id) + ");";
result queryResult(command.exec(query));
if (verbose)
cout << "Result of " << query << ": " << endl;
if (queryResult.size() != 1)
{
cerr << "getStock: Incorrect number of results: " << queryResult.size() << endl;
throw invalid_argument("getStock: Incorrect number of results.");
}
if (queryResult[0][0].is_null())
{
cerr << "getStock: Stock id = " << id << " does not exist." << endl;
throw invalid_argument("getStock: Stock does not exist.");
}
Stock stock;
stock.setId(queryResult[0][0].as<int>());
stock.setPrice(Decimal(queryResult[0][1].as<string>()));
if (verbose)
cout << "Stock: id = " << stock.getId() << ", price = " << stock.getPrice() << endl;
return stock;
}
示例2: stocksBuySell
//.........这里部分代码省略.........
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
bStock.setAmount(amount);
bStock.setPrice(price);
//we did buy stock
buy = true;
//add to the bought stock queue
bStocks.push(bStock);
}
else if (command == "sell")
{
//get sell amount and price from user
cin >> sAmount >> sPrice;
//add to sell total
sTotal += (sPrice * sAmount);
//amount and price of current sold stock transaction
sStock.setAmount(sAmount);
sStock.setPrice(sPrice);
//we did sell stock
sell = true;
//add sold stock to queue
sStocks.push(sStock);
//to allow us to go into the loop to find total sold stocks
int tmp = 1;
// should to handle the selling of stocks
for (; tmp != 0;)
{
//if there are no more bought stocks left leave
if (bStocks.empty())
break;
bStock = bStocks.front();
tmp = (sStock.getAmount() - bStock.getAmount());
Dollars tmpD = sStock.getPrice() - bStock.getPrice();
//if we didn't finish selling one bought transaction
//we save that number into bought stock
if (tmp < 0)
{
tmp *= -1;
bStock.setAmount(tmp);
bStocks.front() = bStock;
tmp = 0;
}
else if (tmp > 0)
{
bStocks.pop();
}
Dollars Profit = tmpD * bStock.getAmount();
profit.push(Profit);
}
//while (tmp == 0);
}
示例3: SetStockPricesEqual
void SetStockPricesEqual( Stock & s1, Stock & s2 )
{
s1.setPrice( s2.getPrice() );
}