From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.5 required=5.0 tests=BAYES_05,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7ba49aac4e73460 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.68.231.202 with SMTP id ti10mr137380pbc.5.1328752966010; Wed, 08 Feb 2012 18:02:46 -0800 (PST) Path: wr5ni3242pbc.0!nntp.google.com!news2.google.com!postnews.google.com!vv9g2000pbc.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Need Help On Ada95 Problem Date: Wed, 8 Feb 2012 18:01:16 -0800 (PST) Organization: http://groups.google.com Message-ID: <553ceec3-ec34-41de-9723-0dc342379cfe@vv9g2000pbc.googlegroups.com> References: NNTP-Posting-Host: 24.230.151.194 Mime-Version: 1.0 X-Trace: posting.google.com 1328752965 27408 127.0.0.1 (9 Feb 2012 02:02:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 9 Feb 2012 02:02:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: vv9g2000pbc.googlegroups.com; posting-host=24.230.151.194; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUALESNKRC X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1,gzip(gfe) Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-02-08T18:01:16-08:00 List-Id: On Feb 8, 7:03=A0pm, Will wrote: > I am new to Ada and need help on an exercise for school. =A0Can anyone > help. =A0The problem is as follows ( you can skip all the build up > background A Christmas Story references): > > Problem 1: Secret Decoder Ring > > You may remember Ralphie's disappointment when he received his Little > Orphan Annie Secret Decoder Ring. > What you may not realize is that, after Ralphie threw away his ring, > his brother Randy dug it out of the trash. Randy grew up to run the IT > department of his small hometown bank, and was responsible for storing > the 4-digit Personal Identification Numbers (PINs) chosen by his > bank's customers. He knew better than to store these PINs in the > clear, so he encrypted them using Ralphie's ring. > > The decoder ring had two wheels, one printed with letters and one > printed with numbers. In the video clip, you see Ralphie decoding the > numbers read on the radio, looking up each number and copying down the > corresponding letter. Randy uses the ring in a similar way, but > instead of disguising letters as numbers, he does the reverse, > disguising numbers as letters. To encrypt a PIN, he finds each digit > on the wheel, and turns it into a letter. (The ring contains some two- > digit numbers as well, but he ignores those, using only the single- > digit numbers.) > > Here is a small portion of the decoder ring: > > =A0 =A0 =A0number wheel -> =A0 =A00 =A01 =A02 =A03 =A04 =A05 =A06 =A07 = =A08 =A09 > =A0 =A0 =A0letter wheel -> =A0 =A0U =A0R =A0O =A0V =A0A =A0L =A0T =A0I = =A0N =A0E > > 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. So start by describing things in terms of types. Type Cypher_Character is Private; Type Pin_Character is Private; Type Pin_String is Array(1..4) of Pin_Character; --- Later in the private section. Type Cypher_Character is new Character; Type Pin_Character is new Character; In this mindset things become crystal clear: this is merely type- conversion. So you'll need a conversion function, something like: Function Convert_Pin_Character( Item : In Pin_Character ) Return Cypher_Character; with an implementation of: Function Convert_Pin_Character( Item : In Pin_Character ) Return Cypher_Character is begin Return Result : Cypher_Character do ----- ACTUAL CONVERSION GOES HERE end return; end; 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.