Question

COBOL Translate English to Pig Latin This interactive program translates any word the user enters into...

COBOL

  1. Translate English to Pig Latin

This interactive program translates any word the user enters into Pig Latin.

The interactive session

---------------------------------------------

Enter any word to see what it looks like in Pig Latin.
To quit, type Uitqay.

---------------------------------------------

string
The Pig Latin equivalent is: Ingstray
---------------------------------------------
unstring
The Pig Latin equivalent is: Unstringlay
---------------------------------------------
Uitqay Oodbyegay!

Specifications

• If the word starts with a consonant, move the consonants before the first vowel to the end of the word and add ay. If the word starts with a vowel, just add lay to the end of the word.

• The word entered can be up to 15 characters long, and the Pig Latin equivalent can be up to 18 characters long. The Pig Latin equivalent should start with an uppercase letter and be followed by all lowercase letters. If a user enters more than one word, translate just the first word.

• To end the program, the user must type the word Uitqay, which is Pig Latin for Quit.

Homework Answers

Answer #1

Pig Latin is an encryption of an English word obtain by following certain steps.

1. Find the first vowel in the string.

2. Split the string into two halves from the index of first vowel. one is part before the vowel other is part after the vowel.

3. Part before a vowel is now shifted to the end of the string. Behind part after a vowel in the string.

4. Add 'ay' in the end of the string and you word is ready.

5. If the vowel is encounter as the first letter no need to split just add 'ay' at the end and the word is ready.

I write a python program to demonstrate it.

*bold and Italics are comments showing what a set of command is doing

# Checking the first vowel in the string.
# It returns the true value when encounter the first vowel in string.

def check_vowel(character):
return (character == 'A' or character == 'E' or character == 'I' or character == 'O' or
character == 'U' or character == 'a' or character == 'e' or character == 'i' or
character == 'o' or character == 'u')

# Converting string into pig latin.
# The string splits from the point where it finds its first vowel.
# After spliting the starting string before the vowel concatenates at the add and 'ay' is added in end.
# If any string contains a vowel at the start it doesn't split. It gets print as it is with an addition on 'ay' at the end.

def convert_pig_latin(string):
  
# initializing index for the condition.
index = -1
  
# conversion on string into pig latin.
for i in range(len(string)):
  
# checking for the first vowel.
# as this value gets true from function, if condition executes it update index of vowel to initial index for split.

if(check_vowel(string[i])):
index = i
break
  
# return '-1' if conversion is not possible.
if(index == -1):
return -1
  
# return 'converted_string' if conversion is possible.
return string[index:index+1].upper() + string[index+1:] + string[0:index] + 'ay'

# Main Function input and output.
# Infinite while loop make it continuously working till it doesn't get terminating condition.

def main():
  
print("Enter any word to see what it looks like in Pig Latin.\nTo quit, type Uitqay")
  
# infinite loop for performing task again and again.
while True:
  
# input the string.
string = input()

  # if condition match then code is exit saying goodbye in pig latin else it continues.
if string == 'Uitqay' or string == 'uitqay':
print("Oodbyegay!")
break

else:

  # converting string to pig latin.
converted_string = convert_pig_latin(string)
if(converted_string == -1):
print("Invalid String. Please enter vaild string\nTo quit, type Uitqay")
else:
print("The Pig Latin equivalent is: ",converted_string)

if __name__ == '__main__':
main()

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions