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


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

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:drrezeau,项目名称:School-Projects,代码行数:101,代码来源:stock.cpp


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