From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: I need feedback
Date: Thu, 16 Jun 2011 00:34:55 -0700 (PDT)
Date: 2011-06-16T00:34:55-07:00 [thread overview]
Message-ID: <60103dcd-f9a9-4577-8367-2cbd1747c23e@b1g2000yql.googlegroups.com> (raw)
In-Reply-To: 7249477f-1b33-4546-b1cd-f7333e2cff00@y30g2000yqb.googlegroups.com
juanmiuk wrote:
> Well, Thank you for all suggestion, I think I follow all of them.
> There you go the final version:
>
> with Ada.Text_IO;
> with Ada.Integer_Text_IO;
> with Ada.Numerics.Discrete_Random;
> with Ada.Strings.Fixed;
>
> use Ada;
> use Ada.Strings.Fixed;
>
> procedure Sort_3_Numbers is
>
> subtype One_Ten is Integer range 1 .. 10;
>
> package Roulette10 is new Ada.Numerics.Discrete_Random(One_Ten);
>
> Gen10: Roulette10.Generator;
>
> WIDTH_NUM : constant One_Ten := One_Ten'Width;
> THE_BASE : constant One_Ten := 10;
This is not necessary, see why below.
> procedure Output_Num
> ( The_Number : in One_Ten;
> Width_Num : in One_Ten;
> The_Base : in One_Ten )
> is
>
> begin
>
> Integer_Text_IO.Put(The_Number, Width_Num, The_Base);
>
> end Output_Num;
This entire procedure does nothing but call Integer_Text_IO.Put, so is
not necessary; you might as well call Integer_Text_IO.Put directly.
In the spec of Integer_Text_IO.Put, the parameter Base has a default
value of 10, so you need not specify it. You could even do away with
Width_Num like this:
package One_Ten_IO is new Ada.Text_IO.Integer_IO (Num => One_Ten);
This would initialize the constant One_Ten_IO.Default_Width to be
One_Ten'Width; you would not have to do it yourself.
> begin
> Roulette10.Reset(Gen10);
> for I in One_Ten'Range loop
> Main_Process : declare
> A : One_Ten := Roulette10.Random(Gen10);
> B : One_Ten := Roulette10.Random(Gen10);
> C : One_Ten := Roulette10.Random(Gen10);
>
> First : One_Ten;
> Secon : One_Ten;
> Third : One_Ten;
> begin
> Output_Num(A, WIDTH_NUM, THE_BASE);
> -- Changing all the Output_Num by Integer_Text_IO.Put(A, WIDTH_NUM, THE_BASE)
> -- as Jeffrey Carter comments then won't be any dupplications.
Or, even more succinctly:
One_Ten_IO.Put (A);
[rest snipped].
Hope this helps.
--
Ludovic Brenta.
next prev parent reply other threads:[~2011-06-16 7:34 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-14 21:12 I need feedback juanmiuk
2011-06-14 21:50 ` Ludovic Brenta
2011-06-15 9:10 ` Pascal Obry
2011-06-15 11:40 ` Yannick Duchêne (Hibou57)
2011-06-15 19:38 ` Shark8
2011-06-16 4:24 ` juanmiuk
2011-06-16 7:34 ` Ludovic Brenta [this message]
2011-06-14 23:16 ` Jeffrey Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox