In this assignment, you’ll decode Twitter messages that include Internet abbrevi
ID: 3764352 • Letter: I
Question
In this assignment, you’ll decode Twitter messages that include Internet abbreviations, such as LOL and IRL. The starter program decodes two abbreviations. 1. Expand the number of abbreviations that can be decoded to include the following: AFK = away from keyboard NVM = never mind BFF = best friends forever FTW = for the win IIRC = if I recall correctly TTYL = talk to you later IMHO = in my humble opinion Save your solution for this step in a file named “step1.cpp”. You’ll need to submit each step as a separate file. 2. Allow the user to enter a complete tweet (160 characters or less) as a single line of text. Use getline to get the single line of text then resize (or truncate) to 160 characters. Search the resulting string (using string’s find function) for those common abbreviations and print a list of each abbreviation along with its decoded meaning. Save your solution for this step in a file named “step2.cpp”. You’ll need to submit each step as a separate file. 3. Convert the user's tweet to a decoded tweet, replacing the abbreviations directly within the tweet. You only need to replace the first instance of a particular abbreviation. Save your solution for this step in a file named “step3.cpp”. You’ll need to submit each step as a separate file. starter code: #include #include using namespace std; int main() { string tweet; cout << "Enter abbreviation from tweet: "; cin >> tweet; // Output decoded abbreviation from tweet if (tweet == "LOL") { cout << "LOL = laughing out loud" << endl; } else if (tweet == "IRL") { cout << "IRL = in real life" << endl; } else { cout << "Sorry, don't know that one." << endl; } return 0; }
Explanation / Answer
Step 1:
#include <bits/stdc++.h>
using namespace std;
int main() {
string tweet;
cout << "Enter abbreviation from tweet: ";
cin >> tweet;
// Output decoded abbreviation from tweet
if (tweet == "LOL") {
cout << "LOL = laughing out loud" << endl;
}
else if (tweet == "IRL") {
cout << "IRL = in real life" << endl;
}
else if(tweet=="AFK"){
cout<<"AFK = away from keyboard"<<endl;
}
else if(tweet=="NVM"){
cout<<"NVM = never mind"<<endl;
}
else if(tweet=="BFF"){
cout<<"BFF = best friends forever"<<endl;
}
else if(tweet=="FTW"){
cout<<"FTW = for the win"<<endl;
}
else if(tweet=="IIRC"){
cout<<"IIRC = if I recall correctly"<<endl;
}
else if(tweet=="TTYL"){
cout<<"TTYL = talk to you later"<<endl;
}
else if(tweet=="IMHO"){
cout<<"IMHO = in my humble opinion"<<endl;
}
else{
cout << "Sorry, don't know that one." << endl;
}
return 0;
}
Step 2:
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cout<<"Enter tweet:";
getline(cin,s);
string tweet;
int l=s.length();
for(int i=0;i<160 && i<l;i++){
tweet[i]+=s[i];
}
if (tweet.find("LOL") ) {
cout << "LOL = laughing out loud" << endl;
}
else if (tweet.find("IRL") ) {
cout << "IRL = in real life" << endl;
}
else if(tweet.find("AFK")){
cout<<"AFK = away from keyboard"<<endl;
}
else if(tweet.find("NVM")){
cout<<"NVM = never mind"<<endl;
}
else if(tweet.find("BFF")){
cout<<"BFF = best friends forever"<<endl;
}
else if(tweet.find("FTW")){
cout<<"FTW = for the win"<<endl;
}
else if(tweet.find("IIRC")){
cout<<"IIRC = if I recall correctly"<<endl;
}
else if(tweet.find("TTYL")){
cout<<"TTYL = talk to you later"<<endl;
}
else if(tweet.find("IMHO")){
cout<<"IMHO = in my humble opinion"<<endl;
}
else{
cout << "Sorry, don't know that one." << endl;
}
return 0;
}
Step 3:
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cout<<"Enter tweet:";
getline(cin,s);
string tweet;
int l=s.length();
for(int i=0;i<160 && i<l;i++){
tweet+=s[i];
}
if (tweet.find("LOL")!=-1 ) {
int x=tweet.find("LOL");
tweet=tweet.substr(0,x)+"laughing out loud"+tweet.substr(x+3,tweet.length()-(x+3));
}
if (tweet.find("IRL")!=-1 ) {
int x=tweet.find("IRL");
tweet=tweet.substr(0,x)+"in real life"+tweet.substr(x+3,tweet.length()-(x+3));
}
if(tweet.find("AFK")!=-1){
int x=tweet.find("AFK");
tweet=tweet.substr(0,x)+"away from keyboard"+tweet.substr(x+3,tweet.length()-(x+3));
}
if(tweet.find("NVM")!=-1){
int x=tweet.find("NVM");
tweet=tweet.substr(0,x)+"never mind"+tweet.substr(x+3,tweet.length()-(x+3));
}
if(tweet.find("BFF")!=-1){
int x=tweet.find("BFF");
tweet=tweet.substr(0,x)+"best friends forever"+tweet.substr(x+3,tweet.length()-(x+3));
}
if(tweet.find("FTW")!=-1){
int x=tweet.find("FTW");
tweet=tweet.substr(0,x)+"for the win"+tweet.substr(x+3,tweet.length()-(x+3));
}
if(tweet.find("IIRC")!=-1){
int x=tweet.find("IIRC");
tweet=tweet.substr(0,x)+"if I recall correctly"+tweet.substr(x+4,tweet.length()-(x+4));
}
if(tweet.find("TTYL")!=-1){
int x=tweet.find("TTYL");
tweet=tweet.substr(0,x)+"talk to you later"+tweet.substr(x+4,tweet.length()-(x+4));
}
if(tweet.find("IMHO")!=-1){
int x=tweet.find("IMHO");
tweet=tweet.substr(0,x)+"in my humble opinion"+tweet.substr(x+4,tweet.length()-(x+4));
}
cout<<tweet<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.