下载地址:https://download.csdn.net/download/qq_31293575/18340399
项目介绍
Pig Latin Lab The George Washington University Computer Science 1023 Professor Brenner (nbrenner@gwu.edu)
适用场景
毕业论文、课程设计、公司项目参考
系统说明
Pig Latin Lab
The George Washington University
Computer Science 1023
Professor Brenner (nbrenner@gwu.edu)
Create a webpage to translate words from English to Pig Latin. Pig Latin is a secret language used by American children to disguise their conversation from the ears of others. E.g. “Igpay Atinlay isway away ecretsay anguagelay.” The rule is to move all the initial consonants to the end of the word and add “ay”. If the word begins with a vowel (viz. one of “a”, “e”, “i”, “o”, or “u”), then just add “way”. So, “this” becomes “isthay” and “strong” becomes “ongstray”. Sample HTML:
Hints on implementation
- When retrieving the contents of a textbox with the .value property, remember that this is always a string. (And recall that the plus sign performs addition only if both its left and right argument are numbers; if either is a string, the two arguments are joined as strings.)
- Create a for loop which runs the number of times equal to the number of letters in the input word. On each turn of the loop, extract the next letter from the string of the word. Review the Javascript string functions, as described in the last handout.
- You will build up the output (Pig Latin) word one letter at a time, but you must also build up a string containing the initial consonants, also one letter at a time. Create a variable which is true while in the initial consonant group, but which changes to false when the first vowel is found. Then an if statement inside the for loop will look at this variable, and decide what to do with the current letter.
- Create a string to hold the five English (really Latin) vowels. E.g.:
vowels = "aeiou"
Then you can use string searching to determine if a letter taken from the input word is a vowel or not (or you could use a slower if statement).
- When you come to the end of the word (i.e. after the for loop finishes), create the complete Pig Latin word by joining the strings you created in step 3, and append the proper tail. Display it in the output text box.
- Don’t bother about UPPER CASE vs. lower case; assume only lower case (convert the examples I give in this handout, if you use them).
- [Optional, for advanced programmers] Three improvements can be made to this program.
- The input can be a sentence, i.e. of words separated by blanks. [Even more optionally, permit separation by punctuation marks like comma or period.]
- Input words can begin with the letter “q”. Since a following letter “u” may act as a consonant (viz. like a “w”), you must treat it as a consonant; examples: “quiet” → “ietquay”, “quality” → “alityquay”. But in names from the Middle East, “q” is a solo consonant: “Qatar” → “Atarqay” and “Qumran’ → “Umranqay”. And don’t forget about “qubit” (→ “ubitqay”).
- “y” is sometimes a vowel; e.g. “sky”, “hyper” (→ “yskay”, “yperhay”). How can you distinguish these from “yogurt” (→ “ogurtyay”), where “y” is a consonant?
运行截图
关注【程序代做 源码分享】公众号获取更多免费源码!!!