22:13 1 ull A learn-ap-southeast-1-prod-fleet02-xythos.s3-ap-southeast-1.ama Course Code: CSCI1540 (2019-20, Term 1) Page 3 o

22:13 1 ull A learn-ap-southeast-1-prod-fleet02-xythos.s3-ap-southeast-1.ama Course Code: CSCI1540 (2019-20, Term 1) Page 3 of 6 3. (20%) Write a program (file name: Q3.cpp) with a function void findpair (const int x[], int m, const int y[l, int n, int t, int &a, int &b);. The parameters m and n are the size of parameter arrays x and y respectively. The func- tion finds a pair of values (one value in x; one value in y) so that the absolute difference of the pair (absolute value of their difference) is the smallest but at least t. The found values are written to the reference parameters a and b respectively. E.g., suppose array x has contents (7,4,1,5} and array y has contents (20,30,10,40,50). Then the call findpair (x, 4, y, 5, 24, a, b) should write 5 to a and 30 to b, because |5 – 30 = 25 is the smallest but at least 24. Note: • When there is more than one pair whose absolute difference is the smallest but at least t, you can write any such pair to a and b. E.g., x is (5}; y is (7,3}. The call findpair (x, 1, y, 2, 2, a, b) can write either 5,7 or 5,3 to a,b. Both pairs have an absolute difference 2. • It is possible that no pair satisfies the condition “the smallest but at least t”. If this is the case, you do not have to update a and b at all. E.g., x is (5); y is (7,3). The call findpair (x, 1, y, 2, 9, a, b) shall not update a and b because both absolute difference (2) is not at least 9. • What you write in the main () function is unimportant. It can contain code to test the required function. We shall grade only the required function. Course Code: CSCI1540 (2019-20, Term 1) Page 4 of 6



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *