From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Need Help On Ada95 Problem
Date: Wed, 8 Feb 2012 18:01:16 -0800 (PST)
Date: 2012-02-08T18:01:16-08:00 [thread overview]
Message-ID: <553ceec3-ec34-41de-9723-0dc342379cfe@vv9g2000pbc.googlegroups.com> (raw)
In-Reply-To: a5adb33b-96ba-4f48-adfa-9a01e1d42a7d@j14g2000vba.googlegroups.com
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
>
> 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:
>
> 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.
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.
next prev parent reply other threads:[~2012-02-09 2:02 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 [this message]
2012-02-10 1:36 ` BrianG
2012-02-10 2:22 ` Shark8
2012-02-10 5:32 ` Alex
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