#include #include #include "candidate.hpp" int main() { using namespace ivl; using namespace std; // expressions [continued] const array a = arr(0.1, 0.2, 0.3, 0.2, 0.1); double mu = 0.3, sigma = 0.1; array N(a.size()); for(int i = 0; i < N.size(); i++) { N[i] = 1.0 / (sigma * sqrt(2 * pi)) * exp(-1.0 / (2.0 * _[sigma] ->* 2) * _[a[i] - mu] ->* 2); } cout << "N = " << N << endl; // iterators array b = arr(9, 4, 7); // ex 2: cout << b ->* 2 << endl; sort(b.begin(), b.end()); cout << "b sorted = " << b << endl; cout << "these are the 3! permutations of the elements of " << b << endl; do { cout << b << endl; } while ( next_permutation(b.begin(), b.end()) ); // range arrays int ca[12] = { 7, -9, 3, 8, -1, 0, -3, 5, -6, 0, 8, -4 }; array c(ca); cout << "c = " << c << endl; array d = c[3,_,2,_,11]; cout << "d = " << d << endl; c[0,_,7] *= 2; cout << "c = " << c << endl; // boolean arrays cout << "c < 0 = " << (c < 0) << endl; using ivl::find; cout << "find(c < 0) = " << find(c < 0) << endl; cout << "c[c < 0] = " << c[c < 0] << endl; array list = arr( cand("bob",7,10), cand("carol",8,7), cand("ted",5,9), cand("alice",8,3) ); cand ch("charlie",7,2); array f = list > ch; cout << "candidates " << list[f] << " are better than " << ch << endl; // indirect arrays size_array p = find(c < 0); cout << "p = " << p << endl; cout << "c[p] = " << c[p] << endl; p = idx(3, 4, 6, 7, 8, 10); cout << "p = " << p << endl; cout << "c = " << c << endl; c[p] += 1; cout << "c = " << c << endl; p = idx(1,1,9,9,4,9,1); cout << "p = " << p << endl; cout << "c[p] = " << c[p] << endl; // indirect arrays list.push_back(ch); cout << "all candidates now are " << list << endl; array score = 7 * list[&cand::grade] + 3 * list[&cand::ref]; cout << "score = " << score << endl; using ivl::max; array best = list[score == max(score)]; cout << "best candidates now are... the following one: " << best << endl; // ex 3: cout << list[list > ch][&cand::grade] << endl; }