0

Hey guys need as much help as you can give me cause I need to turn this in by midnight.

I am trying to do this:
You are to write a program that will input English text translate it into Pig Latin, then output the result to a file

Pig Latin is an invented language formed by transforming each word according to the following rules:
1.If the word starts with a vowel ('a', 'e', 'i', 'o', 'u', or 'A, 'E', 'I', 'O', 'U') or does not contain a vowel, its Pig Latin equivalent is formed by just adding the suffix “way”.
2.If the word starts with a consonant (any letter that is not a vowel) and contains a vowel its Pig Latin equivalent is formed by moving the initial consonant string (that is all letters up to the first vowel) from the beginning of the word to the end and then adding the suffix “ay”.
3.If a word is transformed by rule 2) and starts with an upper case character (consonant), its Pig Latin equivalent also starts with an upper case character (vowel) and the consonant is changed to lower case.

A word will be taken to mean any consecutive sequence of letters, i.e. you don't have to check that the sequence is actually an English word. A word is terminated by any non-letter (e.g white space, punctuation mark, etc.).

Made this outline:
int main( )
{
declare el, pl as strings to store an English line, Pig Latin line;

prompt for and get English line (use gets);
while (line is not equal to “!!!”)
{
translate(el, pl);
output Pig Latin line to the screen and to a file;
prompt for and get English line (use getline);
}

system("pause");
return 0;
}

void translate(const char el[ ], char pl[ ])
{
declare ew, pw as c-strings to store an English, Pig Latin word;
declare ep, pp as integer variables that tell the current positions in el, pl;
/*alternatively you can declare ep, pp as pointers of type char *, but this is tricky*/

initialize current positions ep, pp to be the beginning of el, pl, i.e. initialize them to 0;
while (not at end of el)
if (character at current position in el is a letter)
{
extract word from el that starts from current position and store in ew;
translate word ew to Pig Latin and store in pw;
copy pw at current end of pl;
make sure ep, pp are now set to positions just past the word;
}
else /* character at current position in el is not a letter */
{
copy this character unchanged to current position in pl;
increment ep, pp;
}

Null terminate the string pl;
}

This is what I have tried to do but I really suck so....

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

int main( )
{ 
	char englishline[], piglatinline[]
	
	cout << "Please enter the text that is going to be translated to piglatin.";
	cin.get(englishline[]);
	while (englishline[] != "!!!")
   	{  
		translate(englishline[], piglatinline[]);
			cout << piglatinline[] << endl;
			fout << piglatinline[] << endl;
			cin.getline(englishline[]);
	}
   
	system("pause");
	return 0;
}

void translate(const char englishline[], char piglatinline[])
{
	char englishword[], piglatinword[];
	int englishpostion=englishline[0]
	int piglatinpostion=piglatinline[0];
   	while (!englishline[\0])
      	if (englishline[] == char)
      	{
			englishword[]=englishline[]-englishline[]
          	translate(englishword[] piglatinword[]);
			strcpy.piglatinword;
			englishpostion=englishline[0]-englishposition;
			piglatinpostion=piglatinline[0]-piglatinposition;
      	}
      	else
      	{
			strcpy.englishword;
			englishword=piglatinpostion;
          	copy character unchanged to current position in pl;
          	increment ep, pp;
      	}
   
	Null terminate the string pl;
}

Please help :(

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Aranarth
0

This would be so much easier if you just used strings, see the code example below.
It would also help if you would just open your C++ book and start reading... it doesn't look like you've done that until now.

This code still doesn't handle punctuation marks properly like the task description demands. That'll be your task.

#include <iostream>
#include <sstream>
using namespace std;

bool isVowel(char c) {c=tolower(c); return c=='a' || c=='e' || c=='i' || c=='o' || c=='u';}

string translate(const string& word)
{
  if (isVowel(word[0]))return word+"way"; //first char is vowel
  int vowelPos=1;
  while (vowelPos<word.length() && !isVowel(word[vowelPos]))vowelPos++; //look for first vowel
  if (vowelPos>=word.length())return word+"way"; //no vowels found
  if (isupper(word[0]))return string(1,toupper(word[vowelPos]))+word.substr(vowelPos+1,word.length()-
                              vowelPos-1)+string(1,tolower(word[0]))+word.substr(1,vowelPos-1)+"ay";
  else return word.substr(vowelPos,word.length()-vowelPos)+word.substr(0,vowelPos)+"ay";
}

int main()
{
  cout << "Please enter a phrase:" << endl;
  string phrase,word;
  getline(cin,phrase);
  stringstream ss(phrase);
  while (ss >> word)cout << translate(word) << ' ';
}

Edited by Aranarth: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.