01: #include <iostream> 02: #include <vector> 03: using namespace std; 04: /** 05: Returns the positions of all values within a range 06: @param v a vector of floating-point numbers 07: @param low the low end of the range 08: @param high the high end of the range 09: @return a vector of positions of values in the given range 10: */ 11: vector<int> find_all_between(vector<double> v, 12: double low, double high) 13: { vector<int> pos; 14: for (int i = 0; i < v.size(); i++) 15: if (low <= v[i] && v[i] <= high) 16: pos.push_back(i); 17: 18: return pos; 19: } 20: 21: int main() 22: { vector<double> salaries(5); 23: salaries[0] = 35000.0; 24: salaries[1] = 63000.0; 25: salaries[2] = 48000.0; 26: salaries[3] = 78000.0; 27: salaries[4] = 51500.0; 28: 29: vector<int> matches 30: = find_all_between(salaries, 45000.0, 65000.0); 31: 32: for (int j = 0; j < matches.size(); j++) 33: cout << salaries[matches[j]] << "\n"; 34: return 0; 35: }