comp.lang.ada
 help / color / mirror / Atom feed
* Re: help Please
       [not found] <36ab9be5.2873369@news.ptd.net>
@ 1999-01-24  0:00 ` Matthew Heaney
  1999-01-26  0:00   ` Steve Kerr
  1999-01-26  0:00   ` Simon Wright
  0 siblings, 2 replies; 12+ messages in thread
From: Matthew Heaney @ 1999-01-24  0:00 UTC (permalink / raw)


rross@postoffice.ptd.net (bob) writes:

> hey, i am a student and i cant seem to figure this out:
> we are to add two integer numbers together , assuming that the
> computer
> doesnt know how to add.  for example , you read two integers into an
> array
> of characters each.
> then you add the numbers together in a for loop:
> 
> for a in reverse (1..10) loop
> 	--Z is the 3rd array or result array
> 	Z(a) := A(a)+B(a)+carry;
> 
> something like that, where carry is if you have a sum of more than 10,
> which is decided in an if statement later in the loop
> 
> my problem is: we are supposed to use array A and B as type
> characters.
> you cant add two characters and you cant typecast them to integers, so
> how
> do u get the result of the sums into Z?
> any help on this would be greatly appreciated
> thanks in advance

If you want to add two characters together, then just define an operator
to do that:

 function "+" (L, R : Character) return Character is ...;

You can't "typecast" a character to integer, like this

     ... Integer (C) ...

but of course you can convert a character into its underlying integer
representation either by using Unchecked_Conversion or Character'Pos.


 




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help Please
  1999-01-24  0:00 ` help Please Matthew Heaney
  1999-01-26  0:00   ` Steve Kerr
@ 1999-01-26  0:00   ` Simon Wright
  1 sibling, 0 replies; 12+ messages in thread
From: Simon Wright @ 1999-01-26  0:00 UTC (permalink / raw)


Matthew Heaney <matthew_heaney@acm.org> writes:

> You can't "typecast" a character to integer, like this
> 
>      ... Integer (C) ...
> 
> but of course you can convert a character into its underlying integer
> representation either by using Unchecked_Conversion or Character'Pos.

I would have thought the original problem would have expected the
character '1' to act in this context as if it had the numeric value 1
(rather than 49 which Character'Pos might give you)




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help Please
  1999-01-24  0:00 ` help Please Matthew Heaney
@ 1999-01-26  0:00   ` Steve Kerr
  1999-01-26  0:00     ` David C. Hoos, Sr.
  1999-01-26  0:00   ` Simon Wright
  1 sibling, 1 reply; 12+ messages in thread
From: Steve Kerr @ 1999-01-26  0:00 UTC (permalink / raw)


Matthew Heaney wrote:

[....snip snip.....]

> If you want to add two characters together, then just define an operator
> to do that:
>
>  function "+" (L, R : Character) return Character is ...;
>
> You can't "typecast" a character to integer, like this
>
>      ... Integer (C) ...
>
> but of course you can convert a character into its underlying integer
> representation either by using Unchecked_Conversion or Character'Pos.
>

  More simply, you can use the value attribute. For example

    integer'value("4")

will give you the integer value 4, not the code for ASCII "4".

This attribute can be used with any string representing a discrete type, so
I guess boolean'value("TRUE") works too (although I have only ever tried it
with numeric values). Leading and trailing spaces in the string are ignored,
so there's no need to trim it. As a matter of interest, this 'value is the
opposite of 'image.

BTW Jarrod, if the computer does not know how to add, what does it do with
the '+' operator in your example ;-)







^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help Please
  1999-01-26  0:00   ` Steve Kerr
@ 1999-01-26  0:00     ` David C. Hoos, Sr.
  1999-01-27  0:00       ` Steve Kerr
  0 siblings, 1 reply; 12+ messages in thread
From: David C. Hoos, Sr. @ 1999-01-26  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 991 bytes --]


Steve Kerr wrote in message <36ADB3F7.7A239560@gecm.com>...
>Matthew Heaney wrote:
>
>[....snip snip.....]
<snip>
>  More simply, you can use the value attribute. For example
>
>    integer'value("4")
>
>will give you the integer value 4, not the code for ASCII "4".
>
>This attribute can be used with any string representing a discrete type, so
>I guess boolean'value("TRUE") works too (although I have only ever tried it
>with numeric values). Leading and trailing spaces in the string are
ignored,
>so there's no need to trim it. As a matter of interest, this 'value is the
>opposite of 'image.
>
Not quite true -- it's for every _scalar_ type which includes reals, as well
as discretes:

Hear what RM95 says:

S�Value For every scalar subtype S:

S�Value denotes a function with the following specification:

function S'Value(Arg : String)
return S'Base

This function returns a value given an image of the value as a String,
ignoring any leading or trailing spaces. See 3.5.







^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help Please
  1999-01-26  0:00     ` David C. Hoos, Sr.
@ 1999-01-27  0:00       ` Steve Kerr
  1999-01-27  0:00         ` Tucker Taft
  0 siblings, 1 reply; 12+ messages in thread
From: Steve Kerr @ 1999-01-27  0:00 UTC (permalink / raw)


David C. Hoos, Sr. wrote:

> Hear what RM95 says:
>
> S�Value For every scalar subtype S:
>
> S�Value denotes a function with the following specification:
>
> function S'Value(Arg : String)
> return S'Base
>
> This function returns a value given an image of the value as a String,
> ignoring any leading or trailing spaces. See 3.5.

 This is true in Ada 95, but NOT Ada 83. The Ada 83 LRM states:

        P'value -  For a prefix P that denotes a discrete type or subtype.

The original poster did not say whether he was using Ada83 or Ada95, so I guess
we are both correct.

This does though raise an interesting point though (assuming that the same rules
apply to the image attribute), how does Ada95 decide on the string
representation of a floating point number for the image attribute ? i.e. how
many decimal places to display and whether to display an exponent, particulaly
where the float can be represented without an exponent (e.g. 0.1234). My guess
is that this is compiler dependant, does anyone know different ?







^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help Please
  1999-01-27  0:00       ` Steve Kerr
@ 1999-01-27  0:00         ` Tucker Taft
  0 siblings, 0 replies; 12+ messages in thread
From: Tucker Taft @ 1999-01-27  0:00 UTC (permalink / raw)


Steve Kerr (stephen.kerr@gecm.com) wrote:

: ...
: This does though raise an interesting point though (assuming that the same rules
: apply to the image attribute), how does Ada95 decide on the string
: representation of a floating point number for the image attribute ? i.e. how
: many decimal places to display and whether to display an exponent, particulaly
: where the float can be represented without an exponent (e.g. 0.1234). My guess
: is that this is compiler dependant, does anyone know different ?

Oh please, not compiler dependent! ;-).  

There is actually a surprisingly easy way to find this out, and 
that is to look in the Ada 95 Reference Manual.  (I suspect you 
will quickly be bombarded with repeats of this answer!)

The relevant paragraph is RM95 3.5(33):

  The image of a floating point value is a decimal real literal
  best approximating the value (rounded away from zero if halfway
  between) with a single leading character that is either a minus
  sign or a space, a single digit (that is nonzero unless the value
  is zero), a decimal point, S'Digits-1 (see 3.5.8) digits after
  the decimal point (but one if S'Digits is one), an upper case E, 
  the sign of the exponent (either + or -), and two or more digits
  (with leading zeros if necessary) representing the exponent.
  If S'Signed_Zeros is True, then the leading character is a minus
  sign for a negatively signed zero.

So the quicker answer is: Min(S'Digits-1, 1) digits after
the decimal point, and there will always be an exponent (ugly as
that may be ;-).

--
-Tucker Taft   stt@averstar.com   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help please
  2000-05-22  0:00 saju sathyan
@ 2000-05-22  0:00 ` Gautier
  2000-05-23  0:00   ` saju sathyan
  0 siblings, 1 reply; 12+ messages in thread
From: Gautier @ 2000-05-22  0:00 UTC (permalink / raw)


http://www.adapower.com/ HTH G.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* help please
@ 2000-05-22  0:00 saju sathyan
  2000-05-22  0:00 ` Gautier
  0 siblings, 1 reply; 12+ messages in thread
From: saju sathyan @ 2000-05-22  0:00 UTC (permalink / raw)


 hi everybody,
                 I would like to know more about the ada language and like
to know where can I get the ada compiler and documentation.
 thank you

--
jags






^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help please
  2000-05-22  0:00 ` Gautier
@ 2000-05-23  0:00   ` saju sathyan
  0 siblings, 0 replies; 12+ messages in thread
From: saju sathyan @ 2000-05-23  0:00 UTC (permalink / raw)


thank you very much

--
jags
Gautier <gautier.demontmollin@maths.unine.ch> wrote in message
news:39294304.FF79FDC1@maths.unine.ch...
> http://www.adapower.com/ HTH G.






^ permalink raw reply	[flat|nested] 12+ messages in thread

* help please
@ 2001-12-16 15:27 Pierrick
  2001-12-16 18:27 ` Patrick Hohmeyer
  2001-12-16 19:46 ` Steve Doiel
  0 siblings, 2 replies; 12+ messages in thread
From: Pierrick @ 2001-12-16 15:27 UTC (permalink / raw)



   --I've declared this type :

type T_Tableau is array (integer range <>);
...

   --and this procedure :

function Plus_Petit (Table : T_Tableau) return Integer is
...

   --And after that, I create a table :

Table : T_Tableau (1..5);
...

begin
...

   --When i try to call my procedure with these parameters, it doesn't work (but no problem at compilation) :

Plus_Petit (Table (3..5));


Could you please tell my why ?
Sorry for my bad english :)


Pierrick









^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help please
  2001-12-16 15:27 help please Pierrick
@ 2001-12-16 18:27 ` Patrick Hohmeyer
  2001-12-16 19:46 ` Steve Doiel
  1 sibling, 0 replies; 12+ messages in thread
From: Patrick Hohmeyer @ 2001-12-16 18:27 UTC (permalink / raw)


Looks like a homework to me ...

No error in what you posted ...
You may find T'First, T'Last and T'Range interesting.

Aucune erreure dans le code montre.
Revise les attributs de type pour les tableaux,
surtout T'First, T'Last et T'Range. ;-)

-- 
Patrick Hohmeyer



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: help please
  2001-12-16 15:27 help please Pierrick
  2001-12-16 18:27 ` Patrick Hohmeyer
@ 2001-12-16 19:46 ` Steve Doiel
  1 sibling, 0 replies; 12+ messages in thread
From: Steve Doiel @ 2001-12-16 19:46 UTC (permalink / raw)


I think you're missing something in your example.  When I try to compile the
line:

  type T_Tableau is array (integer range <>);

I get the compile time error message:
  missing "OF"

Which I expect, since you must give the element type of the array.

SteveD

"Pierrick" <nospam_pierrickz@hotmail.com> wrote in message
news:3c1cbdb9$0$756$7402020d@newsfeed.sunrise.ch...
>
>    --I've declared this type :
>
> type T_Tableau is array (integer range <>);
> ...
>
>    --and this procedure :
>
> function Plus_Petit (Table : T_Tableau) return Integer is
> ...
>
>    --And after that, I create a table :
>
> Table : T_Tableau (1..5);
> ...
>
> begin
> ...
>
>    --When i try to call my procedure with these parameters, it doesn't
work (but no problem at compilation) :
>
> Plus_Petit (Table (3..5));
>
>
> Could you please tell my why ?
> Sorry for my bad english :)
>
>
> Pierrick
>
>
>
>
>
>





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-12-16 19:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-16 15:27 help please Pierrick
2001-12-16 18:27 ` Patrick Hohmeyer
2001-12-16 19:46 ` Steve Doiel
  -- strict thread matches above, loose matches on Subject: below --
2000-05-22  0:00 saju sathyan
2000-05-22  0:00 ` Gautier
2000-05-23  0:00   ` saju sathyan
     [not found] <36ab9be5.2873369@news.ptd.net>
1999-01-24  0:00 ` help Please Matthew Heaney
1999-01-26  0:00   ` Steve Kerr
1999-01-26  0:00     ` David C. Hoos, Sr.
1999-01-27  0:00       ` Steve Kerr
1999-01-27  0:00         ` Tucker Taft
1999-01-26  0:00   ` Simon Wright

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox