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

are in the array. The function returns the largest int that is in the array. Wri

ID: 3696121 • Letter: A

Question

are in the array. The function returns the largest int that is in the array. Write test code that thoroughly tests the function. The test code should use assertions. int count0ccurrences(int a[], int len, int k); Implement the function count0ccurrences 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 in a. Write test code that thoroughly tests the function. The test code should use assertions.

Explanation / Answer

#include <iostream>

using namespace std;
int countOccurences(int a[],int length,int value)
{
int times=0;
for(int i=0;i<length;i++)
{
if(a[i]==value)
times++;
}
return times;

}
int main()
{
int a[30],length,value;
cout << "enter size of array :";
cin >> length;
cout << "enter array elements: ";
for(int i=0;i<length;i++)
cin >> a[i];
cout << "enter item to find it's max repetitions:";
cin >> value;
if(countOccurences(a,length,value) <= 1)
cout << "Sorry values in array are UNIQUE ";
else
cout << "max repetitions of "<< value<< " is " << countOccurences(a,length,value)<< " ";
return 0;
}