Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This question needs to be answered in C++ Language. PLEASE FOLLOW ALL INSTRUCTIONS. FOLLOW SOURCE CODE. PLEASE USE ALL OF THE FUNCTIONS LISTED AND NO

This question needs to be answered in C++ Language. PLEASE FOLLOW ALL INSTRUCTIONS. FOLLOW SOURCE CODE.

PLEASE USE ALL OF THE FUNCTIONS LISTED AND NO MORE. MAKE SURE TO USE isWhitespace and isPunctuation

image text in transcribed----------------------------------------------------------------------------SOURCE CODE-------------------------------------------------------------------

#include

#include

using namespace std;

bool isVowel (char ch);

/**

* Removes the first character of the string, and places it at the

* end of the string.

* @param pString the word to be rotated.

* @return the new reordered string

*/

string rotate (const string& pStr);

string pigLatinString (const string& input);

int main ()

{

string str;

// Get a word from the user

cout

cin >> str;

cout

// Output the text as pig Latin

cout

return 0;

}

bool isVowel (char ch)

{

switch (ch)

{

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':

case 'Y':

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

case 'y':

return true;

default:

return false;

}

}

string rotate (const string& pStr)

{

string::size_type len = pStr.length();

string rStr;

rStr = pStr.substr(1, len - 1) + pStr[0];

return rStr;

}

string pigLatinString (const string& input)

{

string::size_type len;

string pStr = input;

bool foundVowel;

string::size_type counter;

if (isVowel(pStr[0]))

pStr = pStr + "-way";

else

{

pStr = pStr + '-';

pStr = rotate(pStr);

len = pStr.length();

foundVowel = false;

for (counter = 1; counter

{

if (isVowel(pStr[0]))

{

foundVowel = true;

break;

}

else

pStr = rotate(pStr);

}

if (!foundVowel)

pStr = pStr.substr(1, len) + "-way";

else

pStr = pStr + "ay";

}

return pStr;

}

-----------------------------------------------------------------------IMAGE OF SOURCE CODE------------------------------------------------------

image text in transcribedimage text in transcribed--------------------------------------------------------------------------------TEXT FILE INCLUDED-------------------------------------------------------

Today we live in an era where information is processed, almost, with the speed of light. Through computers, the technological revolution is drastically changing the way we live and communicate with each other. Terms such as Internet, which was unfamiliar even a few years ago, are very common today. With the help of computers you can send letters to and receive letters from loved ones within seconds. You no longer need to send an application by mail to apply for a job; in many cases you can simply submit your job application via the Internet. You can watch how stocks perform in real time, and instantly buy and sell. Kids in elementary school regularly surf the Internet and use computers to design their classroom projects. Students no longer type their papers on typewriters or write them by hand. Instead, they use powerful word processing software to complete term papers. Many people maintain and balance their checkbooks on computers.

These are some of the ways computers have greatly impacted our daily lives. This is all made possible because of the availability of different software, which are computer programs. For example, word processing software are programs that enable you to write term papers, create impressive looking resumes, and even write a book. Even this book was created with the help of a powerful word processor. Without software a computer is of no use. However, software are developed with the help of programming languages. The programming language C++, especially, is very well suited for developing software to accomplish a specific task.

Until the early 1990s, before beginning to teach a programming language course, instructors used to spend the first few weeks just teaching their students how to use computers. Today, by the time students graduate from high school, they know very well how to work with a computer. This book is not concerned with explaining how to use computers. Rather, this book teaches you how to write programs in a language called C++. It is useful, however, to at least understand some of the basic terminology and different components of a computer before you begin programming. This chapter briefly describes the main components of a computer system, the history and evolution of computer languages, and some fundamental ideas about how to solve problems with computer programming.

-----------------------------------------------------------IMAGE OF TEXT FILE FOR REFERENCE----------------------------------------------------

image text in transcribed

DESCRIPTION The attached starter code (from the end of Chapter 7) converts a string into the Pig Latin form, but it processes only one word. Make sure you fully understand the details of the program described on pages 504 - 508 (a copy of the text is included with the starter code). Make the following changes to the code: 1. Add comments to the program describing what each section of code does. 2. Then, modify the program so that it can be used to process text of an unspecified length from a file named InputText.txt and outputs Pig Latin to a file named PigLatinText.txt. An example input file is attached for you to use for testing. If the program fails to open InputText.txt, ouput the error message, "Cannot open 'InputText.txt'. Program terminated." and exit without creating PigLatinText.txt. Hint: To check if the next character of the input stream is whitespace or the start of a word, use the peek function available in istreams (and therefore ifstreams). If the next character is whitespace, remove it from the input stream and output it to the output file. If the next character is not whitespace, read in the next word as a string and translate it into Pig Latin. 3. Modify pigLatinString() to handle punctuation. If a word ends with a punctuation the pig Latin form, put the punctuation at the end of the string. For example, the pig Latin form of Hello! is ello-Hay!. The output file should have the same whitespace as the original. Solve this problem by creating and using these two additional functions: isPunctuation that accepts a character and returns a Boolean value. Assume that the text contains the following punctuation marks: , (comma), . (period), ? (question mark), ! (exclamation point), ; (semicolon), and : (colon). isWhitespace that accepts a character and returns a Boolean value. Consider spaces, tabs, newline, and carriage return (' 'l characters to be whitespace characters. . You may create additional functions if you like. For example, you may create a seperate function to read and write from and to the text files, but you could also put that code in main(). None of the functions described here require non-constant pass-by-reference parameters. 3 #include #include 4 5 6 7 using namespace std; bool isVowel (char ch); 8 9 10 11 12 13 14 15 /** * Removes the first character of the string, and places it at the * end of the string. * @param pString the word to be rotated. * @return the new reordered string */ string rotate (const string& pStr); 16 17 18 19 20 21 string pigLatinString (const string& input); int main() { string str; // Get a word from the user cout > str; cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

=+3. What public and objective does each tactic serve?

Answered: 1 week ago

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago