Write a program called lol.cpp that allows the user to enter a sentence. Then pr
ID: 3772598 • Letter: W
Question
Write a program called lol.cpp that allows the user to enter a sentence. Then program then searches the sentence for various lolspeak abbreviations and substitutes them with the proper words. You should have a function named LOLSpeak that takes your sentence as a parameter and returns the corrected sentence. Make your program work with the three abbreviations below AND at least 7 more of your own (total 10).
Note: You cannot use a normal cin statement to input a sentence (it truncates after the first space).
char Input[80];
cout << "Enter a sentence: ";
cin.getline(Input, 80, ' ');
string Sentence = Input;
Program 2 Example Output
This program will correct ur lolspeak abrreviations.
Enter a sentence:
U look gr8 today. I will ttyl when I see you 2nite.
The corrected sentence:
You look great today. I will talk to you later when I see you tonight.
Explanation / Answer
#include<iostream>
#include<string>
#include<stdio.h>
#include <map>
#include <cstring>
using namespace std;
string LOLSpeak(char* sentence,map<string,string> mp){
//char s =(char *) sentence;
char * pch;
string s="";
map<string,string>::iterator it;
pch = strtok(sentence," ");
while(pch!=NULL){
//cout<<pch<<" ";
it = mp.find(pch);
if (it != mp.end()){
// cout<<mp[pch]<<" ";
s=s+mp[pch]+ " ";
}
else{
// cout<<pch<<" ";
s = s+ pch + " ";
}
//cout<<mp.find(pch)->second;
pch = strtok(NULL," ");
}
return s;
}
int main(){
char input[80];
map<string,string> mp;
mp["u"] = "you";
mp["lol"] = "laughing out loud";
mp["brb"] = "be right back";
mp["gr8"] = "great";
mp["ttyl"] = "talk to you later";
mp["2nite"] = "tonight";
mp["2day"] = "today";
mp["asap"] = "as soon as possible";
mp["lmao"] = "laughing my ass off";
mp["aka"] = "also known as";
mp["b4"] = "before";
mp["bf"] = "boyfriend";
cout<<"This program will correct ur lolspeak abrreviations. ";
cout<<"Enter a sentence: ";
cin.getline(input,180,' ');
string sentence = LOLSpeak(input,mp);
cout<<" The corrected sentence: "<<sentence;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.