comp.lang.ada
 help / color / mirror / Atom feed
From: "Alex" <alex@foo.invalid>
Subject: Re: Need Help On Ada95 Problem
Date: Fri, 10 Feb 2012 05:32:07 +0000 (UTC)
Date: 2012-02-10T05:32:07+00:00	[thread overview]
Message-ID: <jh2a4n$kmn$1@dont-email.me> (raw)
In-Reply-To: 4ea6309f-cf07-44f6-8c56-5189a0081dcc@g27g2000yqa.googlegroups.com

Sure you can just use 'Pos! While the positions of the digit characters
do not correspond directly to their values, they are sequential in the
ASCII mapping, so all you have to do is subtract the position of the
Character '0' from each one to calculate its value. Check it out:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Main is

begin

   for I in Character'('0') .. Character'('9') loop
      Put(Character'Pos(I) - Character'Pos('0'));
      New_Line;
   end loop;

end Main;



Shark8 wrote:

> On Feb 9, 7:36�pm, BrianG <m...@null.email> wrote:
> > On 02/08/2012 09:01 PM, Shark8 wrote:
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > > On Feb 8, 7:03 pm, Will<willmann...@gmail.com> �wrote:
> > >> I am new to Ada and need help on an exercise for school. �Can
> > anyone >> help. �The problem is as follows ( you can skip all the
> > build up >> background A Christmas Story references):
> > 
> > >> Problem 1: Secret Decoder Ring
> > ...
> > >> � � � number wheel -> � � �0 �1 �2 �3 �4 �5 �6 �7 �8 �9
> > >> � � � letter wheel -> � � �U �R �O �V �A �L �T �I �N �E
> > 
> > >> So, for example, Randy encrypts the PIN 9537 as ELVI.
> > 
> > >> Complete the function Encrypt(PIN) that takes a 4-digit PIN (as a
> > >> string) and returns the corresponding 4-letter code (also as a
> > >> string).
> > 
> > >> Note: It would be possible to convert digits to letters using a
> > giant >> IF statement, but don't do this. Instead, the letter wheel
> > is given to >> you as a string, so use each digit to read the
> > appropriate letter from >> the string.
> > 
> > > Alright this is actually a simple problem; there are several ways
> > > to go about this,
> > > but let's play to Ada's strengths and use types.
> > 
> > ...
> > > Reading the problem the note says:
> > > It would be possible to convert digits to letters using a giant
> > > IF statement, but don't do this. Instead, the letter wheel is
> > > given to you as a string, so use each digit to read the
> > > appropriate letter from the string.
> > 
> > > Meaning that they're hinting strongly that you use the CASE
> > > statement.
> > 
> > I don't see why this would require either an if or a case.
> > 
> > --
> > ---
> > BrianG
> > 000
> > @[Google's email domain]
> > .com
> 
> Well, you COULD use Ada's Maps; but that's just going to do the same
> thing: you still have to define the mapping.
> You can't just index into Character (via 'POS, 'VAL and index-
> manipulation) because the mapping isn't sequential;
> or even partly-sequential in the ASCII codes.
> 
> See the (3,4,5) association with (V,A,L) and (6,7,8) with (T,I,N).



  reply	other threads:[~2012-02-10  5:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-09  1:03 Need Help On Ada95 Problem Will
2012-02-09  1:51 ` Robert A Duff
2012-02-09  2:01 ` Shark8
2012-02-10  1:36   ` BrianG
2012-02-10  2:22     ` Shark8
2012-02-10  5:32       ` Alex [this message]
2012-02-10 15:19         ` Shark8
2012-02-10 15:45           ` Alex
2012-02-10 20:07           ` Robert A Duff
2012-02-12 19:40             ` Will
2012-02-12 19:42               ` Will
2012-02-12 22:26               ` Robert A Duff
2012-02-13  0:41                 ` Will
2012-02-13  0:43                 ` Nasser M. Abbasi
2012-02-10  5:45       ` Alex
2012-02-10 13:29         ` Robert A Duff
2012-02-10 13:50           ` Alex
2012-02-10 14:30             ` Robert A Duff
2012-02-10 15:32               ` Alex
2012-02-10 20:03                 ` Robert A Duff
2012-02-13  3:28       ` BrianG
2012-02-10  8:47   ` Simon Wright
2012-02-09  3:38 ` Alex
     [not found]   ` <90a10801-440b-4a31-88d0-f0f7c17137f1@eb6g2000vbb.googlegroups.com>
2012-02-09 13:35     ` Alex
replies disabled

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