✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
#define main1 main
/** Question C1
What is output of the program?
*/
//Q-stl-1: std::ranges::for_each; std::ranges::count; std::ranges::count_if;
//std::ranges::all_of; std::ranges::none_of
#include <iostream>
#include <vector>
#include <algorithm>
int main1() {
std::vector<int> v = {-4, 3, -2, 2, -9, 3, -4, 0};
auto it1 = std::ranges::find(v, -2);
auto it2 = std::ranges::find_if(v, [](int x){
return x > 0;
});
auto itMin = std::ranges::min_element(v);
auto itMax = std::ranges::max_element(v);
int p1 = (it1 == v.end()) ? -1 : static_cast<int>(it1 - v.begin());
int p2 = (it2 == v.end()) ? -1 : static_cast<int>(it2 - v.begin());
std::cout << p1 << "|" << p2 << "|" << *itMin << "|" << *itMax;
return 0;
}
Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!