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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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-7-bit Received: by 10.68.135.231 with SMTP id pv7mr3246356pbb.8.1328863641940; Fri, 10 Feb 2012 00:47:21 -0800 (PST) Path: wr5ni8004pbc.0!nntp.google.com!news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!78.46.240.70.MISMATCH!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: Need Help On Ada95 Problem Date: Fri, 10 Feb 2012 08:47:20 +0000 Organization: A noiseless patient Spider Message-ID: References: <553ceec3-ec34-41de-9723-0dc342379cfe@vv9g2000pbc.googlegroups.com> Mime-Version: 1.0 Injection-Info: mx04.eternal-september.org; posting-host="dFCm8HWntFqmDIilBLqEJQ"; logging-data="1717"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+AO/7Uq4gJXcS982SNO7iy6BUFskbArpA=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (darwin) Cancel-Lock: sha1:EiiuVxpf0aP8/3Zr9qq0RHN8F9Y= sha1:XbVtx+MQOzSreblAxHnNgSjvYeY= Content-Type: text/plain; charset=us-ascii Date: 2012-02-10T08:47:20+00:00 List-Id: Shark8 writes: >> 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; Really, this is overkill. > 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. No, they want you to use the encoding as an array. But I think it would be better to use a character mapping: The_Ring : constant Ada.Strings.Maps.Character_Mapping := Ada.Strings.Maps.To_Mapping ("0123456789", "UROVALTINE"); function Encode (PIN : String) return String is begin return Ada.Strings.Fixed.Translate (PIN, The_Ring); end Encode; OK, if you encode 9537s you get ELVIs ... But we don't know what the professor feels about students who are too clever for their own good and have clearly been reading ahead in the textbook! (or asking for help on the net ...)