How to resolve the algorithm Old lady swallowed a fly step by step in the Ada programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Old lady swallowed a fly step by step in the Ada programming language
Table of Contents
Problem Statement
Present a program which emits the lyrics to the song I Knew an Old Lady Who Swallowed a Fly, taking advantage of the repetitive structure of the song's lyrics. This song has multiple versions with slightly different lyrics, so all these programs might not emit identical output.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Old lady swallowed a fly step by step in the Ada programming language
Source code in the ada programming language
with Ada.Text_IO, Ada.Containers.Indefinite_Doubly_Linked_Lists; use Ada.Text_IO;
procedure Swallow_Fly is
package Strings is new Ada.Containers.Indefinite_Doubly_Linked_Lists(String);
Lines, Animals: Strings.List;
procedure Swallow(Animal: String;
Second_Line: String;
Permanent_Second_Line: Boolean := True) is
procedure Print(C: Strings.Cursor) is
begin
Put_Line(Strings.Element(C));
end Print;
begin
Put_Line("There was an old lady who swallowed a " & Animal & ",");
Put_Line(Second_Line);
if not Animals.Is_Empty then
Lines.Prepend("She swallowed the " & Animal & " to catch the " &
Animals.Last_Element & ",");
end if;
Lines.Iterate(Print'Access);
New_Line;
if Permanent_Second_Line then
Lines.Prepend(Second_Line);
end if;
Animals.Append(Animal); -- you need "to catch the " most recent animal
end Swallow;
procedure Swallow_TSA(Animal: String; Part_Of_Line_2: String) is
begin
Swallow(Animal, Part_Of_Line_2 &", to swallow a " & Animal & ";", False);
end Swallow_TSA;
procedure Swallow_SSA(Animal: String; Part_Of_Line_2: String) is
begin
Swallow(Animal, Part_Of_Line_2 &" she swallowed a " & Animal & ";", False);
end Swallow_SSA;
begin
Lines.Append("Perhaps she'll die!");
Swallow("fly", "But I don't know why she swallowed the fly,");
Swallow("spider", "That wriggled and jiggled and tickled inside her;");
Swallow_TSA("bird", "Quite absurd");
Swallow_TSA("cat", "Fancy that");
Swallow_TSA("dog", "What a hog");
Swallow_TSA("pig", "Her mouth was so big");
Swallow_TSA("goat","She just opened her throat");
Swallow_SSA("cow", "I don't know how");
Swallow_TSA("donkey", "It was rather wonky");
Put_Line("There was an old lady who swallowed a horse ...");
Put_Line("She's dead, of course!");
end Swallow_Fly;
You may also check:How to resolve the algorithm Sudoku step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Pangram checker step by step in the Cowgol programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Befunge programming language
You may also check:How to resolve the algorithm Arithmetic/Complex step by step in the Slate programming language
You may also check:How to resolve the algorithm GSTrans string conversion step by step in the ALGOL 68 programming language