Question

In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an...

In C++

Write a function

int * return_matches(int a[], int & size,TEST t)

which returns an array (allocated off of the heap in the function) containing only the elements of array a that pass the “test” t. The function iterates through all the elements of a, and constructs a new array containing all the elements that pass the test.

When the parameter corresponding to “size” is passed in (by reference), it contains the size of the array a. In the function that variable is modified, so that when “return_matches” returns, the parameter will contain the number of matches found. This will allow us to print the array returned by the function, since we know how big it is.

What is a “test”? It’s a Boolean function that tests if an integer meets a specific criteria.

For example

bool is_even(int n){

return n%2==0;

}

To make this work we could use a typedef like:

typedef bool TEST(int)

so now TEST becomes a type and the function “is_even” is indeed of type TEST since it is a function of a single integer variable and returns a bool.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
In C++ Write a function int * return_matches(int a[], int & size,TEST t) which returns an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C function with signature btbstree (int' post, int size) that gets the post-order traversal...

    Write a C function with signature btbstree (int' post, int size) that gets the post-order traversal of a binary search tree in the form of an int array, reconstructs the tree and returns a pointer to the tree root as output (The second input parameter size specifies the number of elements in the tree). Note: Type bt is defined in the following way: typedef struct btreenode { struct btreenode *left; int data; struct btreenode *right; |}bt;

  • **Bonus Question** Write a C function with signature bt' bstree (int' post, int size) that gets...

    **Bonus Question** Write a C function with signature bt' bstree (int' post, int size) that gets the post-order traversal of a binary search tree in the form of an int array, reconstructs the tree and returns a pointer to the tree root as output (The second input parameter size specifies the number of elements in the tree). Note: Type bt is defined in the following way: typedef struct btreenode { struct btreenode *left; int data; struct btreenode "right; bt;

  • **Bonus Question Write a C function with signature bt' bstree (int' post, int size) that gets...

    **Bonus Question Write a C function with signature bt' bstree (int' post, int size) that gets the post-order traversal of a binary search tree in the form of an int array,reconstructs the tree and returns a pointer to the tree root as output (The second input parameter size specifies the number of elements in the tree). Note: Type bt is defined in the following way: typedef struct btreenodel struct btreenode *left; int data; struct btreenode *right; }bt; 12pt Paragraph B...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • In class Recursion problems bool anyNegative(int al , int size) This function returns true if there...

    In class Recursion problems bool anyNegative(int al , int size) This function returns true if there are any negative numbers in the array, grity false otherwise. int firstNegative(int al I, int size) This function returns the position of the first negative number in the array & EAO If there are no negative numbers it returns int countNegative(int al I, int size) This function returns the number of negative numbers in the array a. 12 bst Stringsint indexO bout Strings nt...

  • C ++Write a function, anyThree (int a[], int n), that returns true if the value 3...

    C ++Write a function, anyThree (int a[], int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or equal to 0. Write a function, anyThree (int all, int n), that returns true if the value 3 appears in the array exactly 3 times, and no 3's are next to each other. The parameter n will be greater than or...

  • using c++ Write a function that returns true if a given integer array is sorted(in ascending...

    using c++ Write a function that returns true if a given integer array is sorted(in ascending order) and false if it is not. The function should perform no more than "size" comparisons. bool isSorted(int A[], int size);

  • must be done in C You will implement a function that matches one of the prototypes...

    must be done in C You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...

  • Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and...

    Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...

  • (a) Write a recursive function int find(const int A[], int n, int x); which returns the...

    (a) Write a recursive function int find(const int A[], int n, int x); which returns the first index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found. (b) Write a recursive function int rfind(const int A[], int n, int x); which returns the last index i = 0, . . . , n − 1 such that A[i] == x, or n if it is not found....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT