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
Consider the following class interfaces:
o-na [289]

Answer:

class teacher and student I didn't actually read it but I think it is class student

6 0
3 years ago
Which of the following sorting algorithms is described by this text? "Take the item at index 1 and see if it is in order compare
trasher [3.6K]

Answer:

b. selection sort

b. 8 11 17 30 20 25

Explanation:

The options above are the correct answers to the given questions.

Selection sort is a simple comparison-based sorting algorithm.

selection sort. (algorithm) Definition: A sort algorithm that repeatedly searches remaining items to find the least one and moves it to its final location. The run time is Θ(n²), where n is the number of elements. The number of swaps is O(n).

It is this sorting algorithm that will best ne suitable in the given event.

7 0
3 years ago
Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
Neko [114]
The third one probably
5 0
3 years ago
Describe data center technology and its relevance to modern-day cloud computing. Support your opinion with cited information.( S
Masteriza [31]

Answer: Data center technologies are the innovations that support the IT(Information technology) department and its functioning like storing data, management, operating etc. Data centers provide the help in functioning of the cloud services.

The modern cloud computing services require data centers for operations protecting data when the the power of the network goes off or any other failure occurs while data is getting updated or accessed.

6 0
3 years ago
What is output by the following code?
Katarina [22]
The output is 2. The stuff() function receives a copy of n, changes it but the result is never used.
5 0
3 years ago
Other questions:
  • write a pseudo code and flow chart that take a number as input and prints multiplication table up to 10
    9·1 answer
  • Is a network traffic management device used to connect different network segments together?
    9·1 answer
  • The default _____ color is set when you type text.
    6·1 answer
  • Team A found 342 errors during the software engineering process prior to release. Team B found 184 errors. What additional measu
    12·1 answer
  • Does -8 = -21?<br>[this is NOT a trick question]<br>Yes....?<br>No!​
    12·2 answers
  • mta software development fundamentals You are creating an application that accepts input and displays a response to the user. Yo
    10·1 answer
  • HELP PLSSS I WILL MARK U!!!!
    10·2 answers
  • What read a page on website​
    15·1 answer
  • Amanda wants to prevent sensitive data from being sent via email in her organization. What type of agent software can she instal
    15·1 answer
  • When creating a report,you can mske groups and subgroups by?​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!