English to pig latin program help

Hey everyone. I am trying to get a program working to convert an English sentence into a pig latin sentence. I don't have much right now but I have little to go off of or direction. Please help!

if you want to see what i have to do you can check out:
http://home.earthlink.net/~craie/121/projects/piglatin.html

thanks to anyone that helps and gives me some kind of direction!


#include<iostream>
#include<string>
#include<vector>

using namespace std;


int main(void)
{
cout << "\n\n\t\tWelcome to the Pig Lating Program!";
vector<string> phrase();
cout << "\n\nPlease enter your phrase: ";
bool more = true;
while(more)
{
string word;
cin >> word;
if( word[word.length()] = '.')
{
more = false;
}
else
{
phrase.push_back(word);
}
}




cout << "Thanks, that was " << phrase.size() << " words.";


return 0;
}
Last edited on
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
#include<iostream>
#include<string>
#include<vector>

using namespace std;


int main(void)
{
    cout << "\n\n\t\tWelcome to the Pig Lating Program!";
    vector<string> phrase();
    cout << "\n\nPlease enter your phrase: ";
    bool more = true;
    while(more)
    {
        string word;
        cin >> word;
        if( word[word.length()] = '.')
        {
            more = false;
        }
        else
        {
            phrase.push_back(word);
        }
    }
    
    

    
    cout << "Thanks, that was " << phrase.size() << " words.";
    
    
    return 0;
}
okay so now i have a little more after a few hours haha but i don't know how to go about checking if the next char is a vowel or constant then how to move that to the end. any help is greatly appreciated!!!!


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
#include<iostream>
#include<string>
#include<vector>

using namespace std;

bool is_vowel(string c);

int main(void)
{
    cout << "\n\n\t\tWelcome to the Pig Lating Program!";
    vector<string> phrase;
    cout << "\n\nPlease enter your phrase: ";
    bool more = true;
    do
    {
        string word;
        cin >> word;
        phrase.push_back(word);
        if( word[word.length()-1] == '.')
        {
            more = false;
        }
    } while(more);
    
    for( vector<short>::size_type i = 0; i <= ( phrase.size() - 1 ); i++)
    {
        if( is_vowel( phrase[i] ) )
        {
            phrase[i] += "yay";
        }
        else
        {
            if(
    }

    
    for( vector<short>::size_type phrase_pos = 0; phrase_pos != (phrase.size() - 1); phrase_pos++)
    {
        cout << phrase[phrase_pos] << ' ';
    }
    cout << phrase.back();
    
    
    return 0;
}


bool is_vowel(string c)
{
    char b = tolower(c[0]);
    return b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u';
}

bool is_constant(string c, short a)
{
    char b = tolower(c[a]);
    return b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u';
updated version:

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include<iostream>   //need to: remove period and constant starting words aren't working(the constant is cut
//off in the beginning then disappears). the constant should be thrown onto the end of the word then ay
//added. also have to include qu thing and if the word ends in y.
//words starting with a vowel do just fine
#include<string>
#include<vector>

using namespace std;

bool is_vowel(string c);

bool is_vowel_char(char c);

short check_for_const(string a);

string translate(string & a);

short check_for_vowel(string a);

string remove_period(string & a);

int main(void)
{
    cout << "\n\n\t\tWelcome to the Pig Lating Program!";
    vector<string> phrase;
    cout << "\n\nPlease enter your phrase (end with a period): ";
    bool more = true;
    do
    {
        string word;
        cin >> word;
        phrase.push_back(word);
        if( word[word.length()-1] == '.')
        {
            more = false;
        }
    } while(more);
    
    //phrase.pop_back();
    //(phrase[phrase.size()-1]).replace(phrase[phrase.size()-1].length()-1, ""); //trying to replace the period with ""
    
    //remove_period( phrase.size()-1); //another attempt to remove the period
    
    for( vector<short>::size_type i = 0; i <= ( phrase.size() - 1 ); i++)
    {
        if( is_vowel( phrase[i] ) ) //if the word starts with a vowel
        {
            phrase[i] += "yay";
        }
        else
        {
            phrase[i] = translate(phrase[i]);//put in translate func here for words that start with constant
        }
    }

    
    for( vector<short>::size_type phrase_pos = 0; phrase_pos != (phrase.size() - 1); phrase_pos++)
    {
        cout << phrase[phrase_pos] << ' ';
    }
    cout << phrase.back();
    
    
    return 0;
}


bool is_vowel(string c)
{
    char b = tolower(c[0]);
    return b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u';
}

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


short check_for_const(string a)
{
    short pos;
    for( vector<short>::size_type i = 0; i <= a.size() - 1; i++)
    {
        if( !is_vowel_char( a[i] ))
        {
            pos = i;
        }
    }
    return pos;
}

short check_for_vowel(string a)
{
    short pos;
    for( vector<short>::size_type i = 0; i <= a.size() - 1; i++)
    {
        if( is_vowel_char( a[i] ))
        {
            pos = i;
            i = a.size();
        }
    }
    return pos;
}

string translate(string & a)
{
    string b;
    string c;
    short vowel_pos = check_for_vowel(a);
    b = a.substr(0, vowel_pos-1);
    a = a.substr( vowel_pos, a.size() - 1);
    
    c = a + b + "ay";
    
    return c;
}
    
/*
string remove_period(string & a)
{
    a.erase(a.length-1, 1);
    //(phrase[phrase.size()-1]).replace(phrase[phrase.size()-1].length()-1, "")
    return a;
}
    
    
*/    
    
    
    
    
    
Topic archived. No new replies allowed.