{---------------------------------------------------------------------- dataProc.p Started by Jeff Ondich on 10/2/96. This program is a 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. ----------------------------------------------------------------------} 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; var maxSoFar : integer; begin maxSoFar := a; if b > maxSoFar then maxSoFar := b; if c > maxSoFar then maxSoFar := c; ComputeMax := maxSoFar end; {---------------------------------------------------------------------- ComputeMin returns the smallest of its three parameters. ----------------------------------------------------------------------} function ComputeMin( a, b, c : integer ) : integer; var minSoFar : integer; begin minSoFar := a; if b < minSoFar then minSoFar := b; if c < minSoFar then minSoFar := c; ComputeMin := minSoFar end; {---------------------------------------------------------------------- MAIN PROGRAM ----------------------------------------------------------------------} begin {Initialize the person counter.} nPeople := 0; {Print the heading for the output table} writeln( 'Name':10, 'Max':6, 'Min':6, 'Average':10 ); {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.