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
Write an algorithm to display your name 10 times​
Tasya [4]

Hey this code was made in java if you have any issues let me know

package nametest;

public class Nametest {

   

   public static void main(String[] args) {

       System.out.println("namehere");

        System.out.println("namehere");

         System.out.println("namehere");

          System.out.println("namehere");

           System.out.println("namehere");

            System.out.println("namehere");

             System.out.println("namehere");

              System.out.println("namehere");

               System.out.println("namehere");

                System.out.println("namehere");

       

   }

   

}

Hope it helps

-scav

4 0
3 years ago
Why are I/O (input/output operations) important in database environment?
Eddi Din [679]

Answer:  

Database environment is created by storing the data and other related components.The input-output action takes place in the database when the reading and writing of the record units of block is to be done to and from disk unit to memory storage.

The database engine is responsible for reading action of the record before entering it to the memory and then stores it. If the data record unit is to be exported to the disk then output action takes place .It also helps in performing indexing ,vacuuming, portioning etc the information Thus, I/O is important for database.

 

7 0
3 years ago
The scheme function (mult2-diff Ist) should take one argument, a list of numbers, and results in multiplying each number in the
JulijaS [17]

Answer:

The solution code is written in Python.

  1. def mult2_diff(lst):
  2.    num_list = []
  3.    for x in lst:
  4.        num_list.append(x * 2)
  5.    diff = num_list[0]
  6.    for i in range(1, len(num_list)):
  7.        diff = diff - num_list[i]
  8.    
  9.    print(diff)

Explanation:

Firstly, based on the requirement stated in the question, define a function <em>mult2_diff() </em>that takes one argument, <em>lst</em>, which is a list of numbers (Line 1).

This function is expected to multiply each number in the list by two and then followed with computing the difference. To do so, let's try to attempt the first function task, multiplying numbers.  Create a new list, num_list, to hold the multiplied numbers (Line 2). Use a for loop to traverse through each number in the input list, <em>lst</em>, and multiply each of them by two and add it to the <em>num_list </em>(Line 4-5).

To attempt the second function task, create another variable, <em>diff</em>, to hold the value of calculated difference between the numbers in the <em>num_list</em>. Initialize <em>diff </em>with the first number in the <em>num_list</em>. Use a another for-loop to traverse through each number in the num_list starting with second index, <em>1</em>, and calculate the difference between the <em>diff </em>and the current number extracted from the <em>num_list </em>through indexing.

At last print the output of <em>diff</em> (Line 11).

6 0
3 years ago
Different between ocular and compound miscroscope
Nuetrik [128]
<span>One system of lens - ocular microscope
Two systems of lens - compound microscope

Some of the parts of a compound microscope are the </span>eyepiece lens.<span> There are two knobs on under the other to one side of the microscope which are used for </span>Coarse focus and Fine focus. There is an illuminator<span> at the bottom of the microscopic stand, which sheds a powerful light on the subject under the lens. Other parts include </span>objective lenses<span>, </span>stage with stage clips<span> (where the subject is placed) and r</span>evolving nosepiece. The tube<span> connects the eyepiece lens to the </span>turret<span>.</span>
3 0
3 years ago
If a website ends with .gov does it mean that its written by the government or?
Soloha48 [4]
Umm... No. (I'm pretty sure)
7 0
2 years ago
Read 2 more answers
Other questions:
  • Which statement is true about the elements of the interface of a presentation program? The status bar appears at the top of the
    14·2 answers
  • In a computerized accounting system, each transaction that is analyzed must be entered by hand into the appropriate journal and
    12·2 answers
  • Write a function max arguments. write a program that reads three floating-point numbers, uses the max function, and displays the
    5·1 answer
  • Is it possible to learn java s. and c# at the same time? if so I need help who can assist me.
    5·1 answer
  • Draw a logic circuit for the function F = (A + B)(B + C)(A + C), using NOR gates only. ​
    9·1 answer
  • What does resolution mean on a computer monitor?
    9·2 answers
  • Many bookstores have closed since the rise of the Internet. What type of
    11·1 answer
  • When looking at security standard and compliance, which three (3) are characteristics of best practices, baselines and framework
    8·1 answer
  • Sharl downloads images from an online library and uses them in her work. The images are shared under the Creative Commons Attrib
    13·1 answer
  • with a ____ the traffic of a given enterprise or group passes transparently through an internet in a way that effectively segreg
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!