Im ein Schwein Latein-Wandler machen, ich habe es mit einem Wort zu manipulieren bekommen kann und muß es ganze Sätze konvertieren, jedes Wort in Schweinlatein ausgegeben zu machen, unten ist mein Code:Ärger mit ganzem Satz Manipulation
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
bool isVowel (char);
string rotate(string);
string plString(string);
int main()
{
string str;
cout <<"Enter a sentence: ";
getline (cin, str);
cout << endl;
cout << str <<" in pig latin - " << plString(str) << endl;
ifstream infile;
infile.open("input.txt");
infile >> str;
while(infile)
{
cout << plString(str) << " ";
infile >> str;
}
cout << endl;
}
bool 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 rotate(string str)
{
string::size_type len = str.length();
string str1;
str1 = str.substr(1, len - 1) + str[0];
return str1;
}
string plString(string str)
{
string::size_type len;
bool vowel;
string::size_type counter;
if (isVowel (str[0]))
str = str + "way";
else
{
str = str + "";
str = rotate(str);
len = str.length();
vowel = false;
for (counter = 1; counter < len - 1; counter++)
if (isVowel (str[0]))
{
vowel = true;
break;
}
else
str = rotate(str);
if(!vowel)
str = str.substr(1,len) + "way";
else
str = str + "ay";
}
return str;
}
Ratschläge, wie man dies zu ganzen Sätzen macht, wären sehr willkommen!
die # include ist ausschließlich für die text.txt, die, wenn ein Satz in die kalkulatorische wird, wandelt es perfekt –
Stewie9589