comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Subtypes with Combined Ranges
Date: Thu, 18 Jul 2002 13:15:35 +0000 (UTC)
Date: 2002-07-18T13:15:35+00:00	[thread overview]
Message-ID: <slrnajdfrj.om.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: 3D36BD1F.9000101@yahoo.com

* David Rasmussen wrote:
>6.1 Write a program to count the number of occurrences of each letter of
>    the alphabet typed as input at the keyboard. Using a subtype of
>    Character as the index subtype of an array is a sensible way to do
>    this.

>My first thought was to do this:
>subtype Alphabetical is Character range 'A'..'Z' | 'a'..'z';

A subtype has to be holefree.

>But I get an error. What is the best type for this excercise?

There are multiple solutions:
  - subtype Uppercase is Character range 'A' .. 'Z';
    subtype Lowercase is Character range 'a' .. 'z';
  - lettertest : array (Character) of Boolean :=
      ('A' .. 'Z' | 'a' .. 'z' => True, others => False);
  - lettermap : Ada.Strings.Maps.Character_Set :=
      To_Set (((Low => 'a', High => 'z'), (Low => 'A', High => 'Z')));
  - and many more.

Because you post your exercise here, you will get an other one:
 Implement at least ten different algorithms which print the elementary
 multiplication table. Post them here in two weeks.
 



  reply	other threads:[~2002-07-18 13:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-18 13:05 Subtypes with Combined Ranges David Rasmussen
2002-07-18 13:15 ` Lutz Donnerhacke [this message]
2002-07-18 13:44 ` Jacob Sparre Andersen
2002-07-18 14:48   ` David Rasmussen
replies disabled

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