Right now I'm having troubles with \n's being read into the beginning of FirstSide when I use getline
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
|
void ToLower(string&);
void selectionsort(string[], int);
string Translate(string, string);
double ConstCount(string);
void GetInfile(string&);
void GetOutfile(string&);
int main(){
ifstream input;
ofstream output;
int Count=0;
double Consonants=0;
string Outfile, Infile, FirstSide, SecondSide, LatinWord, EnglishWord;
char Delimeter('-'), Delimit(' '), EndLine = '\n';
string WordArray[50];
string LatinArray[50];
GetInfile(Infile);
GetOutfile(Outfile);
input.open(Infile.c_str());
output.open(Outfile.c_str());
output << fixed << showpoint << setprecision(2);
output << "Original Word Alphabetized" << endl;
getline(input, FirstSide, Delimeter);
while (!input.eof()){
getline(input, SecondSide, Delimit);
ToLower(FirstSide);
ToLower(SecondSide);
LatinWord = FirstSide + "-" + SecondSide;
LatinArray[Count] = LatinWord;
EnglishWord = Translate(FirstSide, SecondSide);
WordArray[Count] = EnglishWord;
output << EnglishWord << "------" << LatinWord << "========" << FirstSide << "_____" << SecondSide << endl;
Count++;
Consonants = Consonants + ConstCount(EnglishWord);
getline(input, FirstSide, Delimeter);
}
output << endl;
for (int i = 0; i<Count; i++){
output << LatinArray[i] << endl;
}
output << endl;
for (int j = 0; j<Count; j++){
output << WordArray[j] << endl;
}
output << endl << "Average # of consonants per word: " << Consonants/Count << endl;
if (Count % 2 == 1)
output << "The Middle Word is \"" << WordArray[Count/2] << "\"" << endl;
if (Count % 2 == 0)
output << "The Middle Words are \"" << WordArray[Count/2 - 1] << "\" and \"" << WordArray[Count/2] << "\"" << endl;
return 0;
}
string Translate(string word, string piglatin)
{
string Translated;
piglatin.erase(piglatin.end() - 2, piglatin.end());
Translated = piglatin + word;
return Translated;
}
|
output looks like
this------is-thay========is_____thay
is------is-ay========is_____ay
a------a-ay========a_____ay
little------ittle-lay========ittle_____lay
test------est-tay========est_____tay
to------o-tay========o_____tay
see------ee-say========ee_____say
h
ow------
ow-hay========
ow_____hay
the------e-thay========e_____thay
pig------ig-pay========ig_____pay
latin------atin-lay========atin_____lay
translation------anslation-tray========anslation_____tray
pr
ogram------
ogram-pray========
ogram_____pray
works------orks-way========orks_____way
is-thay
is-ay
a-ay
ittle-lay
est-tay
o-tay
ee-say
ow-hay
e-thay
ig-pay
atin-lay
anslation-tray
ogram-pray
orks-way
this
is
a
little
test
to
see
h
ow
the
pig
latin
translation
pr
ogram
works
Average # of consonants per word: 2.86
The Middle Words are "see" and "h
ow"