本文整理汇总了C++中Stock类的典型用法代码示例。如果您正苦于以下问题:C++ Stock类的具体用法?C++ Stock怎么用?C++ Stock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
using std::cout;
using std::ios_base;
// create an array of initialized objects
Stock stocks[STKS] = {
Stock("NanoSmart", 12, 20.0),
Stock("Boffo Objects", 200, 2.0),
Stock("Monolithic Obelisks", 130, 3.25),
Stock("Fleep Enterprises", 60, 6.5)
};
cout.precision(2); // #.## format
cout.setf(ios_base::fixed, ios_base::floatfield);// #.## format
cout.setf(ios_base::showpoint); // #.## format
cout << "Stock holdings:\n";
int st;
for (st = 0; st < STKS; st++)
stocks[st].show();
Stock top = stocks[0];
for (st = 1; st < STKS; st++)
top = top.topval(stocks[st]);
cout << "\nMost valuable holding:\n";
top.show();
return 0;
}
示例2: command
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;
}
示例3: return
template <class numericType> numericType calculatePERatio<numericType>::operator() (const Stock<numericType>& stock) {
if ((stock.getTickerPrice() == 0) || (stock.getLastDividend() == 0)) {
return (numericType)0;
}
return (numericType)(stock.getTickerPrice()/stock.getLastDividend());
}
示例4: Stock
Stock* Stock::create(int stockCode, String* stockName,int nowPrice,int makedealprice,float percent,int storeNumber )
{
Stock* stock = new Stock(stockCode,stockName,nowPrice,makedealprice,percent,storeNumber);
stock->init();
stock->autorelease();
return stock;
}
示例5: moveTest
static void moveTest(){
ostringstream oss;
Stock stock = Stock();
Draw draw = Draw();
int size;
try {
draw.move(stock, size = 26);
assert(stock.getSize() == 26);
draw.move(stock, size = 5);
} catch(std::logic_error & e){
oss << "Failure while trying to take " << size << " cards!";
}
assert(oss.str() == "Failure while trying to take 5 cards!");
oss.str("");
oss.clear();
Build build = Build();
stock += 3;
try {
stock.move(build);
assert(false);
}
catch(std::exception & e){
oss << e.what();
}
assert(oss.str() == "Can't add card - not in sequence!\n");
}
示例6: market_code
HKU_API std::ostream & operator<<(std::ostream& os, const TradeRecord& record) {
Stock stock = record.stock;
string market_code(""), name("");
if(!stock.isNull()){
market_code = stock.market_code();
#if defined(BOOST_WINDOWS) && (PY_VERSION_HEX >= 0x03000000)
name = utf8_to_gb(stock.name());
#else
name = stock.name();
#endif
}
string strip(", ");
os << std::fixed;
os.precision(4);
os << "Trade(" << record.datetime << strip << market_code
<< strip << name << strip << getBusinessName(record.business)
<< strip << record.planPrice << strip << record.realPrice;
if (record.goalPrice == Null<price_t>()) {
os << strip << "NULL";
} else {
os << strip << record.goalPrice;
}
os << strip << record.number << strip << record.cost.commission
<< strip << record.cost.stamptax << strip << record.cost.transferfee
<< strip << record.cost.others << strip << record.cost.total
<< strip << record.stoploss << strip << record.cash
<< strip << getSystemPartName(record.from) << ")";
os.unsetf(std::ostream::floatfield);
os.precision();
return os;
}
示例7: main
int main(void)
{
using std::cout;
using std::ios_base;
Stock stocks[STKS] = {
Stock("NanoSmart", 12, 20.0),
Stock("Boffo Objects", 200, 2.0),
Stock("Obelisk blue", 130, 3.2),
Stock("Fleep Enterprise", 60, 6.5)
};
cout.precision(2); // *.** format
cout.setf(ios_base::fixed, ios_base::floatfield);// *.** format
cout.setf(ios_base::showpoint);
cout << "Stock holdings:\n";
int st;
for (st = 0; st < STKS; st++)
stocks[st].show();
Stock top = stocks[0];
for (st = 1; st < STKS; st++)
top = top.topval(stocks[st]);
cout << "\nMost valuable holding:\n";
top.show();
return 0;
}
示例8: SetStockImgType
void SetStockImgType::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Stock* stock = objects->getObjectT<Stock>(m_stockId);
// Push another SetStockImgType as redoer
redoers->pushUndoer(new SetStockImgType(objects, stock));
stock->setImgType(m_imgtype);
}
示例9: SetStockPixelFormat
void SetStockPixelFormat::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Stock* stock = objects->getObjectT<Stock>(m_stockId);
// Push another SetStockPixelFormat as redoer
redoers->pushUndoer(new SetStockPixelFormat(objects, stock));
stock->setPixelFormat(static_cast<PixelFormat>(m_format));
}
示例10: revert
void RemoveImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Stock* stock = objects->getObjectT<Stock>(m_stockId);
Image* image = read_object<Image>(objects, m_stream, raster::read_image);
// Push an AddImage as redoer
redoers->pushUndoer(new AddImage(objects, stock, m_imageIndex));
stock->replaceImage(m_imageIndex, image);
}
示例11: getTradingCalendar
DatetimeList StockManager::
getTradingCalendar(const KQuery& query, const string& market) {
Stock stock = getStock("SH000001");
size_t start_ix = 0, end_ix = 0;
DatetimeList result;
if (stock.getIndexRange(query, start_ix, end_ix)) {
result = stock.getDatetimeList(start_ix, end_ix, query.kType());
}
return result;
}
示例12: opsTest
static void opsTest() {
Stock s = Stock();
vector<int> list;
ostringstream oss;
for(int i = 1; i < 13; i++){
list.push_back(i);
}
int num = 1;
try {
s += list; num++;
s += list; num++;
s += list; num++; //this num++ should not be executed
}
catch (std::invalid_argument & e){
oss << "Failed at num = " << num;
}
assert(oss.str() == "Failed at num = 3");
oss.str("");
oss.clear();
//assert Stock pile has 24 cards now
assert(s.getSize() == 24);
try {
s += 13;
}
catch (std::invalid_argument & e){
oss << e.what();
}
//assert exception is caught
assert(oss.str() == "Invalid card value.\n");
oss.str("");
oss.clear();
vector<int> list2 = {5, 3, 2, 1, 0, 1};
try{
s += list2;
} catch(std::invalid_argument & e){
assert(false); //should not be executed
}
assert(s.getSize() == 30);
try {
s += 1;
}catch(std::logic_error & e){
oss << e.what();
}
assert(oss.str() == "Can't have more than 30 cards in Stock pile!\n");
}
示例13: revert
void AddImage::revert(ObjectsContainer* objects, UndoersCollector* redoers)
{
Stock* stock = objects->getObjectT<Stock>(m_stockId);
Image* image = stock->getImage(m_imageIndex);
if (image == NULL)
throw UndoException("One image was not found in the stock");
redoers->pushUndoer(new RemoveImage(objects, stock, m_imageIndex));
stock->removeImage(image);
delete image;
}
示例14: switch
double StockUtil::DividendYield(Stock stock, double marketPrice)
{
if(marketPrice == 0.0){return 0;}
switch(stock.getStockType() )
{
case COMMON:
return (stock.getLastDividend() / marketPrice);
case PREFFERED:
return (stock.getFixedDividend() * stock.getParValue())/ marketPrice;
default:
return 0;
}
}
示例15:
bool Stock::operator!=(const Stock& stock) const {
if (this == &stock)
return false;
if (m_data == stock.m_data)
return false;
if (!m_data || !stock.m_data)
return true;
if( m_data->m_code != stock.code() || m_data->m_market != stock.market())
return true;
return false;
}