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

Design a function that counts the number of times the item x appears among the f

ID: 3836406 • Letter: D

Question

Design a function that counts the number of times the item x appears among the first n elements of the array a and returns that count as the frequency of x in a.

c++

1 #include Kiostream 2 using namespace std; int frequency double int, int 6 int main() 8 double a 561, 508, 400, 301, 329, 599, 455, 400, 346 346, 329, 375, 561, 390, 399, 400, 401, 561, 405, 405, 455, 508, 473, 329, 561, 505, 329, 455, 561, 599, 561, 455, 346, 301, 455, 561, 399, 599, 508, 508); 10 int n 40, x 11 12 cout Item 13 14 cin x 15 16 cout x has frequency frequency (a,n,x) endi; 17 18 19 20 Design your 'frequency' function and insert it here

Explanation / Answer

use this function :

Thanks, let me know if there is any concern.


int frequency(double *arr , int n, int x){
int count[100000] = {0};


for(int i=0;i<n;++i){
count[(int)arr[i]]++;
}
  
return count[x];
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote