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
X = 0
cricket20 [7]

The missing line would be x+= num

This means that every time a number is selected from the range it is added to the value of x.

3 0
2 years ago
What should be a technicians first step in an A/C system
hram777 [196]
A technician's first step with an A/C system is to perform visual inspection
8 0
3 years ago
What is the purpose of the Zoom dialog box? to put the selected range in ascending order in a query to put the selected range in
AlekseyPX

The zoom dialog box helps to enter text and expressions in tight places, such as a property sheet or Query Design view. You can resize the zoom box and change the font. And the zoom box remembers the size and font each time you use it.

Use the

5 0
3 years ago
Read 2 more answers
Play station account
Reika [66]
I have a PlayStation as well
4 0
2 years ago
Read 2 more answers
In 2-5 paragraphs, describe how you would create a new database using your software.
Nikitich [7]

Answer:

1. open the software

2. select a new blank database or database wizard

3. name the database

4. enter field names and select the type of field (text, number, date, currency)

5. make one of the fields the primary key

6. click done, or save and close

7. open the table and add records

5 0
2 years ago
Other questions:
  • A drop-down menu must be contained by
    5·1 answer
  • ________ consists of detailed, preprogrammed instructions that control and coordinate the computer hardware components in an inf
    11·1 answer
  • _______ is a form of crime that targets a computer system to acquire information stored on that computer system, to control the
    12·1 answer
  • Who initially developed what is now known as the internet?
    5·1 answer
  • What major criteria must a product or process meet in order to be considered emerging technology?
    7·1 answer
  • What will be result of below if statement.
    13·1 answer
  • A ____ can be used to enter, display, or edit data
    5·1 answer
  • If you would like to give another user permissions on your mailbox or to particular folders within your mailbox, which role shou
    13·2 answers
  • Five uses of the operating system​
    10·2 answers
  • The famous arcade game Space Invaders was first adapted to which home console?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!