⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleinvoiceprinter.cpp.html

📁 《Big C++ 》Third Edition电子书和代码全集-Part1
💻 HTML
字号:
<html>

<head>
	<title>simpleinvoiceprinter.cpp</title>
</head>

<body>
<pre>  1  #include &lt;iostream&gt;
  2  #include &lt;iomanip&gt;
  3  
  4  using namespace std;
  5  
  6  #include "simpleinvoiceprinter.h"
  7  
  8  SimpleInvoicePrinter::SimpleInvoicePrinter(vector&lt;int&gt; widths)
  9  {
 10     column_widths = widths;
 11     column = 0;
 12  }
 13  
 14  void SimpleInvoicePrinter::print_header(string s)
 15  {
 16     int width = 0;
 17     for (int i = 0; i &lt; column_widths.size(); i++)
 18        width = width + column_widths[i];
 19     for (int j = 0; j &lt; (width - s.length()) / 2; j++)
 20        cout &lt;&lt; " ";
 21     cout &lt;&lt; s &lt;&lt; "\n\n";
 22  }
 23  
 24  void SimpleInvoicePrinter::next_column()
 25  {
 26     column++;
 27     if (column == column_widths.size())
 28     {
 29        cout &lt;&lt; "\n";
 30        column = 0;
 31     }
 32  }
 33  
 34  void SimpleInvoicePrinter::print_string(string value, bool pad_right)
 35  {
 36     if (pad_right) cout &lt;&lt; value;
 37     <font color='#0000cc'>// print padding</font>
 38     for (int i = value.length(); i &lt; column_widths[column]; i++)
 39        cout &lt;&lt; " ";
 40     if (!pad_right) cout &lt;&lt; value;
 41     next_column();
 42  }
 43  
 44  void SimpleInvoicePrinter::print_number(double value, int precision)
 45  {
 46     cout &lt;&lt; setw(column_widths[column])
 47        &lt;&lt; fixed &lt;&lt; setprecision(precision)
 48        &lt;&lt; value;
 49     next_column();
 50  }
 51  
 52  void SimpleInvoicePrinter::print_footer(string s, double total)
 53  {
 54     cout &lt;&lt; "\n" &lt;&lt; s &lt;&lt; " " &lt;&lt; total &lt;&lt; "\n";
 55  }
 56  
 57  </pre>
</body>
</html>

⌨️ 快捷键说明

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