The purpose of this assignment is to help gauge your skills in writing small pro
ID: 3824865 • Letter: T
Question
The purpose of this assignment is to help gauge your skills in writing small programs that involve vectors and/or c-string/string arrays.The program also contains functions and may perform input, output, files and file processing, flow of control, and/or calculations. Please note that this assignment indicates precisely what your program should accomplish, without a precise indication of how the program works. Part of your assignment is designing the techniques of how the program works.
PROGRAM SPECIFICATION
Write a program that reads an input file of sentences and converts each word to “Pig Latin.” In this program’s version, to convert a word to Pig Latin, you should remove the first letter and place that letter at the end of the word. Then you append the string “ay” to the word.
Here is an example:
English: I SLEPT MOST OF THE NIGHT
Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY
Here is what this program should output in English and Piglatin:
For this program, you will download the ASSGN8-A.txt file. This file contains the English statements we will use for our program. Your program should list (output to the console) the English version from the file, and then the pig latin version (as illustrated above).
Explanation / Answer
function translatePigLatin(str) {
var strArr = [];
var tmpChar;
function isConsonant(char) {
return !/[aeiou]/.test(char);
}
if (!isConsonant(str.charAt(0)))
return str + "way";
else
strArr = str.split("");
while (isConsonant(strArr[0])) {
tmpChar = strArr.shift();
strArr.push(tmpChar);
}
return strArr.join("")+"ay";
}
translatePigLatin("consonant");
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.