How to resolve the algorithm The Name Game step by step in the Delphi programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm The Name Game step by step in the Delphi programming language

Table of Contents

Problem Statement

Write a program that accepts a name as input and outputs the lyrics to the Shirley Ellis song "The Name Game".

The regular verse Unless your name begins with a vowel (A, E, I, O, U), 'B', 'F' or 'M' you don't have to care about special rules. The verse for the name 'Gary' would be like this: At the end of every line, the name gets repeated without the first letter: Gary becomes ary If we take (X) as the full name (Gary) and (Y) as the name without the first letter (ary) the verse would look like this: Vowel as first letter of the name If you have a vowel as the first letter of your name (e.g. Earl) you do not truncate the name. The verse looks like this: 'B', 'F' or 'M' as first letter of the name In case of a 'B', an 'F' or an 'M' (e.g. Billy, Felix, Mary) there is a special rule. The line which would 'rebuild' the name (e.g. bo-billy) is sung without the first letter of the name. The verse for the name Billy looks like this: For the name 'Felix', this would be right:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm The Name Game step by step in the Delphi programming language

Source code in the delphi programming language

function WaitForString(Memo: TMemo; Prompt: string): string;
{Wait for key stroke on TMemo component}
var KW: TKeyWaiter;
begin
{Use custom object to wait and capture key strokes}
KW:=TKeyWaiter.Create(Memo);
try
Memo.Lines.Add(Prompt);
Memo.SelStart:=Memo.SelStart-1;
Memo.SetFocus;
Result:=KW.WaitForString;
finally KW.Free; end;
end;


procedure NameGame(Memo: TMemo);
var Name: string;
var Str2: string;
var FL: Char;

	function GetPattern: string;
	var BStr,FStr,MStr: string;
	begin
	if FL='b' then BStr:='bo-' else BStr:='bo-b';
	if FL='f' then FStr:='fo-' else FStr:='fo-f';
	if FL='m' then MStr:='mo-' else MStr:='mo-m';
	Result:=Format('%S, %S, %S%S',[Name,Name,BStr,Str2])+CRLF;
	Result:=Result+Format('Banana-fana %S%S',[FStr,Str2])+CRLF;
	Result:=Result+Format('Fee-fi-%S%S',[MStr,Str2])+CRLF;
	Result:=Result+Format('%S!',[Name])+CRLF;
	end;

begin
while true do
	begin
	Name:=WaitForString(Memo,'Enter a name: ');
	if Name='' then break;
	Str2:=LowerCase(Name);
	FL:=Str2[1];
	if not (FL in ['a','e','i','o','u']) then Delete(Str2,1,1);

	Memo.Lines.Add(GetPattern);
	end;
end;


  

You may also check:How to resolve the algorithm Multiplication tables step by step in the Clojure programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Vigenère cipher step by step in the Nim programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Ada programming language
You may also check:How to resolve the algorithm Monte Carlo methods step by step in the Icon and Unicon programming language