Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Convert the user\'s tweet to a decoded tweet, replacing the abbreviations dir

ID: 3773558 • Letter: 3

Question

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”.

Here is an example program execution for step 3 (user input is highlighted here for clarity): Enter tweet:I'm going to hang out with my BFF IRL tomorrow. Decoded tweet:I'm going to hangout with my best friends forever in real life tomorrow

I thought that I could just use tweet.replace to replace the "LOL" and other abbreviations but apparently that is not so. Can anyone help point me in the right direction?

Explanation / Answer

#include <iostream.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

using namespace std;
void upgrade(int &acr)
{
acr=9;
cout<<updating the file."; getch();

}

void search(char ch[160],char acronym[9][36],int acr)
{

int count,c=strlen(ch);
for(int i=0;i<acr;i++)
{
for(int j=0;acronym[i][j]!='=';j++);
for(int k=0;k<=c;k++)
   { for(int l=0,count=0;l<j;l++)
    if(toupper(ch[k+l])==acronym[i][l]) count++;
    if(count==j) {cout<<' '<<acronym[i]; break;

}
   }
}
}


void display (char ch[160], char acronym[9][36],int acr)
{ int i,j,k,l,count,p;
for(i=0;i<=strlen(ch);i++)
{ for(j=0;j<acr;j++)
    { for(l=0;acronym[j][l]!='=';l++);
      for(k=0,count=0,p=0;k<l;k++)
      if(toupper(ch[i+k])==acronym[j][k]) count++;
      if(count==l) {i+=l-1; for(l+=1;acronym[j][l]!='';l++) cout<<acronym[j][l]; p=1; break;

}
    }
    if(p==0)
    cout<<ch[i];
}
}

void main()
{
clrscr();
int acr=2, c;
char ch[160], acronym[9][36]={"LOL=laughing out loud",
                  "IRL=in real life",
                  "AFK=away from keyboard",
                  "BFF=best friends forever",
                  "FWT=for the victory",
                  "IIRC=if I recall correctly",
                  "IMHO=in my humble opinion",
                  "NVM=never mind",
                  "TTYL=talk to you later"

};
cout<<">if you want to upgrade the program's acromyms' list then enter button ";
c=getch();
if(c==85||c==117) upgrade(acr);
clrscr();
cout<<">Enter your tweet"; cin.getline(ch,160);
search(ch,acronym,acr);
cout<<" >Converting user's tweet ";
display(ch,acronym,acr);
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote