#include<iostream>
#include<string>
#include<vector>
#include <fstream>
usingnamespace std;
//functions here
void fillVector (vector <string> & n); //fills the vector with fin
void pigLatin (string& x); //this function changes the string into piglatin
void outputVector (vector<string> n); //this outputs the vector and all word count information
int wordCount (vector <string> n); //this function counts all the words
int letterCount (vector <string> n); //this function counts all the letters
int counter (string x); //this function aids the letter counter
int charCounter (vector <string> n); //this function counts all the characters
int charCounterhelp (string x); //this funtion helps the charcounter
//constant strings here
string vowel = "way";
string space = " ";
string cons = "ay";
int main()
{
vector <string> phrase(1000000);
fillVector (phrase);
outputVector (phrase);
}
void fillVector (vector <string> & n)
{
ifstream fin;
fin.open("data.txt");
if(fin.fail())
{
cout << "data.txt failed to open" << endl;
exit (0);
}
else
cout << "data.txt has opened" << endl; //this is wthe place where everything stops running
string word;
do
{
getline(fin, word); //reads it into the vector
pigLatin (word); //send word to the pigLatin function
n.push_back(space);
n.push_back(word); //add the new word to the vector
}
while(!fin.eof());
cout << "the vector has been filled" << endl;
}
void pigLatin (string& x)
{
string temp, notVowel;
for (int i = 0; i < x.size(); i++)
{
if (x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u' ) //tests the first value
{ x += vowel;
break;
}
else //if is a constant
{
do
{
temp += x.at(i); //temp is equal to all the consts
//find a way to erase all before temp here
x.erase(x.at(i), temp.length());
}
while (!(x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u'));
if ((x.at(i) == 'a' || x.at(i)== 'e' ||x.at(i)== 'i' || x.at(i)== 'o' || x.at(i)== 'u'))
notVowel += x.at(i);
x += (notVowel + cons);
break;
} //end of else bracket
} //end of the for loop bracket
} //end of piglatin bracket
void outputVector (vector<string> n)
{
for (int i = 0; i < n.size(); i++)
cout << n.at(i); //runs through and outputs
cout << "There are " << wordCount (n) << " in the phrase" << endl;
cout << "There are " << letterCount (n) << " in the phrase" << endl;
cout << "There are " << charCounter (n) << " in the phrase" << endl;
}
int wordCount (vector <string> n)
{
int wordCount = 0;
for (int i = 0; i < n.size(); i++)
if(n.at(i) != space)
wordCount ++;
return wordCount;
}
int letterCount (vector <string> n)
{
int letterCount = 0;
for (int i = 0; i < n.size(); i++)
letterCount = counter (n.at(i));
return letterCount;
}
int counter (string x)
{
int temp = 0;
for (int i = 0; i < x.size(); i++)
{
temp ++;
}
return temp;
}
int charCounter (vector <string> n)
{
int charCount = 0, letters = 0;
letters = letterCount (n);
for (int i = 0; i < n.size (); i++)
charCount = charCounterhelp (n.at(i));
return (charCount + letters);
}
int charCounterhelp (string x)
{
int temp = 0;
for (int i = 0; i < x.size(); i++)
{
char t = x.at(i);
if (isspace (t) == false) //if it is not a space
temp += i;
}
return temp;
}