C++ int lastof(const int a[], int aLen, const int b[], int bLen){int pos = -1;for (size t i = 0; i [3, 2, 11, 10, 1]b1->[8, 10, 6]last0f (al, 5, b1, 3): -1Expected: 3al->[3, 2, 11, 10,...


C++


Write the function lastOf which searches the array a for the last occurance of any value contained in<br>the array b. Returns the index if found. If not found, return -1.<br>arrays.cpp<br>1<br>#include <cstddef><br>int lastof(const int a[], int aLen, const int b[], int bLen)<br>{<br>int pos = -1;<br>for (size t i = 0; i < aLen; ++i)<br>if (a[i]<br>return pos;<br>3<br>4<br>5<br>6<br>7<br>== pos) pos = i;<br>8<br>10<br>11<br>}<br>CodeCheck<br>Reset<br>Testers<br>Running Tester.cpp<br>fail pass fail fail fail<br>al->[3, 2, 11, 10, 1]<br>b1->[8, 10, 6]<br>last0f (al, 5, b1, 3): -1<br>Expected: 3<br>al->[3, 2, 11, 10, 1]<br>b2->[5, 6]<br>last0f(al, 5, b2, 2): -1<br>Expected: -1<br>а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8]<br>b2->[5, 6]<br>last0f (a2, 11, b2, 2): -1<br>Expected: 6<br>а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8]<br>b1->[8, 10, 6]<br>lastof (a2, 11, b1, 3): -1<br>Expected: 10<br>а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8]<br>b3->[11, 2, 1, 15]<br>lastof (a2, 11, b3, 4): -1<br>Expected: 8<br>Score<br>1/5<br>

Extracted text: Write the function lastOf which searches the array a for the last occurance of any value contained in the array b. Returns the index if found. If not found, return -1. arrays.cpp 1 #include int lastof(const int a[], int aLen, const int b[], int bLen) { int pos = -1; for (size t i = 0; i < alen;="" ++i)="" if="" (a[i]="" return="" pos;="" 3="" 4="" 5="" 6="" 7="=" pos)="" pos="i;" 8="" 10="" 11="" }="" codecheck="" reset="" testers="" running="" tester.cpp="" fail="" pass="" fail="" fail="" fail="" al-="">[3, 2, 11, 10, 1] b1->[8, 10, 6] last0f (al, 5, b1, 3): -1 Expected: 3 al->[3, 2, 11, 10, 1] b2->[5, 6] last0f(al, 5, b2, 2): -1 Expected: -1 а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8] b2->[5, 6] last0f (a2, 11, b2, 2): -1 Expected: 6 а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8] b1->[8, 10, 6] lastof (a2, 11, b1, 3): -1 Expected: 10 а2->[4, 12, 12, 10, 12, 1, 5, 10, 11, 9, 8] b3->[11, 2, 1, 15] lastof (a2, 11, b3, 4): -1 Expected: 8 Score 1/5

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here