162k views
1 vote
I am trying to figure this out but every type of coding I put in has errors or it states that the things aren't the same. This coding is being done in C++.

Get a line of text from the user. Output that line. (1 pt) Ex: Enter text: IDK how that happened. TTYL. You entered: IDK how that happened. TTYL. (2) Output the line again, this time expanding common text message abbreviations. (5 pts) Ex: Enter text: IDK how that happened. TTYL. You entered: IDK how that happened. TTYL. Expanded: I don't know how that happened. talk to you later. Support these abbreviations: BFF -- best friend forever IDK -- I don't know JK -- just kidding TMI -- too much information TTYL -- talk to you later Note: If an abbreviation appears twice, only expand its first instance.

User Halfak
by
4.9k points

2 Answers

2 votes
How might a company go about performing a load test on their website?
User Fsevenm
by
5.1k points
2 votes

Final answer:

To solve this schoolwork task, you need to read a text input using getline in C++, store it in a string, then find and replace specific abbreviations from the string, ensuring that each is only expanded once before outputting the updated string.

Step-by-step explanation:

The code in question requires you to read a line of input from the user in C++, output it, and then re-output the same line with certain abbreviations expanded to their full forms. Utilizing the getline function will allow you to read an entire line into a string, then use conditional statements to find and replace abbreviations before printing it out.

To ensure each abbreviation is only expanded once, a flag can be used for each abbreviation to indicate whether it has been expanded already. Here is a simple code outline to help you get started:

\#include <iostream>
#include <string>

int main() {
std::string text;
std::cout << "Enter text: ";
std::getline(std::cin, text);
std::cout << "You entered: " << text << '\\';

// Code to search for abbreviations and replace them
// while ensuring each is expanded only once

std::cout << "Expanded: " << expandedText << '\\';

return 0;
}
User Marcelo Diniz
by
4.7k points