C/C++

Помогите пожалуйста решить

Дан вектор (массив переменного размера используя по возможности операции методы типа класса vector выполнить следующие действия заполнить массив случайными числами Найти максимальный положительный элемент Вычислить произведение элементов массива Вывести положительные Элементы на экран
язык с++
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <random>
#include <vector>
#include <iterator>
#include <numeric>
#include <cstdlib>
using namespace std;
int main() {
uniform_int_distribution<> uid(-32, 32);
mt19937 gen{ random_device()() };
auto rand = [&] { return uid(gen); };
const auto length = 12;
vector<int> box(length);
generate(box.begin(), box.end(), rand);
copy(box.begin(), box.end(), ostream_iterator<int>(cout, " "));
puts("");
auto max = *max_element(box.begin(), box.end());
auto positive = [](int x) { return x > 0; };
if (find_if(box.begin(), box.end(), positive) != box.end()) cout << "max: " << max << '\n';
else puts("Positive not found!");
auto product = accumulate(box.begin(), box.end(), 1LL, multiplies<>());
cout << "product: " << product << '\n';
vector<int> pos;
copy_if(box.begin(), box.end(), back_inserter(pos), positive);
cout << "positive: ";
copy(pos.begin(), pos.end(), ostream_iterator<int>(cout, " "));
puts("");
system("pause > nul");
}
ДК
Дмитрий Канаев
61 047
Лучший ответ
#include < iostream >
#include < vector >
#include < random >
#include < ctime >

using namespace std;

void fillWithRandoms(vector< double > &a_, int N){
srand(time(NULL));
while(N--)
a_.push_back(rand() % 21 - 10);
}

double findMaxPositiveElement(vector< double > &a_){
double res = 0;
for(auto &i: a_)
res = max(res, i);
return res;
}

double productOfVector(vector< double > &a_){
double res = 1;
for(auto &i: a_)
res *= i;
return res;
}

void showPositiveElements(vector< double > &a_){
for(auto &i: a_)
if(i > 0)
cout << i << " ";
}

int main(){
int n;
cin >> n;
vector< double > a;
fillWithRandoms(a, n);
cout << "Vector a = ";
for(auto &i: a) cout << i << " ";
double positiveMax = findMaxPositiveElement(a);
if(positiveMax > 0)
cout << "\nMax positive element = " << positiveMax;
else
cout << "\nThere are no positive elements in the vector";
double vectorProduct = productOfVector(a);
cout << "\nProduct of vector elements = " << vectorProduct;
cout << "\nPositive elements in vector: ";
showPositiveElements(a);
}