Question

In: Computer Science

3.24 LAB C++ : Program: Text message decoder (1) Use getline() to get a line of...

3.24 LAB C++ : Program: Text message decoder

(1) Use getline() to get a line of user input into a string. Output the line. (3 pts)

Ex:

Enter text:
IDK if I'll go. It's my BFF's birthday. 
You entered: IDK if I'll go. It's my BFF's birthday.


(2) Search the string (using find()) for common abbreviations and print a list of each found abbreviation along with its decoded meaning. (3 pts)

Ex:

Enter text:
IDK if I'll go. It's my BFF's birthday. 
You entered: IDK if I'll go. It's my BFF's birthday. 
BFF: best friend forever
IDK: I don't know

Support these abbreviations:

  • BFF -- best friend forever
  • IDK -- I don't know
  • JK -- just kidding
  • TMI -- too much information
  • TTYL -- talk to you later

pls help this is so confusing!!

Solutions

Expert Solution

Please find your solution below and if any doubt or need change comment.And do upvote.

CODE:

#include <iostream>
#include<string>
using namespace std;

int main()
{
    string str;
    int index;
    //take input using getline
    cout<<"Enter text:"<<endl;
    getline(cin,str,'\n');
    cout<<"You entered: "<<str<<endl;
    
    //using find() function find if these  string 
    //are present or not 
    index = str.find( "BFF", 0 );
    if( index != string::npos )
    {
       cout<<"BFF: best friend forever\n";
    }
    index = str.find( "IDK", 0 );
    if( index != string::npos )
    {
       cout<<"IDK: I don\'t know\n";
    }
    index = str.find( "JK", 0 );
    if( index != string::npos )
    {
       cout<<"JK: just kidding\n";
    }
    index = str.find( "TMI", 0 );
    if( index != string::npos )
    {
       cout<<"TMI: too much information\n";
    }
    index = str.find( "TTYL", 0 );
    if( index != string::npos )
    {
       cout<<"TTYL: talk to you later\n";
    }

    return 0;
}

OUTPUT:


Related Solutions

C++ Text message decoder Use getline() to get a line of user input into a string:...
C++ Text message decoder Use getline() to get a line of user input into a string: Enter text: IDK if I'll go. It's my BFF's birthday. Search the string using find() for common abbreviations and replace() them with their long form. In addition, use a for loop to iterate through each character of the string and replace any occurences of '.' with '!': Enter text: IDK if I'll go. It's my BFF's birthday. I don't know if I'll go! It's...
A Java program that deciphers each message by building the string. Each line of the text...
A Java program that deciphers each message by building the string. Each line of the text file contains either a word or a command followed by a forward slash and the requirements of the command. A Stack Implementation is needed as. As you read the data from the text file, you need to know if it is a new phrase or command. The commands are: i – an insert followed by the letters, numbers, or symbols that need to be...
Infile and getline - how can I change this code to get the whole line from...
Infile and getline - how can I change this code to get the whole line from a text file? Right now it only gets the first word each time it reads. NUMBER can be any integer. This code gets strings that are in multiple lines from a text file. Some words are separated by whitespace and that makes the input wrong. It only works if there is only one word. infile >> arrayOne[dive] >> arrayTwo[dive]; while (infile && dive< NUMBER)...
Implement a Message Authentication Code program in either C/C++ or Python. 1. Accept a message as...
Implement a Message Authentication Code program in either C/C++ or Python. 1. Accept a message as keyboard input to your program. 2. Accept a secret key for the sender/recipient as keyboard input to your program. 3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85 + 67 = 378....
Create a message encoder/decoder. PLEASE USE BASIC PYTHON METHODS/FUNCTIONS. The user enters a message that could...
Create a message encoder/decoder. PLEASE USE BASIC PYTHON METHODS/FUNCTIONS. The user enters a message that could only include alphabetic letters and space. There are 26 alphabetic letters. Consider space the 27th letter. The user then enters a shift code that should be an integer between -26 and 26. The application will show the encoded/decoded message based on the shift code entered. If you encode a message, each letter in the message will be moved forward through the alphabet according to...
Whenever I am attempting to write a simple program on C++ I get an error message...
Whenever I am attempting to write a simple program on C++ I get an error message that reads "cout was not declared in this scope". Literally every time. This has become frustrating because I have even written my code the exact same way as some of my classmates who got theirs to compile and run with no sign of this error at all, and yet min gives this answer. I will leave an example of a code where this error...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder...
Write a c or matlab text code(to be copied ) for Huffman coder and Huffman decoder that asks the user to enter the string and output the Huffman code for every letter and a code for encoding that will have every letter and its Huffman code and output all the possibilities for the real string. you must show a screen of an input and the output for both the encoder and the decoder
C++ Write a program that reads a line of text, changes each uppercase letter to lowercase,...
C++ Write a program that reads a line of text, changes each uppercase letter to lowercase, and places each letter both in a queue and onto a stack. The program should then verify whether the line of text is a palindrome (a set of letters or numbers that is the same whether read forward or backward). Please use a Queue Class and Stack class.
Write a program that takes in a line of text as input, and outputs that line...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH IN C++ PLEASE!
Write a Java program to read in text line by line until a blank line is...
Write a Java program to read in text line by line until a blank line is entered. When this occurs the program returns the total number of words and characters found as shown in the example below. A program to count the number of words and characters in an input text block. Enter text line by line; blank line to end. >> This is the first line of text >> Followed by the second line of text >> Ending with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT