Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 programs 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 the txt file:

I SLEPT MOST OF THE NIGHT THE CAT IN THE HAT IS BACK EVERYONE LOVES PROGRAMMING MY BEST DAYS ARE AHEAD OF ME I REALLY LIKE PIG LATIN I CAME, I SAW, I CONQUERED THEY HEARD FIRSTHAND ACCOUNTS OF THE INCA EMPIRE JUMP -=\ SPORTS ARE THE MOST WATCHED PROGRAMS ON T.V. WHAT'S THE DEAL WITH AIRLINE PEANUTS?

This is the program I have. Currently the end of file wont work.

#include #include #include #include

int main() { using std::cout; using std::cin; using std::endl; using std::fstream; std::string sentence, userFile, word, pig; int index = 0, limit; std::ifstream inFile;

cout << "What is the file name? " << endl; getline(cin, userFile); inFile.open(userFile);

if(!inFile) { cout << "Sorry, that file does not work." << endl; cin.get(); } else { while (!inFile.eof()) { for(int i = 0; i <= limit; ++i) { getline(inFile, sentence); cout << sentence << endl; if(sentence[i] == ' ' || limit == i) { word = sentence.substr(index, (i - index)); word.erase(0,1); pig = pig + word + sentence.substr(index, 1) + "ay "; cout << endl; index = i + 1; } } } }

cout << "The new file says: " << pig << endl; inFile.close(); return 0; }

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago