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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm The Name Game step by step in the XPL0 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 XPL0 programming language

Source code in the xpl0 programming language

proc PrintVerse(Name);
char Name;
int  I, Vowel;

    proc PrintLine(Str, Let);
    int  Str, Let;
    [Text(0, Str);
    if Name(0) # Let then ChOut(0, Let!$20);    \bary
    if Vowel then ChOut(0, Name(0)!$20);        \earl
    Text(0, Name+1);
    CrLf(0);
    ];

[Name(0):= Name(0) & ~$20;      \to uppercase
I:= 1;
while Name(I) do                \to lowercase
    [Name(I):= Name(I) ! $20;  I:= I+1];
case Name(0) of
    ^A,^E,^I,^O,^U: Vowel:= true
other Vowel:= false;
Text(0, Name);  Text(0, ", ");  Text(0, Name);
PrintLine(", bo-", ^B);
PrintLine("Banana-fana fo-", ^F);
PrintLine("Fee-fi-mo-", ^M);
Text(0, Name);  Text(0, "!^m^j^m^j");
];

int Names, I;
[Names:= ["gARY", "Earl", "Billy", "Felix", "Mary", "sHIRley"];
for I:= 0 to 6-1 do PrintVerse(Names(I));
]

  

You may also check:How to resolve the algorithm Arrays step by step in the Java programming language
You may also check:How to resolve the algorithm Variable declaration reset step by step in the Nim programming language
You may also check:How to resolve the algorithm Convert decimal number to rational step by step in the Clojure programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Nutt programming language
You may also check:How to resolve the algorithm First-class functions step by step in the BQN programming language