I need to use pointers to do this homework for pig Latin where to converter to p
ID: 3536078 • Letter: I
Question
I need to use pointers to do this homework for pig Latin where to converter to pig latin you remove the first letter and place that letter at the end of the word. then you append the string "ay" to the word example
English: I slept most of the nigtht
Pig Latin: Iay leptsay ostmay foay hetay igthtnay
I want to make a string sentence an array and then a pointer that points to enach word in the array I need to use all the string functions library as much as I can here is how I started
#include<iostream>
#include<string>
using namespace std;
void prindLatinWord(char *);
int main()
{
int size = 1000;
string sentence[size];
string *ptrWord;
do{
cout "enter a phrase or q to quit : ";
getline(cin, sentence[size]);
cout << endl;
ptrWord = sentence;
count =0;
while(*ptrWord !=isspace())
{
*ptrWord = sentence[count];
if(ptrWord.length()==1)
cout << *ptrWord <<"ay ";
else
string newWord = printLatinWord(*ptrWord)
}
)while(sentence ! == "q")
)
void printLatinWord
//please help wit the function the whole code
Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
void printLatinWord(string word)
{
if(word.length()==1)
{
cout<<word<<"ay"<<" ";
return ;
}
const char* str=word.c_str();
cout<<str[word.length()-1];
for(int i=1;i<word.length()-1;i++)
cout<<str[i];
cout<<str[0];
cout<<"ay";
cout<<" ";
}
int main()
{
string sentence;
int i;
int j;
unsigned int k;
while(1)
{
cout <<" enter a phrase or q to quit : ";
getline(cin, sentence);
if(sentence.compare("q")==0)
break;
k=0;
while(k<sentence.length())
{
i=k;
j=0;
while(k<sentence.length()&&sentence.at(k)!=' ')
{
j++;
k++;
}
printLatinWord(sentence.substr(i,j));
while(k<sentence.length()&&sentence.at(k)==' ')
k++;
}
}
return 0;
}