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
skelet666 [1.2K]
1 year ago
8

8.11 lab: filter and sort a listwrite a program that gets a list of integers from input, and outputs non-negative integers in as

cending order (lowest to highest).ex: if the input is:10 -7 4 39 -6 12 2the output is:2 4 10 12 39 for coding simplicity, follow every output value by a space. do not end with newline.
Computers and Technology
1 answer:
Sergio039 [100]1 year ago
6 0
<h3>How to filter and sort a listwrite a program that gets a list of integers from input, and outputs non-negative integers in ascending order?</h3>

Here is an example of a program that gets a list of integers from input and outputs non-negative integers in ascending order:

<em>#include <iostream></em>

<em>#include <algorithm></em>

<em>#include <vector></em>

<em />

<em>using namespace std;</em>

<em />

<em>int main()</em>

<em>{</em>

<em>    // Read integers from input and store them in a vector.</em>

<em>    vector<int> numbers;</em>

<em>    int n;</em>

<em>    while (cin >> n)</em>

<em>    {</em>

<em>        numbers.push_back(n);</em>

<em>    }</em>

<em />

<em>    // Filter out negative numbers from the vector.</em>

<em>    numbers.erase(remove_if(numbers.begin(), numbers.end(), [](int n) { return n < 0; }), numbers.end());</em>

<em />

<em>    // Sort the remaining numbers in ascending order.</em>

<em>    sort(numbers.begin(), numbers.end());</em>

<em />

<em>    // Output the sorted numbers.</em>

<em>    for (int n : numbers)</em>

<em>    {</em>

<em>        cout << n << " ";</em>

<em>    }</em>

<em />

<em>    return 0;</em>

<em>}</em>

<em />

<h3>What is CIN stream?</h3>

This program uses the cin stream to read integers from input and stores them in a vector. Then, it uses the remove_if and sort algorithms to filter out negative numbers and sort the remaining numbers in ascending order. Finally, it outputs the sorted numbers using the cout stream.

To test the program, you can enter a list of integers from the keyboard, followed by the end-of-file indicator (Ctrl+D on Unix-like systems or Ctrl+Z on Windows), and the program will output the non-negative integers in ascending order. For example, if you enter the following input:

<em>>>> 10 -7 4 39 -6 12 2</em>

The program will output the following:

<em>>>> 2 4 10 12 39</em>

This program is not the only way to solve this problem, but it is a simple and effective solution that uses the standard library functions and algorithms.

To Know More About Non-Negative Integers, Check Out

brainly.com/question/19346430

#SPJ4

You might be interested in
Using computers can lead to a number of physical safety issues. State and explain TWO(2) of these types of issues.​​​​​
Ira Lisetskai [31]

The types of issues that is seen are:

  • Electrocution
  • Fire
  • Tripping over wires and others.

<h3>What is the physical safety about?</h3>

There are a lot of of physical safety issues that can come up from using ICT devices.

A fire outbreak can occur if there is an issue with the wiring of the computer system or when there is too much voltage supplied and this is therefore a type of physical safety issues in the computer room.

Note that Electrocution is said to be the death or bad injury that is known to be caused as a result of an electric shock from electric current that tends to pass through the body.

Hence, The types of issues that is seen are:

  • Electrocution
  • Fire
  • Tripping over wires and others.

Learn more about Electrocution from

brainly.com/question/1810934

#SPJ1

6 0
2 years ago
What IEEE 802.11 wireless standard supports devices only in the 5GHz range with speeds up to 4.9Gb/s because of accepting data f
yKpoI14uk [10]

The answer is 802.11ac  

802.11ac is a type if IEEE 802.11 wireless standards that supports Multiple Input, Multiple Output antennas on sending and receiving data. This type of wireless connection supports 2.4GHz signal or frequency and data speed transfer up to 4.9Gbps. Each device or antenna can run up to 400Mbps each and the maximum device it can handle is up to 8 antennas.

8 0
3 years ago
What do both wireless lans (wlans) and wireless wans (wwans) rely on as the communication medium?
AnnyKZ [126]

Wireless lans (WLANS) and wireless wans (wwans) rely on as the radio frequency spectrum communication medium.

<h3>What is Radio spectrum?</h3>

The radio spectrum is known to be an aspect of the electromagnetic spectrum that is said to have frequencies from 0 Hz to 3,000 GHz.

Note that Wireless lans (WLANS) and wireless wans (wwans) rely on as the radio frequency spectrum communication medium for their functions.

Learn more about WLANS from

brainly.com/question/26956118

#SPJ12

4 0
2 years ago
Why the brain is most important???​
algol [13]

Answer:

It helps our body function

Explanation:

3 0
3 years ago
Read 2 more answers
Which kind of tablet positions the case below a keyboard, providing functionality similar to that of a laptop?
lianna [129]
The appropriate response is convertible. A convertible portable figuring gadget has a show screen and cover upheld at three focuses for stable development between a shut position, a tablet PC operational position and a tablet PC operational position. A web pivot gathering essentially couples along a collapsing hub on the cover side of the show screen and to the back negligible edge of the base unit with which the show screen participates.
4 0
3 years ago
Other questions:
  • which type of website would a business selling merchandise on the internet use? A person B information C commercial D social
    9·1 answer
  • Declare a character variable letterStart. Write a statement to read a letter from the user into letterStart, followed by stateme
    10·1 answer
  • In a natural-language processing (NLP) system, the _____ activity involves using the computer to read large amounts of text and
    5·1 answer
  • What does sustainable mean<br>​
    7·1 answer
  • Write the definition of a function named rotate4ints that is passed four int variables. The function returns nothing but rotates
    9·1 answer
  • Universal Container sales reps can modify fields on an opportunity until it is closed. Only the sales operations team can modify
    13·1 answer
  • Why do nonprofit agencies include blogs on there website?
    10·1 answer
  • You are supposed to do a report on something that interests you. You decided to do a report on dogs. As you research, you take n
    14·1 answer
  • Private notes about individual slides that you leave for yourself or for others who might use the presentation file is called __
    13·1 answer
  • A scanner connected to your mac is giving problems and you suspect corrupted device drivers. What should you do first? second?.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!