From: "isaac2004" <isaac_2004@yahoo.com>
Subject: Re: creating an array
Date: 15 Feb 2006 15:29:08 -0800
Date: 2006-02-15T15:29:08-08:00 [thread overview]
Message-ID: <1140046148.803154.70980@f14g2000cwb.googlegroups.com> (raw)
In-Reply-To: <87u0b070gl.fsf@ludovic-brenta.org>
hey finally got it to work thanks to everybody for helping.
here is code
with Ada.Text_Io;
use Ada.Text_Io;
with Ada.Integer_Text_Io;
use Ada.Integer_Text_Io;
procedure Lab6 is
-----------------------------------------------------------------------------------------------
--| Recieves two inputs, one being a number les than ten and the
other number is a number with the same amount of digits
--| as the first recieved number. the second number is then
seperated, the digits stored in an array and put into ascending order
--| Author: Isaac Levin, Western Washington University
--| Last Modified: February 2006
----------------------------------------------------------------------------
subtype Index is Natural range 1 .. 10;
subtype Number is Natural range 000000000 .. 999999999;
type Positivearray is array (1 .. 10) of Natural;
A : Positivearray;
Promptnum : Index;
Fullnum : Number;
procedure Split (
N : in Number;
Num_Digits : in Index;
Dl : in out Positivearray) is
-- set the variables
Temp : Natural := 1;
Remain : Number := N;
Numdigits : Natural := 1;
-- set this flag to TRUE initially to signify that we should
ignore the leading zeros
Leadingzero : Boolean := True;
-- Calculate the largest number to divide the input number by so
we can extract the left most digit.
-- So if # of digits specified are: 3, then Temp would be: 100
begin
-- Loop to extract all the digits
-- Note: Numdigit is used as the index variable for our array,
this helps us take out the leading zeros if the number entered
-- has less digits than what the user specified
for I in 1..Num_Digits loop
-- Get the individual digit by remaindering
A(I) := Remain mod 10;
-- Store the remainder so in the next loop we can extract the
next left most digit
Remain := Remain / 10;
end loop;
end Split;
-- procedure to sort parts of array
procedure Sort (
Thearray : in out Positivearray;
Inuse : in Natural) is
-- Sorts the elements of the array from smallest to largest
Min : Positive;
Indexmin : Positive;
Temp : Positive;
begin
for I in 1..Inuse - 1 loop
Min := Thearray(I);
Indexmin := I;
for J in I + 1 .. Inuse loop
if Thearray(J) < Min then
Min := Thearray(J);
Indexmin := J;
end if;
end loop;
Temp := Thearray(I);
Thearray(I) := Min;
Thearray(Indexmin) := Temp;
end loop;
end Sort;
begin -- actual interface
Put ("Please enter the number of digits.");
Get(Item => Promptnum);
New_Line;
Put(Item => "Please enter a number with ") ;
Put (
Item => Promptnum,
Width => 0) ;
Put (Item => " digits.");
Get(Item => Fullnum);
Split(Fullnum, Promptnum, A);
Sort (A, Promptnum); -- sort array
New_Line;
Put ("The numbers in sorted order are");
New_Line;
for I in 1..Promptnum loop
Put (A(I), 0);
New_Line;
end loop;
end Lab6;
thank you
Happy Coding!
next prev parent reply other threads:[~2006-02-15 23:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-14 6:06 creating an array isaac2004
2006-02-14 13:59 ` jimmaureenrogers
2006-02-14 15:20 ` isaac2004
2006-02-14 18:44 ` jimmaureenrogers
2006-02-14 19:25 ` Björn Persson
2006-02-14 19:39 ` Dmitry A. Kazakov
2006-02-14 21:14 ` isaac2004
2006-02-14 22:17 ` jimmaureenrogers
2006-02-14 22:30 ` isaac2004
2006-02-14 22:45 ` Ludovic Brenta
2006-02-14 22:54 ` isaac2004
2006-02-14 23:10 ` Ludovic Brenta
2006-02-14 23:37 ` isaac2004
2006-02-15 7:45 ` Anders Wirzenius
2006-02-15 20:44 ` Björn Persson
2006-02-16 6:59 ` Anders Wirzenius
2006-02-15 21:53 ` Ludovic Brenta
2006-02-15 23:29 ` isaac2004 [this message]
2006-02-16 3:09 ` jimmaureenrogers
2006-02-15 7:42 ` Maciej Sobczak
2006-02-15 10:37 ` Jean-Pierre Rosen
2006-02-15 13:30 ` Dmitry A. Kazakov
2006-02-15 16:23 ` isaac2004
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox