65.3k views
4 votes
Write your code to define and use two functions. The Get User Values function reads in num Values integers from the input and assigns to user Values. The Output Ints Less Than Or Equal To Threshold function outputs all integers in user Values that are less than or equal to maxVal. num Values indicates the number of integers in user Values. void Get User Values(int user Values[], int num Values) void Output Ints Less Than Or Equal To Threshold (int user Values[], int maxVal, int num Values)

1 Answer

5 votes

Answer:

#include <iostream>

#include <vector>

using namespace std;

/* Define your function here */

vector<int> GetUserValues(vector<int>& userValues, int numValues) {

int tmp = 0;

vector<int> newVec;

for(int i = 0; i < numValues; i++) {

cin >> tmp;

newVec.push_back(tmp);

}

return newVec;

}

void OutputIntsLessThanOrEqualToThreshold(vector<int> userValues, int upperThreshold) {

for (int i = 0; i < userValues.size(); ++i) {

if(userValues.at(i) < upperThreshold) {

cout << userValues.at(i) << " ";

}

}

cout << endl;

}

int main() {

vector<int> userValues;

int upperThreshold;

int numValues;

cin >> numValues;

userValues = GetUserValues(userValues, numValues);

cin >> upperThreshold;

OutputIntsLessThanOrEqualToThreshold(userValues, upperThreshold);

return 0;

}

Step-by-step explanation:

Perhaps their is a better way to code this, but I couldn't figure out what to do with the pointer in the first function.

User NoorJafri
by
4.8k points