How to resolve the algorithm The Twelve Days of Christmas step by step in the Delphi programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm The Twelve Days of Christmas step by step in the Delphi programming language
Table of Contents
Problem Statement
Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas.
The lyrics can be found here.
(You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm The Twelve Days of Christmas step by step in the Delphi programming language
Source code in the delphi programming language
const GiftList: array [0..11] of string =(
'a partridge in a pear tree.',
'Two turtle doves',
'Three french hens',
'Four calling birds',
'Five golden rings',
'Six geese a-laying',
'Seven swans a-swimming',
'Eight maids a-milking',
'Nine ladies dancing',
'Ten lords a-leaping',
'Eleven pipers piping',
'Twelve drummers drumming');
const Cardinals: array [0..11] of string =
('first','second','third','forth',
'fifth','sixth','seventh','eight',
'ninth','tenth','eleventh','twelfth');
procedure DoOneDay(Memo: TMemo; Day: integer);
var S: string;
var I: integer;
begin
S:='On the '+Cardinals[Day]+' of Christmas ';
S:=S+'my true love gave to me'+CRLF;
for I:=Day downto 0 do
begin
if (Day>0) and (I=0) then S:=S+'and ';
S:=S+GiftList[I]+CRLF;
end;
Memo.Lines.Add(S);
end;
procedure TwelveDaysOfChristmas(Memo: TMemo);
var I: integer;
begin
for I:=0 to 12-1 do DoOneDay(Memo,I);
end;
You may also check:How to resolve the algorithm Tokenize a string step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Repeat step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Erlang programming language
You may also check:How to resolve the algorithm Random number generator (included) step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Word wrap step by step in the Nim programming language