Question: c + + Programming Exam: Implement assign, printVector, and main Functions in C + + Objective: Create three functions in C + + . The

c++ Programming Exam: Implement assign, printVector, and main Functions in C++
Objective: Create three functions in C++. The first, assign, is for entering numbers into a vector. The second is the main function, which calls assign to populate the vector, then prompts for lower and upper bounds, calls the range function with this data, and displays the result using printVector.
Part 1- Implement the assign Function
Function Specifications for assign:
Function Name: assign
Return Type: std::vector
Parameter: None
Requirements:
Prompt for Number Count: Ask the user how many numbers they want to enter.
Input and Store Numbers: Use a loop to input each number and store it in a std::vector.
Return the Vector: After all numbers are entered, return the populated vector.
Part 2- Implement the printVector Function
Function Specifications:
Function Name: printVector.
Parameter: A std::vector to be printed.
Return Type: None
Requirements:
Display Contents: Print each element of the vector. If the vector is empty, print a message such as "Empty vector".
Formatting: Ensure the output is user-friendly and clearly formatted (See example below).
Part 3- Implement the range Function
Function Specifications:
Function Name: range.
Parameter: A std::vector a vector containing the numbers to be filtered
Parameter: A lower parameter is the lower bound of the range.
Parameter: An upper parameter is the upper bound of the range.
Return Type: A std::vector of filtered numbers.
Requirements:
The function iterates through each number in the numbers vector and checks if it falls within the specified bounds (inclusive of the bounds themselves). If a number falls within the bounds, it is added to the result vector.
Return the result vector.
Part 4- Implement the main Function
Task for Main Function:
Call assign Function: Use assign to input numbers and receive the populated vector.
Request Bounds: Ask the user for the lower and upper bounds for the range.
Call range Function: Pass the vector from assign and the bounds to range, storing the returned vector.
Display Results with printVector: Use printVector to show the contents of the vector returned by range.
Example Interaction:
Enter the number of elements: 4
Enter element 1: 8
Enter element 2: 3
Enter element 3: 5
Enter element 4: 1
Enter lower bound: 2
Enter upper bound: 6
Result: 3,5
need done before 11:00 am today

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!