Board index » delphi » need help with Sorting and files

need help with Sorting and files

I have been asked to design and implement a program to sort some
numerical data, the data is real numbers of the form 63x.xx   i.e all
numbers are under 639 and have two decimal places.

In each set of data to be sorted there may be up to 35 numbers but
never less than ten.

The numbers to be sorted will arrive in the form of a file of
real.

The output from your program will be displayed on the screen as well
as saved to a new file.

To test your program you will need to create a file of numbers that
conforms to the input requirements of the program.

The random number function returns an integer value between 0 and 1
less than the parameter passed to it e.g.

Random(999)  >>>>>  0 to 998

To convert this number to a real, you may divide it by (say) 100, this
would give a real value between 0.00 and 9.98

 

Re:need help with Sorting and files


Hi!

Quote
Alistair wrote:

> I have been asked to design and implement a program to sort some
> numerical data, the data is real numbers of the form 63x.xx   i.e all
> numbers are under 639 and have two decimal places. [...]

Read
  D.E. Knuth, "The Art of Computer Programming",
  vol. 3: "Sorting and Searching";
  published by Addison-Wesley in the 1970s

or search the net for "Insertion sort", "Bubblesort", and "Quicksort".

HTH,
Joerg Bruehe

--
Joerg Bruehe, SQL Datenbanksysteme GmbH, Berlin, Germany
     (speaking only for himself)
mailto: jo...@sql.de

Re:need help with Sorting and files


Quote
"Alistair" <messwiththebest2...@hotmail.com> wrote in message

news:fa77feec.0205150030.40299595@posting.google.com...

Quote
> I have been asked to design and implement a program to sort some
> numerical data, the data is real numbers of the form 63x.xx   i.e all
> numbers are under 639 and have two decimal places.

Most all of us were asked to design similar programs when we were
in school, too!

Good Luck.

Rufus

Re:need help with Sorting and files


On 15 May 2002 01:30:19 -0700, messwiththebest2...@hotmail.com

Quote
(Alistair) wrote:
>I have been asked to design and implement a program to sort some
>numerical data, the data is real numbers of the form 63x.xx   i.e all

... Are you sure this can be done in Pascal?  

Re:need help with Sorting and files


On 15 May 2002 01:30:19 -0700, messwiththebest2...@hotmail.com

Quote
(Alistair) wrote:
>I have been asked to design and implement a program to sort some
>numerical data, the data is real numbers of the form 63x.xx   i.e all
>numbers are under 639 and have two decimal places.

>In each set of data to be sorted there may be up to 35 numbers but
>never less than ten.

>The numbers to be sorted will arrive in the form of a &#8216;file of
>real&#8217;.

>The output from your program will be displayed on the screen as well
>as saved to a new file.

>To test your program you will need to create a file of numbers that
>conforms to the input requirements of the program.

>The random number function returns an integer value between 0 and 1
>less than the parameter passed to it e.g.

>Random(999)  >>>>>  0 to 998

>To convert this number to a real, you may divide it by (say) 100, this
>would give a real value between 0.00 and 9.98

Generating and sorting random numbers with Turbo Pascal v6.0.

     By the way, numbers of the form 63x.xx includes 639.99 which
is NOT smaller than 639.

     To construct your test program, do it in small steps. I suggest
you first learn to generate random integers in the range of 0 to 99.
After you have learned that, just divide that by 100 and get 0.00 to
0.99. That gives you the decimal fraction for the random real number.
Now generate the integer to go with it, in your case that would be 0
to 639. Add the two together and store in an array of real.
     Display the array as Writeln(realnum:3:2).

There are many ways to sort the array but, with so few numbers, speed
is not a factor. Just use a way you understand. The following finds
the smallest number in the remainder of the array each iteration. The
sort is in ascending order:

For j := 1 to {length of array - 1} Do
Begin
    smallest := a[j];  {where "a" is an array of real}
    For k := j + 1 to {length of array} Do
    Begin
         if a[k] < smallest then smallest := a[k];
    End;
    {If smallest <> a[j] then swap positions of these 2 array
elements.}
End;

I leave the disk writing and reading to you.

Re:need help with Sorting and files


Quote
messwiththebest2...@hotmail.com (Alistair) wrote in message <news:fa77feec.0205150030.40299595@posting.google.com>...
> I have been asked to design and implement a program to sort some
> numerical data, the data is real numbers of the form 63x.xx   i.e all
> numbers are under 639 and have two decimal places.

Why are you taking a class and then asking someone to write your
program for you? Why not drop the class and take Marketing or Womens
Studies or some other silly thing? You can't fake programming
knowlege. Why not give it a try and post your code? Folks here will
offer suggestions and then you can learn how to program.

Re:need help with Sorting and files


On 14 Jun 2002 10:03:08 -0700, srog...@pd-engineers.com (steve rogers)
wrote:

Quote
>Why are you taking a class and then asking someone to write your
>program for you? Why not drop the class and take Marketing or Womens
>Studies or some other silly thing?

How about the Philisophy of the History of Art?

Other Threads