41.5k views
2 votes
Write a program in C# : Pig Latin is a nonsense language. To create a word in pig Latin, you remove the first letter and then add the first letter and "ay" at the end of the word. For example, "dog" becomes "ogday" and "cat" becomes "atcay". Write a GUI program named PigLatinGUI that allows the user to enter a word and displays the pig Latin version.

1 Answer

3 votes

Answer:

The csharp program is as follows.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

string word = textBox1.Text;

string ch = word.Substring(0, 1);

string str = word.Substring(1, word.Length-1);

string s = str.Insert(str.Length, ch);

textBox2.Text = s.Insert(s.Length, "ay");

}

private void button3_Click(object sender, EventArgs e)

{

Close();

}

private void button2_Click(object sender, EventArgs e)

{

textBox1.Text = "";

textBox2.Text = "";

}

}

}

Step-by-step explanation:

1. A string variable to hold the user input is declared and initialized accordingly. The user inputted string is taken from textbox1.

string word = textBox1.Text;

2. A string variable to hold the first character of the user inputted string is declared and initialized.

string ch = word.Substring(0, 1);

3. A string variable to hold the user inputted string without the first character is declared and initialized accordingly.

string str = word.Substring(1, word.Length-1);

4. A string variable to hold the substring from step 3 along with the inserted characters at the end, is declared and initialized accordingly.

string s = str.Insert(str.Length, ch);

5. The final string is assigned to the textbox 2, which is the PigLatin conversion of the user inputted string.

textBox2.Text = s.Insert(s.Length, "ay");

6. All the above take place when the user clicks Convert to PigLatin button.

7. Two additional buttons, clear and exit are also included in the form.

8. When the user clicks clear button, both the textboxes are initialized to empty string thus clearing both the textboxes.

textBox1.Text = "";

textBox2.Text = "";

9. When the user clicks the exit button, the application closes using the Close() method.

10. The program is done in Visual Studio.

11. The output of the program is attached.

12. The program can be tested for any type of string and any length of the string.

Write a program in C# : Pig Latin is a nonsense language. To create a word in pig-example-1
User Chaochana
by
3.5k points