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


C++ Stock::setPrice方法代码示例

本文整理汇总了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;
}
开发者ID:junajan,项目名称:nodejs-stock,代码行数:29,代码来源:PgsqlDataProvider.cpp

示例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);
      }
开发者ID:drrezeau,项目名称:School-Projects,代码行数:101,代码来源:stock.cpp

示例3: SetStockPricesEqual

void SetStockPricesEqual( Stock & s1, Stock & s2 )
{	
	s1.setPrice( s2.getPrice() );
}
开发者ID:SighPhy,项目名称:ClassWork,代码行数:4,代码来源:Debug_15_12_Lucas_Jones.cpp


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