bundle.cpp.html

来自「《Big C++ 》Third Edition电子书和代码全集-Part1」· HTML 代码 · 共 45 行

HTML
45
字号
<html>

<head>
	<title>bundle.cpp</title>
</head>

<body>
<pre>  1  #include "bundle.h"
  2  
  3  void Bundle::add(Item* it)
  4  {
  5     items.push_back(it);
  6  }
  7  
  8  double Bundle::get_unit_price() const
  9  {
 10     double price = 0;
 11     for (int i = 0; i &lt; items.size(); i++)
 12     {
 13        price = price
 14           + items[i]-&gt;get_unit_price() * items[i]-&gt;get_quantity();
 15     }
 16     return price;
 17  }
 18  
 19  string Bundle::get_description() const
 20  {
 21     string description = "";
 22     for (int i = 0; i &lt; items.size(); i++)
 23     {
 24        if (i &gt; 0) description = description + ", ";
 25        description = description + items[i]-&gt;get_description();
 26     }
 27     return description;
 28  }
 29  
 30  int Bundle::get_quantity() const
 31  {
 32     return 1;
 33  }
 34  
 35  </pre>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?