The problem is to tabulate and summarize the donations to a sports booster club. An example input follows; each row gives the name of the donor, a number which is the month of the year in which the donation was made, and the amount, in dollars.
Fred 3 50.00
Jim 4 25.00
June 5 25.00
Fred 5 10.00
Emily 6 15.00
Antonio 6 10.00
Patrick 2 5.00
Patrick 3 5.00
Patrick 4 5.00
etc.
Note that the donations can appear in any order in the file, and one person can donate several times during the year.
Your task is to read all the input an store it in suitably declared arrays. Then display the data in table form on the screen (here you may save the display table in a file to be printed on the printer). This will look something like:
Name Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Fred 0.00 0.00 50.00 0.00 10.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Jim 0.00 0.00 0.00 10.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 June 0.00 0.00 0.00 0.00 25.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 Emily 0.00 0.00 0.00 0.00 0.00 15.00 0.00 0.00 0.00 0.00 0.00 0.00 Antonio 0.00 0.00 0.00 0.00 0.00 10.00 0.00 0.00 0.00 0.00 0.00 0.00 Patrick 0.00 5.00 5.00 5.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
etc.
Then find each person's total donation, and display the names and corresponding totals in descending order of total donation, i.e. biggest total first. The output woud then look like:
Name Total Fred 60.00 June 25.00 Patrick 15.00 Emily 15.00 Antonio 10.00 Jim 10.00
Follow the same procedure for this program that you have for the previous ones, as follows:
Note that steps 1 to 6 are best done away from the computer.
PROCEDURE Sort(VAR Names:nameArrayType; VAR Totals:totalArrayType; Donations: integer); VAR IndexOfLargest, StartIndex, Index : integer; TempTotal : real; TempName : string[20]; BEGIN FOR StartIndex := 1 TO Donations DO BEGIN IndexOfLargest := StartIndex; FOR Index := StartIndex + 1 TO Donations DO IF Totals[Index] > Totals[IndexOfLargest] THEN IndexOfLargest := Index; IF IndexOfLargest <> StartIndex THEN { do the swap } BEGIN TempTotal := Totals[IndexOfLargest]; TempName := Names[IndexOfLargest]; Totals[IndexOfLargest] := Totals[StartIndex]; Names[IndexOfLargest] := Names[StartIndex]; Totals[StartIndex] := TempTotal; Names[StartIndex] := TempName END { of swap } END { of outer FOR loop } END; { of procedure Sort }
Hand in you design document, source code and sample output by Wednesday, 21st. November, before 5pm.