1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Blababa [14]
3 years ago
5

Write code that inserts userItem into the output string stream itemsOSS until the user enters "Exit". Each item should be follow

ed by a space. Sample output if user input is "red purple yellow Exit":
Computers and Technology
1 answer:
My name is Ann [436]3 years ago
3 0

Answer:

<h2>C++ Code:</h2>

#include <iostream>  //header file for input output functions like cout cin

#include <sstream>  // reads from string as a stream

#include <string> // header file for strings

using namespace std;   //  used for computer to detect  endl cout, cin

int main() {  //start of the main function of the program

string userItem;  // declare string type variable

ostringstream itemsOSS;   // output string stream    

cout << "Enter items (type Exit to quit):" << endl;  

// prompts user to enter items and type Exit to quit

cin >> userItem;   //reads input userItems

while (userItem != "Exit") {   //loop that runs untill userItem gets equal to Exit

itemsOSS << userItem << " ";

  // inserts userItem into the output string stream itemsOSS

cin >> userItem; }   //reads items stored in userItem variable

cout << itemsOSS.str() << endl;}   // prints current contents of the itemsOSS.                                                                                              

<h2>Explanation:</h2>

I will explain the code line by line.

  • The first line includes a header file iostream which is used for input and output functions such as cin, cout etc.
  • The next line includes sstream header file to read from a string as a stream. String streams are streams containing strings. Strings are treated like streams and stream operations are used on these strings.
  • The next line includes string header file in order to use strings in the program.
  • Next line namespace is used for the computer to identify objects like endl, cin, cout.
  • This lines starts the main function and enters the body of main function.
  • A string type variable userItem is declared.
  • ostringstream type variable itemsOSS is declared. ostringstream class works on strings.
  • This line prompts the user to enter the items and type Exit word to quit. endl is used to insert new line.
  • This line read input from variable userItem which is inserted by the user.
  • This statement starts a loop which will continue to execute until the user types Exit.
  • In the body of while loop, this line shows that the items entered by the user  in userItem will be inserted into the output string stream itemsOSS. Every userItem is followed by a space. << this is insertion operator. This retrieves items from the input sequence and inserts them into the itemsOSS, until Exit is typed.
  • Next line reads items stored in userItem variable.
  • str() returns a copy of the string which is manipulated by the current stream string and it outputs the contents of the itemsOSS stream.
<h2>Output:</h2>

Enter items (type Exit to quit):

red purple yellow Exit

red purple yellow

You might be interested in
A network manager prevents users accessing certain websites. She does this by setting up:
Rus_ich [418]

Answer:

A or B

Explanation:

Firewalls and internet filters are the same thing, people nowadays tend to use "internet filters" more, but again they mean the same thing.

7 0
4 years ago
Combustion is an example of to energy conversion.
Marizza181 [45]
If this is a true or false question I would say true... but I dont know I’m confusion <3
7 0
3 years ago
You can create a negative indent, sometimes called a(n) ________________, by dragging the indent markers on the ruler to the lef
Murljashka [212]
B is the best answer
I hope it’s work
8 0
3 years ago
How can presentation software be used in a business or professional setting? Choose all that apply.​
ahrayia [7]

Answer:

Presentations are commonly projected onto a whiteboard a large screen.

Slides can also be printed out onto clear acetate and used with a overhead projector (0HP) to project the contact onto a screen. If this method is used each acetate side usually has to be replaced my newly.

Presentations can also be set up to play through a large did you go display in reception areas of the hotels, schools, businesses etc.

3 0
4 years ago
What are the responsibilities of the DBA and the database designers?
Ratling [72]

Answer:

Explanation:

DBA's main responsibility is making sure that there is enough CPU, disk, memory, and network bandwidth available, as well as making backups every so often. Meanwhile, the database designers/developers are responsible for investigating and implementing what the end-user needs and making sure that the database holds all of the information that the end-user will be using.

3 0
3 years ago
Other questions:
  • Which of the following statements BEST describe why Agile is winning?
    14·2 answers
  • A one page document that introduces you, your skills and background and asks for an interview is an example of what type of docu
    5·2 answers
  • Name three actions you can perform on an inserted image.
    7·2 answers
  • How does is make you feel when you're kind to others? What are some opportunities in your life to be more kind to your friends a
    9·1 answer
  • Sami is creating a web page for her dog walking business. Which item will set the theme for her page? Background color Heading c
    11·2 answers
  • What is the purpose of a report?
    14·1 answer
  • The process of recording and reporting the financial data for a business is known as:
    6·2 answers
  • What is a fundamental difference between the SAP platform and the AirBnB platform?
    10·1 answer
  • What is the address space of a computer with a 64-bit address bus?
    7·1 answer
  • Which window would show you bindings for local area connection 2?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!