Sort an array of records?

Hi friends, how can I code a pascal program that will store rainfall figures for each of 12 months for a weather station. For each entry the number of the month must be in integer and total rainfall in real (cm). The program should first allow the user to enter the 12 sets of data then should go into a loop offering the user the following choices until they choose to quit. 1:Display the highest figure 2: Display the lowest figure 3: Display the rainfall figures in ascending order 4:Display the rainfall figures in month order 5:Quit. Using an array of records and sorting the records into the right order prior to displaying by option 1 & 2. Check that rainfall figures entered are >=0 and that choices are in the range 1-5. If out of range values are entered,the user should be prompted and allowed to enter new values.

Comments

• : Hi friends, how can I code a pascal program that will store rainfall figures for each of 12 months for a weather station. For each entry the number of the month must be in integer and total rainfall in real (cm). The program should first allow the user to enter the 12 sets of data then should go into a loop offering the user the following choices until they choose to quit. 1:Display the highest figure 2: Display the lowest figure 3: Display the rainfall figures in ascending order 4:Display the rainfall figures in month order 5:Quit. Using an array of records and sorting the records into the right order prior to displaying by option 1 & 2. Check that rainfall figures entered are >=0 and that choices are in the range 1-5. If out of range values are entered,the user should be prompted and allowed to enter new values.
:
USe the bubblesort algorithm (http://en.wikipedia.org/wiki/Bubblesort). It is fast and easy to code for small datasets.
• : Hi friends, how can I code a pascal program that will store rainfall figures for each of 12 months for a weather station. For each entry the number of the month must be in integer and total rainfall in real (cm). The program should first allow the user to enter the 12 sets of data then should go into a loop offering the user the following choices until they choose to quit. 1:Display the highest figure 2: Display the lowest figure 3: Display the rainfall figures in ascending order 4:Display the rainfall figures in month order 5:Quit. Using an array of records and sorting the records into the right order prior to displaying by option 1 & 2. Check that rainfall figures entered are >=0 and that choices are in the range 1-5. If out of range values are entered,the user should be prompted and allowed to enter new values.
:
Hi mate, need more push please code this for me.
• : : Hi friends, how can I code a pascal program that will store rainfall figures for each of 12 months for a weather station. For each entry the number of the month must be in integer and total rainfall in real (cm). The program should first allow the user to enter the 12 sets of data then should go into a loop offering the user the following choices until they choose to quit. 1:Display the highest figure 2: Display the lowest figure 3: Display the rainfall figures in ascending order 4:Display the rainfall figures in month order 5:Quit. Using an array of records and sorting the records into the right order prior to displaying by option 1 & 2. Check that rainfall figures entered are >=0 and that choices are in the range 1-5. If out of range values are entered,the user should be prompted and allowed to enter new values.
: :
: Hi mate, need more push please code this for me.
:
Here is the bubblesort algorithm. You need to edit this code to match your data-structure.
[code]
procedure Sort;
var
i, j: integer;
T: TArrayElement;
begin
for i := 0 to ArraySize-1 do
for j := 0 to ArraySize-2 do
if Array[j].Data > Array[j+1].Data then { Compare records }
begin
T := Array[j]; { Swap records if they are in the wrong order }
Array[j] := Array[j+1];
Array[j+1] := T;
end;
end;
[/code]
• : : : Hi friends, how can I code a pascal program that will store rainfall figures for each of 12 months for a weather station. For each entry the number of the month must be in integer and total rainfall in real (cm). The program should first allow the user to enter the 12 sets of data then should go into a loop offering the user the following choices until they choose to quit. 1:Display the highest figure 2: Display the lowest figure 3: Display the rainfall figures in ascending order 4:Display the rainfall figures in month order 5:Quit. Using an array of records and sorting the records into the right order prior to displaying by option 1 & 2. Check that rainfall figures entered are >=0 and that choices are in the range 1-5. If out of range values are entered,the user should be prompted and allowed to enter new values.
: : :
: : Hi mate, need more push please code this for me.
: :
: Here is the bubblesort algorithm. You need to edit this code to match your data-structure.
: [code]
: procedure Sort;
: var
: i, j: integer;
: T: TArrayElement;
: begin
: for i := 0 to ArraySize-1 do
: for j := 0 to ArraySize-2 do
: if Array[j].Data > Array[j+1].Data then { Compare records }
: begin
: T := Array[j]; { Swap records if they are in the wrong order }
: Array[j] := Array[j+1];
: Array[j+1] := T;
: end;
: end;
: [/code]
:
Thanks that was really helpful.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!