How to resolve the algorithm Old lady swallowed a fly step by step in the FutureBasic 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 FutureBasic 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 FutureBasic programming language
Source code in the futurebasic programming language
include "NSLog.incl"
begin enum output
_firstAnimal = 0
_lastAnimal = 7
end enum
local fn OldLadySwallowedAFly
NSUInteger i, j, numberOfAnimals
CFMutableStringRef mutStr = fn MutableStringWithCapacity( 0 )
NSLogClear
CFArrayRef animals = @[@"fly", @"spider", @"bird", @"cat", @"dog", @"goat", @"cow", @"horse.."]
CFArrayRef verses = @[@"",¬
@"I don't know why she swallowed the fly — perhaps she'll die!\n",¬
@"That wriggled and jiggled and tickled inside her.",¬
@"How absurd, to swallow a bird!",¬
@"Imagine that, she swallowed a cat!",¬
@"What a hog to swallow a dog!",¬
@"She just opened her throat and swallowed that goat!",¬
@"I wonder how she swallowed a cow?",¬
@"She's dead, of course!"]
numberOfAnimals = len(animals)
for i = 0 to numberOfAnimals -1
NSLog( @"There was an old lady who swallowed a %@.", animals[i] ) : MutableStringAppendFormat( mutStr, @"There was an old lady who swallowed a %@.\n", animals[i] )
if i == _firstAnimal then NSLog( @"%@", verses[1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[1] ) : continue
if i > _firstAnimal then NSLog( @"%@", verses[i+1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[i+1] )
if i == _lastAnimal then break
if ( i > 0 )
for j = i to 1 step -1
CFStringRef p
if fn StringIsEqual( animals[j-1], @"fly" ) then p = @"." else p = @","
NSLog( @"\tShe swallowed the %@ to catch the %@%@", animals[j], animals[j-1], p ) : MutableStringAppendFormat( mutStr, @"\tShe swallowed the %@ to catch the %@%@\n", animals[j], animals[j-1], p )
if j == 2 then NSLog(@"\tThat wriggled and jiggled and tickled inside her.") : MutableStringAppendString( mutStr, @"\tThat wriggled and jiggled and tickled inside her.\n" )
if j == 1 then NSLog( @"%@", verses[1] ) : MutableStringAppendFormat( mutStr, @"%@\n", verses[1] ) : break
next
end if
next
SpeechSynthesizerRef ref = fn SpeechSynthesizerWithVoice( @"com.apple.speech.synthesis.voice.daniel.premium" )
fn SpeechSynthesizerStartSpeakingString( ref, mutStr )
end fn
fn OldLadySwallowedAFly
HandleEvents
You may also check:How to resolve the algorithm Monty Hall problem step by step in the Raku programming language
You may also check:How to resolve the algorithm Hilbert curve step by step in the C programming language
You may also check:How to resolve the algorithm Hello world/Line printer step by step in the Java programming language
You may also check:How to resolve the algorithm String comparison step by step in the Java programming language
You may also check:How to resolve the algorithm Loops/Increment loop index within loop body step by step in the Delphi programming language