Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am having issues with this question , it is computer programming class and we are using C + + programming. can you correct this
I am having issues with this question it is computer programming class and we are using C programming. can you correct this program? Use C programming to redo program
Use C programming write a program:
The Programming Example: Pig Latin Strings converts a string into the pig Latin form, but it processes only one word. Rewrite the program so that it can be used to process a text of an unspecified length. If a word ends with a punctuation mark, in the pig Latin form, put the punctuation at the end of the string. For example, the pig Latin form of Hello! is elloHay!. Assume that the text contains the following punctuation marks:
comma
period
question mark
; semicolon
: colon
Store the output in ChExOut.txt
Status: FAILED!
Check:
Test: File test
Reason: Unable to find ethay Internetway. Youway ancay atchway' in the program.
Error : str AssertionError
Timestamp: ::
Status: FAILED!
Check:
Test: File test
Reason: Unable to find otay endspay ethay irstfay ewfay eeksway' in the program.
Error : str AssertionError
Timestamp: ::
#include
#include
#include
#include
#include
#include
bool isPunctuationchar c
return c c c c ; c :;
std::string pigLatinconst std::string& word
std::string result ;
std::string::sizetype len word.length;
std::string::sizetype firstvowel len; position of the first vowel
Find the position of the first vowel
for std::string::sizetype i ; i len; i
if std::tolowerwordia std::tolowerwordie
std::tolowerwordii std::tolowerwordio
std::tolowerwordiu
firstvowel i;
break;
Construct the Pig Latin word
if firstvowel
If the word starts with a vowel
result word Hay";
else
If the word starts with consonants
result word.substrfirstvowel word.substr firstvowelay;
return result;
int main
std::ifstream inFileChExIntxt;
std::ofstream outFileChExOut.txt;
if inFile
std::cerr "Error opening input file." std::endl;
return ;
if outFile
std::cerr "Error creating output file." std::endl;
return ;
std::string line;
while std::getlineinFile line
std::istringstream issline;
std::string word;
bool firstWord true;
while iss word
Check if the word ends with a punctuation mark
char lastChar word.back;
bool hasPunctuation isPunctuationlastChar;
Remove punctuation if present
if hasPunctuation
word.popback;
Convert to Pig Latin
std::string pigLatinWord pigLatinword;
Append punctuation back if present
if hasPunctuation
pigLatinWord lastChar;
Write the word to the output file
if firstWord
outFile ;
outFile pigLatinWord;
firstWord false;
outFile std::endl; End of line
std::cout "Pig Latin conversion completed. Output saved in ChExOut.txt std::endl;
inFile.close;
outFile.close;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started