question archive #include <iostream> #include <cstring> using namespace std;   int main() { //set vars const int size =81; char inStr[size]; char outStr[size + 20 ] = ""; int currentInIndex = 0; int currentOutIndex = 0; char firstChar = 0;   cout << " Enter a sentence and I will translate it to Pig Latin: "; cin

#include <iostream> #include <cstring> using namespace std;   int main() { //set vars const int size =81; char inStr[size]; char outStr[size + 20 ] = ""; int currentInIndex = 0; int currentOutIndex = 0; char firstChar = 0;   cout << " Enter a sentence and I will translate it to Pig Latin: "; cin

Subject:Computer SciencePrice: Bought3

#include <iostream>

#include <cstring>

using namespace std;

 

int main()

{

//set vars

const int size =81;

char inStr[size];

char outStr[size + 20 ] = "";

int currentInIndex = 0;

int currentOutIndex = 0;

char firstChar = 0;

 

cout << " Enter a sentence and I will translate it to Pig Latin: ";

cin.getline(inStr,size);

int length = strlen(inStr);

//test for errors

if (length>size)

{

cout << "Error";

return 42;

}

 

firstChar = inStr[0];

 

//parse through arrays

 

for (currentInIndex =0; currentInIndex<length+1; currentInIndex++)

{

//Beg of word (just storing character)

if (firstChar == 0 && isalpha(inStr[currentInIndex]))

{

firstChar = inStr[currentInIndex];

}

//Middle of word

else if (isalpha(inStr[currentInIndex]) && firstChar != 0)

{

outStr[currentOutIndex++] = inStr[currentInIndex];

}

//End of word

else

{

if (firstChar != 0)

outStr[currentOutIndex++] = firstChar;

outStr[currentOutIndex++] ='a';

outStr[currentOutIndex++] ='y';

}

//space

outStr[currentOutIndex++] = inStr[currentInIndex++];

firstChar = 0;

}

outStr[currentOutIndex] = '\0';

cout << outStr ;

return 0;

}

 

 

}

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE