{---------------------------------------------------------------------- dataProc2.p Started by Jeff Ondich on 10/2/96. This program is an INCORRECT solution to the first programming assignment in CS 117, Fall 1996. It reads lines of text of the form "Number Number Number Name" and reports the maximum, minimum, and average values corresponding to each name. This program also reports the number of people (lines) in the input database. Where's the problem? ----------------------------------------------------------------------} program dataproc(input,output); var name : string(40); score1, score2, score3, nPeople : integer; maximum, minimum : integer; average : real; {---------------------------------------------------------------------- ComputeMax returns the largest of its three parameters. ----------------------------------------------------------------------} function ComputeMax( a, b, c : integer ) : integer; begin if (a > b) and (a > c) then ComputeMax := a else if (b > a) and (b > c) then ComputeMax := b else ComputeMax := c end; {---------------------------------------------------------------------- ComputeMin returns the smallest of its three parameters. ----------------------------------------------------------------------} function ComputeMin( a, b, c : integer ) : integer; begin if (a < b) and (a < c) then ComputeMin := a else if (b < a) and (b < c) then ComputeMin := b else ComputeMin := c end; {---------------------------------------------------------------------- MAIN PROGRAM ----------------------------------------------------------------------} begin {Initialize the person counter.} nPeople := 0; {For each line of input...} while not eof do begin {...get the numbers and name,...} readln( score1, score2, score3, name ); {...compute the average, max, and min,...} average := (score1 + score2 + score3) / 3; maximum := ComputeMax( score1, score2, score3 ); minimum := ComputeMin( score1, score2, score3 ); {...report the results,...} writeln( name : 10, maximum : 6, minimum : 6, average : 10 : 2 ); {...and update the person counter.} nPeople := nPeople + 1 end; {Report the number of people.} writeln; writeln( 'There are ', nPeople:3, ' people in this database.' ) end.