In: Computer Science
In C++, Write the definition of the function MaximumCount() whose header is
int MaximumCount(Array<double>& data)
It returns the amount of times the maximum value of data appears in data. If data is empty, it returns 0. For instance, if data = [7, 1, 4, 9, 6, 7, 7, 3, 2, 6, 9, 5, 9], it will return 3 since 9 appears three times
code:
#include <bits/stdc++.h> 
using namespace std; 
int MaximumCount(double data[15]) 
{ 
    //size of array data
    int n = 13;
    int maxcount=0;
        
        // consider all elements are not visited as false
        vector<bool> visited(n, false); 
                // count frequencies 
        for (int i = 0; i < n; i++) { 
                // if present skip
                if (visited[i] == true) 
                        continue; 
                // Count frequency 
                int count = 1; 
                for (int j = i + 1; j < n; j++) { 
                        if (data[i] == data[j]) { 
                                visited[j] = true; 
                                count++; 
                        } 
                } 
                if(count>maxcount) 
                maxcount=count;
        }
        //return maximum count
        return maxcount;
} 
int main() 
{ 
        double data[15] = { 7,1,4,9,6,7,7,3,2,6,9,5,9}; 
        int c=MaximumCount(data); 
        cout<<"Maximum count is :"<<c;
        return 0; 
} 
screenshot

output:

if array is empty : n means length of array is 0;
#include <bits/stdc++.h> 
using namespace std; 
int MaximumCount(double data[15]) 
{ 
    //size of array data
    int n = 0;
    int maxcount=0;
        
        // consider all elements are not visited as false
        vector<bool> visited(n, false); 
                // count frequencies 
        for (int i = 0; i < n; i++) { 
                // if present skip
                if (visited[i] == true) 
                        continue; 
                // Count frequency 
                int count = 1; 
                for (int j = i + 1; j < n; j++) { 
                        if (data[i] == data[j]) { 
                                visited[j] = true; 
                                count++; 
                        } 
                } 
                if(count>maxcount) 
                maxcount=count;
        }
        //return maximum count
        return maxcount;
} 
int main() 
{ 
        double data[15] = {}; 
        int c=MaximumCount(data); 
        cout<<"Maximum count is :"<<c;
        return 0; 
} 


-----------------------