1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int pLatin(string &s1, int &rtrnNum, int &end);
void find(string &s1, int &end);
int main()
{
//Declarations
int rtrnNum = 0; //temporary number for return value of main
string entry; //original text entered
string temp;
int tempN = 0; //save the vowel's position in the word
int i = 0;
//Prompt
cout << "This program takes a string of words and coverts it to pig latin." << endl;
while (i == 0)
{
//Input
cout << "Enter a string of words, or press Enter to quit." << endl;
getline(cin, entry); //input line of text
cout << entry << endl;//displays original text
string s1(entry);
cout << "The string you entered was, "<< s1.length() << " characters long." << endl;
int end = s1.length();
pLatin(s1, rtrnNum, end); //calls function
if (rtrnNum > 0) //Return Value
{
return 1;
}
else
{
return i;
}
}
}
int pLatin(string &s1, int &rtrnNum, int &end)
{
//declarations
int i = 0; //condition for While
if (s1 == "")
{
return 1;
}
while (i == 0)
{
find(s1, end);
}
}
void find(string &s1, int &end)
{
//See if fist letter of entry starts with vowel
if (s1.at(0) == 'a' || s1.at(0) == 'e' || s1.at(0) == 'i' || s1.at(0) == 'o' || s1.at(0) =='u')
{
s1 = s1 + "hay";
}
else
{
s1.find('a');
if (s1.at(2) = 'a')
{
s1.insert(end, s1.at(0,1));
s1.erase(end, s1.at(0));
s1.insert(end, "hay");
}
}
}
|