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

This output Write a program that will continually prompt for the user name and t

ID: 3541734 • Letter: T

Question


This output


Write a program that will continually prompt for the user name and then prompt for multiple lines of text messages. (The user name consists of only one word.) The text message entry is terminated when in a new line, the user enters "! !" and the enter key, i.e. a line with only the string " ! ! ". The string "! !" must NOT be included in the message. When the program reads the inputs, it will then store the user name and their message into a message buffer that is of the C++ string class. There is only one shared message buffer to store multiple user names and their messages. All messages must be prepended to the message buffer, i.e. the latest message must be placed before the older messages in the shared message buffer. In other words, the shared message buffer contains messages that are in reverse chronological order. The format for prepending the username and message into the shared message buffer is as follows. The user name must first be enclosed by the strings "{ [" and " ] }"followed by the user message before preappending into the shared message buffer. Examples are shown in Questions (2) and (3) above. After a user terminated their message, the program will then prompt if there is any more user name. If the answer is "yes", then it starts the cycle again. The name of the next user name and message will be prepended to the same shared message buffer. Note that the start of each user name and message can be detected by the string " { [".If the answer is "no", it will then proceed to the next stage of outputting the user names and messages stored in the shared message buffer. The output will display the text, "The current messages are: " and then must show all the user names and messages stored in the shared message buffer in reverse chronological order, i.e. the latest message first. Each message must start on a new line, where the user name is printed followed by the character and a newline and then the user message. Your program must print a blank line after each message.

Explanation / Answer

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

int main()
{
    string line,username,decision;
    string message="",umessage="",finalmessage="";
    while(true)
    {
       
    cout<<"Enter user name >"<<endl;
    cin>>username;
    cout<<"Enter the message >"<<endl;
    while (true) {
        getline(cin, line);
       
        if (line=="!!") {
            break;
        }
        else
        umessage = umessage + line+" ";
        // some code
    }
    message="{["+ username +"]}"+ umessage;
    finalmessage.insert(0, message);
    umessage="";
    message="";
    cout<<"Any more users: >"<<endl;
    cin>>decision;
    if(decision=="no")
    {
        break;
    }
   
    }
   
    int first=0,last;
    cout<<"The current messages are:"<<endl;
    while(1)
    {
        first=finalmessage.find("{[",first);
        last=finalmessage.find("]}",first+2);
        cout<<finalmessage.substr(first+2,last-(first+2))<<":";
        first=finalmessage.find("{[",last);
        if(first==-1)
        {
            cout<<finalmessage.substr(last+2,finalmessage.length()-last-2);
            break;
        }
        cout<<finalmessage.substr(last+2,first-last-2);
       
        first=last+2;
    }
    int num;
    cin>>num;
   return 0;
}

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