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
The _____ is the button that you push to take a photograph. i think its B Help PLZ
Sati [7]

Answer:

C

Explanation:

see the image on this web site as example: https://www.digitaltrends.com/photography/what-does-this-do-an-explanation-of-dslr-buttons/

4 0
4 years ago
If a business owner wanted to create a banner ad for his business on his webpage, he could use Java programming to develop a (n)
hichkok12 [17]

The answer is applet

An applet is a fully functional Java application that is usually embedded within a HTML page and runs in a web browser. It has the entire Java API at its disposal and extends the java.applet.Applet class. Its class provides the standard interface between the applet itself and the environment of the browser.

8 0
4 years ago
Read 2 more answers
Liz will use a CD-R compact disk to write to more than once. Carlo will use a CD-RW compact disk to write to more than once. Who
Helen [10]
A. Only Carlo is correct.

CD-R drives once burned cannot be reused, however CD-RW can be rewritten for up to 1000 times.
8 0
4 years ago
Please answer quick:))))
Anika [276]
I think B and the second one C
8 0
3 years ago
Virtual classrooms are examples of communication or not​
3241004551 [841]

Answer:

I would say yes

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • In the two-level directory, if a user refers to a particular file then__________________ Select one: a. only his/her own UFD (us
    7·1 answer
  • Write a recursive function, len, that accepts a parameter that holds a string value, and returns the number of characters in the
    7·1 answer
  • Most smartphones use operating systems developed by ________.
    10·1 answer
  • Create a script that asks for the visitor's weight in pounds and his/her height in inches. The program should then calculate the
    13·1 answer
  • What are the two types of computers
    15·2 answers
  • What is wrong with this line of python code
    9·1 answer
  • Given the declaration Circle x = new Circle(), which of the following statements is most accurate?
    11·1 answer
  • They have requested a 1- to 2-page memo that describes the hospital's protections against a ransomware attack.
    10·1 answer
  • Explain how a magnetic hard disk drive (HDD) operates.
    12·1 answer
  • Q.3.1 Explain why devices on a network need addresses. (5)​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!