Question: Using C++ to solve the problem In this problem, you will be translating the Gettysburg address into pig latin (more details below). We will proceed
Using C++ to solve the problem
In this problem, you will be translating the Gettysburg address into pig latin (more details below). We will proceed in several steps.
1. Write a function called is alpha which inputs a character and returns a bool. It should return true if the input is a letter. (Make sure it works for both upper and lower case.) 2. Write a function called is_punc which inputs a character and returns a bool. It should return true if the input is any of the following punctuation marks: open parenthesis, closed parenthesis, period, comma, exclamation point, semicolon, colon, question mark, double quote, or single quote and return false otherwise. 3. Write a procedure called make_lower which inputs a string and changes all upper case letters to lower case. For example, if s = Tom the Turtle" then after the procedure is called we should have s = tom the turtle" 4. Write a function called words which inputs one large string (use reference to a const) and returns a vector of strings. Each of the entries of the vector should be a word from the original string. There should be no spaces in the vector, but if a word is immediately followed by punctuation, you should keep that punctuation at the end of the word. So for example, if input string was Isnt the weather lovely today!? Unrelatedly, would you like some coffee? The function words should return a vector of strings of length 11. The 11 strings should be Isnt the weather lovely today!? Unrelatedly, would you like some and coffee? 5. Write a function word_to_PL which inputs a string (use reference to a constant) and returns a string. This return string should be the original string translated into pig latin (see below). Make sure to keep punctuation in the correct spot so if the input is today!? Then the return value should be odaytay!? Similarly, if the input is isnt the output should be isntay (It may be helpful to write a helper function called is_vowel.) You may assume that the first character of each word is a letter. 6. Write a function vec_to_PL which inputs a vector of strings (where each string is a single word) and translates each word to pig latin. This function should input a vector of strings (use reference to a const) and return a vector of strings. It should almost definitely use word_to_PL as a helper function. 7. Write a function called build paragraph which inputs a vector of strings (use reference to a const) and returns a single string. The return string is created by concatenating the entries of the vector, but inserting a single space in between words. For example, if the input vector was {cats,, dogs,, and, giraffes.} the return string would be cats, dogs, and giraffes. 8. Now, download the file Gettysburg.txt from CCLE and save it in the same folder as your .cpp file. Use an input stream to read in the contents of the file and save it as a single string. You should be able to do this with a single getline. (See class notes on Input/Output from 11/30.) Make sure to use the Gettysburg.txt file I post on CCLE. (Dont just find another copy of the Gettysburg address on the internet.) I have done some mild preprocessing of the file to make your life easier. 9. Use the above functions to transform this string into a vector, translate it into pig latin, and then put it back together into a single string. 10. Use an output stream to write the new string in a file called ettysburggay.txt (Dont forget the double g.)
The Rules of Pig Latin: For the purpose of this assignemnt, the rules of pig latin are as follows. 1. The letters a, e, i, o, u are always vowels and all other letters are consonants. In particular, y is always a consonant. (Upper case vowels are also vowels.) 2. If the first letter of a word is a consonant, remove the first letter of the word, add it to the end, and then add ay. So for example, pig latin and gettysburg become igpay atinlay and ettysburggay (note the double g) 3. If the first letter of a word is a vowel, and the last letter is a consonant, just add the letters ay to the end so the words if arc and animal become ifay arcay and animalay 4. If the first letter of a word is a vowel and the last letter is also a vowel, then add the letters yay to the end so area i and auto becomeareayay iyay and autoyay 5. There are no uppercase letters in pig latin, so use the procedure make lower to make everything lowercase. I recommend doing this immediately after you read in the one very long string (i.e. step 8).
Some remarks: 1. The actual rules of pig latin are slightly different. I have modified them to avoid making this assignment longer than it already is. 2. It is a good idea to test each function after you write it. For this purpose, it might be a good idea to build a print function which prints a vector of strings. (This is optional.) You should also check that if you take a long string, first apply words and then apply build paragraph, you get the original string back. (This will work as long as there arent multiple spaces in a row in the original string.) 3. We are using the Gettysburg Address for this assigment, but feel free to have fun and test it out on other documents of your choosing. (For your actual submission, stick to Gettysburg, but if you come up with something amusing, feel free to send me an email)
Gettysburg.txt (showing below)
Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. But, in a larger sense, we can not dedicate, we can not consecrate, we can not hallow, this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us, that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion, that we here highly resolve that these dead shall not have died in vain, that this nation, under God, shall have a new birth of freedom, and that government of the people, by the people, for the people, shall not perish from the earth.
And now we have the code below. We just need to edit them.
#include
//comments here void make_lower( ) { //your code goes here }
//comments here bool is_alpha( ) { //your code goes here }
//comments here bool is_vowel( ) { //your code goes here }
//comments here bool is_punc( ) { //your code goes here }
//comments here vector
//comments here string word_to_PL( ) { //your code goes here }
//comments here vector
//comments here string build_paragraph( ) { //your code goes here
}
int main() {
//your code goes here
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
