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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string sms();
string eng();
string eng(string str)
{
size_t found;
for (int i = 0; i < str.length(); ++i){
str[i]=tolower(str[i]);
}
found = str.find("brb");
if (found != string::npos){
str.replace(str.find("brb"),3,"be right back");
}
found = str.find("btw");
if (found != string::npos){
str.replace(str.find("btw"),3,"by the way");
}
found = str.find("fwiw");
if (found != string::npos){
str.replace(str.find("fwif"),4,"for what it's worth");
}
found = str.find("gr8");
if (found != string::npos){
str.replace(str.find("gr8"),3,"great");
}
found = str.find("imho");
if (found != string::npos){
str.replace(str.find("imho"),4,"in my humble opinion");
}
found = str.find("l8r");
if (found != string::npos){
str.replace(str.find("l8r"),3,"later");
}
found = str.find("omw");
if (found != string::npos){
str.replace(str.find("omw"),3,"on my way");
}
found = str.find("np");
if (found != string::npos){
str.replace(str.find("np"),2,"no problem");
}
found = str.find("tmi");
if (found != string::npos){
str.replace(str.find("tmi"),3,"too much information");
}
found = str.find("ttyl");
if (found != string::npos){
str.replace(str.find("ttyl"),4,"talk to you later");
}
found = str.find("wywh");
if (found != string::npos){
str.replace(str.find("wywh"),4,"wish you were here");
}
cout << str << endl;
return (str);
}
string sms(string str)
{
size_t found;
for (int i = 0; i < str.length(); ++i){
str[i]=tolower(str[i]);
}
found = str.find("be right back");
if (found != string::npos){
str.replace(str.find("be right back"),13,"brb");
}
found = str.find("by the way");
if (found != string::npos){
str.replace(str.find("by the way"),10,"btw");
}
found = str.find("for what it's worth");
if (found != string::npos){
str.replace(str.find("for what it's worth"),19,"fwiw");
}
found = str.find("great");
if (found != string::npos){
str.replace(str.find("great"),5,"gr8");
}
found = str.find("in my humble opinion");
if (found != string::npos){
str.replace(str.find("in my humble opinion"),20,"imho");
}
found = str.find("later");
if (found != string::npos){
str.replace(str.find("later"),5,"l8r");
}
found = str.find("on my way");
if (found != string::npos){
str.replace(str.find("on my way"),9,"omw");
}
found = str.find("no problem");
if (found != string::npos){
str.replace(str.find("no problem"),10,"np");
}
found = str.find("too much information");
if (found != string::npos){
str.replace(str.find("too much information"),20,"tmi");
}
found = str.find("talk to you later");
if (found != string::npos){
str.replace(str.find("talk to you later"),17,"ttyl");
}
found = str.find("wish you were here");
if (found != string::npos){
str.replace(str.find("wish you were here"),18,"wywh");
}
cout << str << endl;
return(str);
}
void main()
{
string str, junk;
int number = 1;
while (number != 3){
cout << "Welcome to the english/sms translator service" << endl;
cout << "1) translate english to sms" << endl;
cout << "2) translate sms to english" << endl;
cout << "3) quit" << endl;
cout << "Enter choice: ";
cin >> number;
getline(cin, junk);
if (number == 1){
cout << "Enter an english sentence or phrase: ";
getline(cin, str);
sms(str);
}
if (number == 2){
cout << "Enter a sms sentence or phrase: ";
getline(cin, str);
eng(str);
}
}
}
| |