Write a function that converts a single English word to its pig Latin equivalent
ID: 3533907 • Letter: W
Question
Write a function that converts a single English word to its pig Latin
equivalent. That function should have a header as follows:
string convertToPigLatin (string inStr)
Your program should:
1) Open a file for input called pigLatinIn.txt, which will be provided to you. This
file will consist of one English word per line.
2) Open a file for output called pigLatinOut.txt.
3) Your program will then read the input file, use the convertToPigLatin() function
to determine the pig Latin equivalent to the word, then write the following to the output
file:
English word Pig Latin Word
------------ --------------
cabin abin-cay
apple apple-way
Explanation / Answer
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
void createtestfile(){//for testing purpose
string datA="This is a very funny test line for a test file. Pigs speak in Pig Latin.";
ofstream make("testfile.txt");
make<<datA;
make.close();
return;
}
string convertToPigLatin (string inStr){//you'll need to complete this
string PigTalk;
//do something here
PigTalk+="ay";
return PigTalk;
}
int main(){
createtestfile();//for testing purposes
string filename;
string input;
ifstream infile("testfile.txt");
ofstream outfile;
cout<<"Enter output file name: ";
cin>>filename;
outfile.open(filename);
if(!infile.is_open()){
cout<<"Input file failed to open... Press any key to exit.";
cin.get();
return 0;
}
while(!infile.eof()){
infile>>pigLatinIn;
if(!infile.eof()){
outfile<<convertToPigLatin (input);
}
}
infile.close();
outfile.close();
cin.get();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.