Repository navigation
Expand file tree
/
Copy pathsevensegment.cpp
More file actions
190 lines (179 loc) · 4.64 KB
/
Copy pathsevensegment.cpp
File metadata and controls
190 lines (179 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include <ostream>
#include <vector>
#include <functional>
namespace RenderedDigit {
const int amount_of_lines = 5;
const int length_of_line = 3;
const std::vector<std::string> minus = {
" ",
" ",
" - ",
" ",
" "
};
const std::vector<std::string> zero = {
" - ",
"| |",
" ",
"| |",
" - "
};
const std::vector<std::string> one = {
" ",
" |",
" ",
" |",
" "
};
const std::vector<std::string> two = {
" - ",
" |",
" - ",
"| ",
" - "
};
const std::vector<std::string> three = {
" - ",
" |",
" - ",
" |",
" - "
};
const std::vector<std::string> four = {
" ",
"| |",
" - ",
" |",
" "
};
const std::vector<std::string> five = {
" - ",
"| ",
" - ",
" |",
" - "
};
const std::vector<std::string> six = {
" - ",
"| ",
" - ",
"| |",
" - "
};
const std::vector<std::string> seven = {
" - ",
" |",
" ",
" |",
" "
};
const std::vector<std::string> eight = {
" - ",
"| |",
" - ",
"| |",
" - "
};
const std::vector<std::string> nine = {
" - ",
"| |",
" - ",
" |",
" - "
};
const std::vector<std::string> big_e = {
" - ",
"| ",
" - ",
"| ",
" - "
};
const std::vector<std::string> small_r = {
" ",
" ",
" - ",
"| ",
" "
};
const std::vector<std::string> small_o = {
" ",
" ",
" - ",
"| |",
" - "
};
}
std::vector<std::string> resolve7SectorDigit(char digit) {
switch (digit) {
case '-':
return RenderedDigit::minus;
case '0':
return RenderedDigit::zero;
case '1':
return RenderedDigit::one;
case '2':
return RenderedDigit::two;
case '3':
return RenderedDigit::three;
case '4':
return RenderedDigit::four;
case '5':
return RenderedDigit::five;
case '6':
return RenderedDigit::six;
case '7':
return RenderedDigit::seven;
case '8':
return RenderedDigit::eight;
case '9':
return RenderedDigit::nine;
case 'E':
return RenderedDigit::big_e;
case 'r':
return RenderedDigit::small_r;
case 'o':
return RenderedDigit::small_o;
default:
return RenderedDigit::zero;
}
}
void printLineBreak(std::ostream &out) {
out << std::endl;
}
void repeat(int times, const std::function<void(int)> &executable) {
for (size_t i = 0; i < times; i++) {
executable(i);
}
}
void printVector(const std::vector<std::vector<std::string>> &vector, std::ostream &out) {
repeat(RenderedDigit::amount_of_lines, [&vector, &out](auto index) {
for_each(cbegin(vector), cend(vector), [&index, &out](auto digit) {
out << digit.at(index);
});
printLineBreak(out);
});
}
// takes a const string reference and builds the corresponding 7 digit sign representation
std::vector<std::vector<std::string>> buildSignVectorRepresentation(const std::string &number) {
std::vector<std::vector<std::string>> digitsInSigns{};
for_each(cbegin(number), cend(number), [&digitsInSigns](auto singleChar) {
digitsInSigns.push_back(resolve7SectorDigit(singleChar));
});
return digitsInSigns;
}
void printFromString(const std::string &text, std::ostream &out) {
printVector(buildSignVectorRepresentation(text), out);
}
[[deprecated("This function is only here to make the alf tests happy")]]
void printLargeDigit(int i, std::ostream &out) {
if (i < 0 || i > 9) {
throw std::invalid_argument("Please use printLargeDigit method to print numbers above nine or below zero");
}
printFromString(std::to_string(i), out);
}
void printLargeNumber(int i, std::ostream &out) {
printFromString(std::to_string(i), out);
}
void printLargeError(std::ostream &out) {
printFromString("Error", out);
}