Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use c++ code and you also have to use assertions and when the code runs i

ID: 3930802 • Letter: P

Question

Please use c++ code and you also have to use assertions and when the code runs it needs to display "All tests passed". If you don't mind can you also answer a previous question I posted because it hasn't been answered. Write test code that thoroughly tests the function. The test code should use assertions. Exercise 2: Counting occurrences (10 points) int countoccurrences(int a, int len, int k) int countOccurrences(int all, int len, int k); Implement the function countOccurrences whose declaration appears above. The first argument of the function is an array a of integers, the second argument len is the number of elements in the array, and the third argument is an integer k. The function returns the number of times k occurs ina Write test code that thoroughly tests the function. The test code should use assertions. Exercise 3: Two-dimensional arrays (10 points)

Explanation / Answer

#include<iostream>
#include<assert.h>
using namespace std;

int countOccurences(int a[],int len,int k)
{
int i=0,count=0;
for(i=0;i<len;i++)
if(a[i]==k)
count++;
  
return count;
}

int main(){
int arr[] = {1,2,3,4,3,2,1};
int count;
  
count = countOccurences(arr,7,2);
assert(count==2 && "Count should be equal to 2");
  
  
count = countOccurences(arr,7,3);
assert(count==3 && "Count should be equal to 2");
return 0;
}

OUTPUT:

prog: prog.cpp:24: int main(): Assertion `count==3 && "Count should be equal to 2"' failed.