📄 simpleinvoiceprinter.cpp.html
字号:
<html>
<head>
<title>simpleinvoiceprinter.cpp</title>
</head>
<body>
<pre> 1 #include <iostream>
2 #include <iomanip>
3
4 using namespace std;
5
6 #include "simpleinvoiceprinter.h"
7
8 SimpleInvoicePrinter::SimpleInvoicePrinter(vector<int> 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 < column_widths.size(); i++)
18 width = width + column_widths[i];
19 for (int j = 0; j < (width - s.length()) / 2; j++)
20 cout << " ";
21 cout << s << "\n\n";
22 }
23
24 void SimpleInvoicePrinter::next_column()
25 {
26 column++;
27 if (column == column_widths.size())
28 {
29 cout << "\n";
30 column = 0;
31 }
32 }
33
34 void SimpleInvoicePrinter::print_string(string value, bool pad_right)
35 {
36 if (pad_right) cout << value;
37 <font color='#0000cc'>// print padding</font>
38 for (int i = value.length(); i < column_widths[column]; i++)
39 cout << " ";
40 if (!pad_right) cout << value;
41 next_column();
42 }
43
44 void SimpleInvoicePrinter::print_number(double value, int precision)
45 {
46 cout << setw(column_widths[column])
47 << fixed << setprecision(precision)
48 << value;
49 next_column();
50 }
51
52 void SimpleInvoicePrinter::print_footer(string s, double total)
53 {
54 cout << "\n" << s << " " << total << "\n";
55 }
56
57 </pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -