/
Widgets.pas
174 lines (154 loc) · 2.91 KB
/
Widgets.pas
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
PROGRAM Widgets;
CONST
NULLP = pointer(0);
NULLC = #0;
LF = #10;
MAXLN = 12;
MAXSTATES = 50;
TYPE
textfield = packed array [1..64] of char;
employee = RECORD
count : integer;
dept : integer;
id : integer;
name : textfield;
plant : integer;
state : integer;
END;
department = array [1..MAXLN] of employee;
plant = array [1..MAXLN] of department;
state = RECORD
id : integer;
count : integer;
employees : array[1..MAXLN] of employee;
plants : array [1..MAXLN] of plant;
END;
statep = ^state;
employeep = ^employee;
VAR
ch : char;
empl : employee;
stt : ^state;
employees : array [1..MAXLN] of employee;
emplcount : integer;
i : integer;
world : packed array [1..MAXSTATES] of ^state;
PROCEDURE readempl;
PROCEDURE readname;
VAR
ch : char;
i : integer;
BEGIN
i := 1;
read(ch);
IF ch = ' ' THEN
read(ch);
WHILE ch <> ':' DO
BEGIN
empl.name[i] := ch;
i := i + 1;
read(ch);
END;
empl.name[i] := NULLC;
read(ch);
END;
BEGIN
read(empl.state);
read(empl.plant);
read(empl.dept);
read(empl.id);
readname;
read(empl.count);
END;
PROCEDURE writeempl;
PROCEDURE writename;
VAR
i : integer;
BEGIN
i := 1;
WHILE empl.name[i] <> NULLC DO
BEGIN
write(ErrOutput, empl.name[i]);
i := i + 1;
END;
END;
BEGIN
WITH empl DO
BEGIN
write(ErrOutput, 'State: ', state, ' Plant: ', plant, ' Dept: ', dept, ' ID: ', id, ' Name: ');
writename;
write(ErrOutput, ' Widgets: ', count);
writeln(ErrOutput);
END
END;
PROCEDURE reademployees;
BEGIN
emplcount := 1;
REPEAT
readempl;
employees[emplcount] := empl;
inc(emplcount);
read(ch); (* Eat the line feed *)
UNTIL eof;
END;
PROCEDURE writeemployees;
BEGIN
FOR emplcount := 1 TO MAXLN DO
BEGIN
empl := employees[emplcount];
writeempl;
END;
END;
PROCEDURE writestate;
BEGIN
IF stt^.count < 10 THEN
write(' ')
ELSE
IF stt^.count < 100 THEN
write(' ')
ELSE
write(' ');
writeln(stt^.count, ' *** total for state ', stt^.id)
END;
PROCEDURE writestates;
BEGIN
FOR i := 1 TO MAXSTATES DO
BEGIN
stt := world[i];
IF NOT(stt = NULLP) THEN
writestate;
END;
END;
FUNCTION findstate(stateid : integer) : statep;
BEGIN
IF world[stateid] = NULLP THEN
world[stateid] := new(statep);
world[stateid]^.count := 0;
world[stateid]^.id := stateid;
findstate := world[stateid];
END;
PROCEDURE initworld;
BEGIN
FOR i := 1 TO MAXSTATES DO
world[i] := NULLP;
END;
PROCEDURE appendtostate(stt : statep; empl : employeep);
BEGIN
END;
PROCEDURE sortworld;
BEGIN
FOR i := 1 TO emplcount DO
BEGIN
empl := employees[i];
stt := findstate(empl.state);
stt^.count := stt^.count + empl.count;
appendtostate(@stt, @empl)
END;
END;
BEGIN
initworld;
reademployees;
writeemployees;
sortworld;
writestates;
END.