<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