C# :: Aufgabe #137 :: Lösung #6

Pig Latin - Schweine Latein
Einführung:
Zitat:
Pig Latin (engl.; wörtlich: Schweine-Latein) bezeichnet eine Spielsprache, die im englischen Sprachraum verwendet wird.
Sie wird vor allem von Kindern benutzt, aus Spaß am Spiel mit der Sprache oder als einfache Geheimsprache, mit der Informationen vor Erwachsenen oder anderen Kindern verborgen werden sollen.
Erklärung:
Zitat:
Beginnt das Wort mit einem Konsonanten, so wird der initiale Konsonant oder Konsonantencluster ans Ende des Wortes verschoben und ein „ay“ angehängt. Zu betrachten ist hierbei nicht die Rechtschreibung, sondern die tatsächliche Aussprache: „Stumme“ Konsonantenbuchstaben, wie z. B. das „h“ in „honor“, sind keine Konsonanten.
loser → oser-lay
button → utton-bay
star → ar-stay
three → ee-thray
question → estion-quay
happy → appy-hay
Pig Latin → Ig-pay Atin-lay
Beginnt das Wort mit einem Vokal oder einem stummen Konsonanten, so wird direkt ein „ay“ angehängt.
eagle → eagle-ay
America → America-ay
honor → honor-ay
Aufgabe:
Schreibt ein Programm welches ein belibiges Wort ins Schweine Latein umwandelt und ausgibt. Auf die Regel mit Stummen H's kann man verzichten.


using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Geheimsprache { class Program { static void Main(string[] args) { Console.WriteLine("Welches Wort möchtest Du umwandeln?"); string wort = Console.ReadLine().ToUpper(); char anfangsbuchstabe = wort.First(); string ersteZweiBuchstaben = wort.Substring(0, 2); string ersteDreiBuchstaben = wort.Substring(0, 3); bool schleife = true; if (schleife == true) { schleife = CheckIfVocal(anfangsbuchstabe, wort); } if (schleife == true) { schleife = CheckIfException3(ersteDreiBuchstaben, wort); } if (schleife == true) { schleife = CheckIfException(ersteZweiBuchstaben, wort); } if (schleife == true) { schleife = CheckIfConsonant(anfangsbuchstabe, wort); } } static bool CheckIfException3 (string firstThreeLetters, string word) { string exception = "SCH"; bool loop = true; if (firstThreeLetters == exception) { Console.WriteLine(word.Remove(0, 3) + firstThreeLetters + "AY"); Console.ReadKey(); loop = false; } return loop; } static bool CheckIfException(string firstTwoLetters, string word) { string[] exceptions = { "ST", "TH", "QU" }; bool loop = true; for (int count = 0; count < 3; count++) { if (firstTwoLetters == exceptions[count]) { Console.WriteLine(word.Remove(0, 2) + firstTwoLetters + "AY"); Console.ReadKey(); loop = false; } } return loop; } static bool CheckIfConsonant(char firstLetter, string word) { char[] consonants = { 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z' }; bool loop = true; for (int count = 0; count < 21; count++) { if (firstLetter == consonants[count]) { Console.WriteLine(word.Remove(0, 1) + firstLetter + "AY"); Console.ReadLine(); loop = false; } } return loop; } static bool CheckIfVocal(char firstLetter, string word) { char[] vocals = { 'A', 'E', 'I', 'O', 'U' }; bool loop = true; for (int count = 0; count < 5; count++) { if (firstLetter == vocals[count]) { Console.WriteLine(word + "AY"); Console.ReadKey(); loop = false; } } return loop; } } }
Kommentare:
Für diese Lösung gibt es noch keinen Kommentar