Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 1 min read

Support

Computing » Computer Science » Computer Programming » Ada Programming

Chapter 1: Introduction

The following subprograms are implementations of the Inventing an Algorithm examples.

To Lower

The Ada example code does not append to the array as the algorithms. Instead we create an empty array of the desired length and then replace the characters inside.

File: to_lower_1.adb (view, plain text, download page, browse all)

function To_Lower (C : Character) return Character renames
Ada.Characters.Handling.To_Lower;

-- tolower - translates all alphabetic, uppercase characters
-- in str to lowercase
function To_Lower (Str : String) return String is
Result : String (Str'Range);
begin
for C in Str'Range loop
Result (C) := To_Lower (Str (C));
end loop;
return Result;
end To_Lower;

Would the append approach be impossible with Ada? No, but it would be significantly more complex and slower.

Equal Ignore Case

File: to_lower_2.adb (view, plain text, download page, browse all)

-- equal-ignore-case -- returns true if s or t are equal,
-- ignoring case
function Equal_Ignore_Case
(S  : String;
T  : String)
return Boolean
is
O : constant Integer := S'First - T'First;
begin
if T'Length /= S'Length then
return False; -- if they aren't the same length, they
-- aren't equal
else
for I in S'Range loop
if To_Lower (S (I)) /=
To_Lower (T (I + O))
then
return False;
end if;
end loop;
end if;
return True;
end Equal_Ignore_Case;

Where this page came from

This page was imported from Wikibooks. From “Ada Programming” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.

Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.

Comments

Spinner Logo

Next in Ada Programming

CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( ## Chapter 6: Dynamic Programming ### Fibonacci numbers The following codes are implementations of the [Fibonacci-Numbers examples]( ### Simple Implementation File: fibonacci_1.adb ([view]( [plain text]( [download page
CC BY-SA 4.0
File: Algorithms/pattern_match_knuth_morris_pratt_test.adb ([view]( [plain text]( [download page]( [browse all]( -- pattern_match_knuth_morris_pratt_test.adb an implementation for fixed strings -- Written by Wikibob, 2004, from notes on the Knuth_Morris_Pratt pattern match algorithm -- adapted to fi
CC BY-SA 4.0
File: error_handling_2.adb ([view]( [plain text]( [download page]( [browse all]( [procedure]( Error_Handling_2 [is]( [procedure]( Square_Root (Y : [out]( Float; X : [in]( Float; Success : [out]( Boolean) [is]( [use]( Ada.Numerics.Elementary_Functions; [begin]( [if]( X < 0.0 [then]( Y := 0.0; Success
CC BY-SA 4.0
[Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( ## Description **Function overloading** (also method overloading) is a programming concept that allows programmers to define two or more functions with the same name and in the same scope. Each function has a unique si
CC BY-SA 4.0
This computer programming article is available for [pseudocode]( and Ada. [Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( Ada is very well suited for all kinds of calculations. You can define your own fixed point and floating point types and — with the aid of generi
CC BY-SA 4.0
This computer programming article is available in [pseudocode]( Ada, [C]( [C++]( and [Delphi]( [Computing]( » [Computer Science]( » [Computer Programming]( » [Ada Programming]( Note: there are some simplifications in the explanations below. Don't take anything too literally. Most programming languag