Branching

Hello all!

I am very new to C++ and I am very confused on this assignment that I have. I have read through the chapters and watched several youtube videos but nothing is helping me to understand what I need to do. I need a very simple explanation on what I need to do with this assignment so I can truly understand what to do going forward. Thank you guys!!

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


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.



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.

1. std::string array[50][1] is what you will want to go with here imo. have the abbreviations in the first part, then the sentence? in the other.

2. std::string array[160] is what you would want to go with here, Getline has some interesting properties where you can separate each word into it's own section? of the array. From there just write a loop for (int i = 0; i < 160; i++ and look for common abbreviations

3. instead of writing a bunch of code all over again, just join it with 2. when it checks a word, have it print out on the screen, but if it's an abbreviation, print out the "not abbreviation".

I'm not the best at c++ but if I were to do it, this is how I would :D

@Radar: why are you making array of 160 strings? You only need one string.
Sorry for late response!
Here is what you want...........

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
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

//Function 1
void upgrade(int &acr)
{ acr=9; cout<<"\n\n>Successfully updated the file."; getch(); }


//Function 2
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<<'\n'<<acronym[i]; break;}
   }
  }
}


//Function 3
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]!='\0';l++) cout<<acronym[j][l]; p=1; break;}
    }
    if(p==0)
    cout<<ch[i];
  }
}



// Function main()
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<<">Press \"u\" if you want to upgrade the program's acromyms' list. ";
c=getch();
if(c==85||c==117) upgrade(acr);
clrscr();
cout<<">Enter your tweet(max. 160 characters): "; cin.getline(ch,160);
search(ch,acronym,acr);
cout<<"\n\n>Converting user's tweet......\n\n";
display(ch,acronym,acr);
getch();
}
@ Vibgyor: In addition to the many errors and all around bizarre structure and design choices in your post, you wrote it in the wrong language... Please revise.

@ OP: We're inevitably going to run into the "I can't use what they didn't teach me in class" crap, but since I don't know what you haven't been taught I'm just going to go with my first instinct and you can adjust my suggestions on the fly.

1.) I would suggest an std::map<std::string, std::string> to correlate the acronyms with their respective translations: http://www.cplusplus.com/reference/map/map/

2.) The 'tweet' should be stored in a single string like LB suggested. The reason for this is that it will allow you to more easily search for the acronyms with std::string.find(): http://www.cplusplus.com/reference/string/string/find/

3.) Swapping out the acronyms for their translations can be accomplished with std::string.replace() : http://www.cplusplus.com/reference/string/string/replace/
@Computergeek01


Computergeek01 wrote:
In addition to the many errors
Errors, huh? I can't find any, got anything to backup your claim, have you compiled it or you are too smart and don't need a compiler, well in later case you must confirm your words before you write them on forums, if you don't want to get messed up in your own lines and appear like a fool.

Computergeek01 wrote:
all around bizarre structure and design choices in your post
The way you do things is not the only way it can be done okay. And secondly the post wasn't for you so don't speak nonsense until I am teaching something inappropriate or irrelevant. If Kmac83 says that it's to complicated for him to follow the code then i'll work on it but for you, so called "pro", I am not gonna waste my time.

Computergeek01 wrote:
you wrote it in the wrong language
cplusplus.com is the name of website that's why all my codes are in that very language. I hope the explanation is enough.

Computergeek01 wrote:
Please revise.
Please revise in a C++ IDE

Computergeek01 wrote:
The 'tweet' should be stored in a single string like LB suggested
I did it the same way, if you your majesty can spare some time free time to take a look rough look.

Use a real C++ compiler from within the last five years: https://ideone.com/bynUu1
None of the headers you used are real C++ headers, I fixed that for you: https://ideone.com/kTU8zy so many errors!
You also don't even try to use std::string at all, opting for ancient C-style character arrays.
Last edited on
@LB
No such headers in my INCLUDE directory.
I have Turbo C++ (Version 3.0) is it's compiler outdated?

also using namespace std; gives error.
Any version of Turbo C++ is incredibly outdated. Don't use it unless you are forced to.

On Windows, use nuwen MinGW or Visual Studio 2015:
http://nuwen.net/mingw.html
https://www.visualstudio.com/products/vs-2015-product-editions (Community is free)

On Linux, use GCC or Clang. On Mac, use Clang/XCode.
Last edited on
@LB okay thanks for telling me. Currently I am being taught on Turbo C++ and I presumed it the latest.

[EDIT] Please browse to: http://www.cplusplus.com/forum/general/174405/
Last edited on
Topic archived. No new replies allowed.