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
|
#include <iostream>
using namespace std;
struct Display
{
bool T, M, B, TL, TR, BL, BR;
};
//=====================================================================
Display setSegments( int n ) // n should be 0 to 9
{
Display d{1,1,1,1,1,1,1}; // start with all segments ON
switch ( n )
{
case 0: d.M = 0; break;
case 1: d.T = d.M = d.B = d.TL = d.BL = 0; break;
case 2: d.TL = d.BR = 0; break;
case 3: d.TL = d.BL = 0; break;
case 4: d.T = d.B = d.BL = 0; break;
case 5: d.TR = d.BL = 0; break;
case 6: d.T = d.TR = 0; break;
case 7: d.M = d.B = d.TL = d.BL = 0; break;
case 8: ; break;
case 9: d.B = d.BL = 0; break;
default: cout << "ERROR\n";
}
return d;
}
//=====================================================================
void draw( Display d )
{
const char S = ' ', H = '-', V = '|';
const char v[] = { S, V };
const char h[] = { S, H };
cout << S << h[d.T] << S << '\n'
<< v[d.TL] << S << v[d.TR] << '\n'
<< S << h[d.M] << S << '\n'
<< v[d.BL] << S << v[d.BR] << '\n'
<< S << h[d.B] << S << '\n';
cout << '\n';
}
//=====================================================================
int main()
{
for ( int n = 0; n < 10; n++ ) draw( setSegments( n ) );
}
//=====================================================================
| |