# Programs to Complete: Seven Segment Display

Program Display7Segments is a simulation of the seven segment displays used in digital watches and calculators. Each digit is made up of a combination of underscores, vertical lines (ASCII 179) and spaces on three consecutive lines of characters. You could complete the program using the following steps:

• Work out the pattern of characters to represent the digits 2, 3 and 4, then write procedures two, three and four to insert them into the three lines of characters.
• Write a routine to display, using seven segment digits, a count from 1 to 999.
• Extend the display to cover integers from 0 to 9999.
```program Display7Segments;
{\$APPTYPE CONSOLE}
uses
SysUtils;
var
intNum, ErrorCode, Hundreds, Tens, Units : integer;
Line1, Line2, Line3, strNum : string;

procedure zero;
begin;
Line1 := '   _ ' + Line1;
Line2 := '  ' + CHR(179) + ' ' + CHR(179) + Line2;
Line3 := '  ' + CHR(179) + '_' + CHR(179) + Line3;
end;

procedure one;
begin;
Line1 := '     ' + Line1;
Line2 := '    ' + CHR(179) + Line2;
Line3 := '    ' + CHR(179) + Line3;
end;

procedure five;
begin;
Line1 := '   _ ' + Line1;
Line2 := '  ' + CHR(179) + '_ ' + Line2;
Line3 := '   ' +  '_' + CHR(179) + Line3;
end;

procedure six;
begin;
Line1 := '   _ ' + Line1;
Line2 := '  ' + CHR(179) + '_ ' + Line2;
Line3 := '  ' + CHR(179) + '_' + CHR(179) + Line3;
end;

procedure seven;
begin;
Line1 := '   _ ' + Line1;
Line2 := '    ' + CHR(179) + Line2;
Line3 := '    ' + CHR(179) + Line3;
end;

procedure eight;
begin;
Line1 := '   _ ' + Line1;
Line2 := '  ' + CHR(179) + '_' + CHR(179) + Line2;
Line3 := '  ' + CHR(179) + '_' + CHR(179) + Line3;
end;

procedure nine;
begin;
Line1 := '   _ ' + Line1;
Line2 := '  ' + CHR(179) + '_' + CHR(179) + Line2;
Line3 := '   ' + '_' + CHR(179) + Line3;
end;

procedure InsertDigit(i: integer);
begin
case i of
0: zero;
1: one;
5: five;
6: six;
7: seven;
8: eight;
9: nine;
end;
end;

begin
Line1 := '';
Line2 := '';
Line3 := '';
repeat
write('Please enter an integer less than 1000 without ' +
'digits 2 - 4. ');
val(strNum, intNum, ErrorCode);
until (ErrorCode = 0) and (length(strNum) <= 3);
Units := intNum MOD 10;
Tens := (intNum DIV 10) MOD 10;
Hundreds := intNum DIV 100;
InsertDigit(Units);
if intNum > 9 then
begin
InsertDigit(Tens);
if intNum > 99 then
begin
InsertDigit(Hundreds);
end;
end;
writeln(Line1);
writeln(Line2);
writeln(Line3);