PigLatin Program

Hi, I'm currently learning C++ and I have this PigLatin program to write, and while everything compiles and there are no errors.. I can't seem to get the string I am passing in to print out in its PigLatin translation. This is my very first post so excuse me if I do not post the code correctly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef PIGLATINH_H
#define PIGLATINH_H

#include <iostream>
using namespace std;

class PigLatinH
{
public:
	PigLatinH();
	bool isVowel(char);
	string PigLatinString(string);
	string RotateString(string);
private:
};
#endif 

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
#include "PigLatinH.h"
#include <iostream>

using namespace std;


//implementation

PigLatinH::PigLatinH()
{

}

//check for vowels
bool PigLatinH::isVowel(char ch)
{
	switch (ch)
        {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
            case 'Y':
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
            case 'y':
                return true;

            default:
                return false;
        }
}

string PigLatinH::PigLatinString(string pStr)
{
	int len;
	bool foundVowel;
	int counter;

	if(isVowel(pStr.at(0)))
	{
		pStr = pStr += "way";
	}
	else
	{
		pStr = pStr += "";
		pStr = RotateString(pStr);

		len = pStr.size();
		foundVowel = false;

		for(counter=1;counter< len-1;counter++)
			if(isVowel(pStr.at(0)))
			{
				foundVowel = true;
				break;
			}
			else
			{
				pStr = RotateString(pStr);
			}

		if(!foundVowel)
		{
			pStr = pStr.substr(1,len) += "ay";
		}
		else
			pStr = pStr += "way";
	}
	return pStr;

}


string PigLatinH::RotateString(string pStr)
{
	int len = pStr.size();
	string rStr;
	rStr = pStr.substr(1,len) += pStr.at(0);
	return rStr;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"
#include "PigLatinH.h"
#include <iostream>



using namespace std;

string preamble = "We the People of the United States in Order to form a more perfect Union establish Justice insure domestic Tranquility provide for the common defence promote the general Welfare and secure the Blessings of Liberty to ourselves and our Posterity do ordain and establish this Constitution for the United States of America";

int main()
{
	PigLatinH translate;
	cout << "Pig Latin form of the Preamble of the Constitution: " << endl;

	translate.PigLatinString(preamble);

	system("Pause");
	return 0;
}
You can do so:
1
2
3
4
5
6
7
8
9
10
int main()
{
	PigLatinH translate;
	cout << "Pig Latin form of the Preamble of the Constitution: " << endl << // Note << instead of ;

	translate.PigLatinString(preamble);

	system("Pause");
	return 0;
}
Hi coder777.. thank you for your reply I tried what
you've suggested and I get an error the error is:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
I underlined the operator that caused the error.
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
	PigLatinH translate;
	cout << "Pig Latin form of the Preamble of the Constitution: " << endl <<
		
	translate.PigLatinString(preamble);
	

	system("Pause");
	return 0;
}

I figured it out... I forgot to include #include <string> thanks coder777
Topic archived. No new replies allowed.