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
|
#include <iostream>
using namespace std;
#include <string>
#include <vector>
//Replaces specified phrase with replacement word
string replace(string english, string pirate, string phrase){
string toReturn = "";
int begin = 0;
int startingIdx=-1;
startingIdx = phrase.find(english, 0);
//Searches for the english word and breaks the phrase up before the english word, adds the pirate word
while (startingIdx!=-1){
toReturn += phrase.substr(begin, startingIdx-begin);
toReturn += pirate;
begin = startingIdx+english.size();
startingIdx = phrase.find(english, begin);
}
toReturn += phrase.substr(begin);
return toReturn;
}
//Makes the first letter of the specified word uppercase
string ucfirst(string word){
word[0]=toupper(word[0]);
return word;
}
int main() {
//Variables
string newPhrase;
vector<string>english{"hello", "friend", "madam", "officer", "stranger", "where", "is", "the", "my", "your", "restaurant", "hotel", "money"};
vector<string>pirate{"ahoy", "matey", "proud beauty", "foul blaggart", "scurvy dog", "whar", "be", "th'", "me", "yer", "galley", "fleabag inn", "booty"};
//User input
cout<<"Enter your phrase: ";
cin.ignore();
getline(cin, newPhrase);
//Making the pirate phrase, uppercase and lowercase
for (int i=0; i<english.size(); i++){
newPhrase=replace(english[i], pirate[i], newPhrase);
pirate[i]=ucfirst(pirate[i]);
english[i]=ucfirst(english[i]);
newPhrase=replace(english[i], pirate[i], newPhrase);
}
cout<<"Pirate Version: "<<newPhrase;
}
|