var
{transaction table}
TransactionPartNo:array[1..10] of integer;
TransactionCustomerNo:array[1..10] of integer;
TransactionQuantity:array[1..10] of integer;
{table of prices}
PriceTable:array[1..10] of integer;
{customer table, one for each customer}
CustomerTotal:array[1..10] of integer;
PriceFile:text;
TransactionFile:text;
OrderTotal,CustomerNo,
TransactionCount,i,PartNo,Customer,Quantity,Price:integer;
begin
assign(PriceFile,'u57.prices');
reset(PriceFile);
assign(TransactionFile,'u57.trans');
reset(TransactionFile);
{read in the Price Table}
read(PriceFile,PartNo);
while(PartNo<>-1) do begin
read(PriceFile,Price);
PriceTable[PartNo]:=Price;
read(PriceFile,PartNo);
end;
{zero out Customer Table}
for i:=1 to 10 do begin
CustomerTotal[i]:=0;
end;
{read in Transaction Table}
read(TransactionFile,Customer);
i:=1;
while(Customer <>-1) do begin
read(TransactionFile,PartNo);
read(TransactionFile,Quantity);
TransactionPartNo[i]:=PartNo;
TransactionCustomerNo[i]:=Customer;
TransactionQuantity[i]:=Quantity;
read(TransactionFile,Customer);
i:=i+1;
end;
TransactionCount:=i-1;
{compute the sum of all orders}
for i:=1 to TransactionCount do begin
OrderTotal:=TransactionQuantity[i]*PriceTable[TransactionPartNo[i]];
CustomerNo:=TransactionCustomerNo[i];
CustomerTotal[CustomerNo]:=
CustomerTotal[CustomerNo]+OrderTotal;
end;
{dump out Customer Totals}
for i:=1 to 10 do begin
if CustomerTotal[i]<>0 then begin
write('Customer Number ',i,' bought ',CustomerTotal[i],
' dollars worth of goods');
writeln;
end;
end;
end.