Question

In: Computer Science

In statistics, the mode of a set of values is the value that occurs most often...

In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Write a function that accepts as arguments the following:

  • An array of integers
  • An integer that indicates the number of elements in the array

The function should determine the mode of the array. That is, it should determine which value in the array occurs most often. The mode is the value the function should return. If the array has no mode (none of the values occur more than once), the function should return −1. (Assume the array will always contain nonnegative values.)
Demonstrate your pointer prowess by using pointer notation instead of array notation in this function.

can someone please help me with this in C++ programming language?

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Have used only pointers. Let me know if you have any doubts or if you need anything to change.

Thank You !

If you are satisfied with the solution, please rate the answer.


===========================================================================

#include <iostream>

using namespace std;

int mode(int* apointer, int size){
  
   int max_occurence=0;
   int modeNumber=0;
  
   for(int i=0; i<size; i++) {
       int current_occurence=0;
       for(int j=0; j<size; j++ ){
          
           if(*(apointer+i)==*(apointer+j)){
               current_occurence+=1;
           }
          
       }
       if(current_occurence>max_occurence){
           max_occurence=current_occurence;
           modeNumber = *(apointer+i);
       }
   }
  
   if(max_occurence!=1) return modeNumber;
   else return -1;
  
  
}

int main(){
  
   int a[] = {44,2,3,4,1,3,44,1,1,2,4,43,1,2,44,44,44};
   cout<<"Mode = "<<mode(a,sizeof(a)/sizeof(int));  
   cout<<endl;
   int b[] = {1,2,3,4,5,6,7,8,9,10,11};
   cout<<"Mode = "<<mode(b,sizeof(b)/sizeof(int));  

}

========================================================================


Related Solutions

The mode is which of the following? The most frequently occurring value in a data set...
The mode is which of the following? The most frequently occurring value in a data set The middle most occurring value in a set of values The difference between the highest and lowest values in a set The arithmetic average of a set of values.
In health care, medicine, and medical research there often occurs a clash in values.
Critical ThinkingIn health care, medicine, and medical research there often occurs a clash in values. These conflicts exist amongst the providers and between the providers and the recipients of care. Provide an example of one such conflict.1. Describe the situation or case2. State what the conflict is3. state clearly and deliberately and underlinewhat the Institutional values and individual values are that are in conflict. BE SURE that you do this. State the values. Be explicit and clear. Underline for emphasis.If...
The mode of a list of values is the value having the greatest frequency. ( You...
The mode of a list of values is the value having the greatest frequency. ( You will implement this algorithm in the lab - project 3) write an algorithm in pseudocode to find the mode of a sorted list in one pass using only iterator Lab10-Project3 Description FindMode You are working with a sorted list of numbers that are stored in SortedLinkedListWithIterator object called this.myList. Duplicates are allowed. Your task is to find a mode of the list - the...
Osteosarcoma is a relatively rare type of bone cancer. It occurs most often in young adults,...
Osteosarcoma is a relatively rare type of bone cancer. It occurs most often in young adults, age 10 - 19; it is diagnosed in approximately 8 per 1,000,000 individuals per year in that age group. In New York City (including all five boroughs), the number of young adults in this age range is approximately 1,400,000. a) What is the expected number of cases of osteosarcoma in NYC in a given year? b) What is the probability that 15 or more...
Mumps is a highly contagious viral infection that most often occurs in children, but can affect...
Mumps is a highly contagious viral infection that most often occurs in children, but can affect adults, particularly if they are living in shared living spaces such as college dormitories. It is most recognizable by the swelling of salivary glands at the side of the face under the ears, but earlier symptoms include headaches, fever, and joint pain. Suppose a college student at a university presents to a physician with symptoms of headaches, fever, and joint pain. Let A =...
Each value in the data set is called a ? .    Variables whose values are...
Each value in the data set is called a ? .    Variables whose values are determined by chance are called ? . A Blank 1 consists of all subjects (human or otherwise) that are being studied.    A Blank 1 is a circle that is divided into sections or wedges according to the percentage of frequencies in each category of the distribution.    Tell whether Descriptive or Inferential Statistics has been used. In the upcoming election, it is predicted...
Prompt: Present value and Future value – In finance we often calculate present and future values....
Prompt: Present value and Future value – In finance we often calculate present and future values. Discuss their uses and the relationship between present and future value. Requirements: 250 words
PRESENT VALUE OF AN ANNUITY Find the present values of these ordinary annuities. Discounting occurs once...
PRESENT VALUE OF AN ANNUITY Find the present values of these ordinary annuities. Discounting occurs once a year. Round your answers to the nearest cent. $700 per year for 16 years at 6%. $   $350 per year for 8 years at 3%. $   $800 per year for 6 years at 0%. $   Rework previous parts assuming that they are annuities due. Round your answers to the nearest cent. $700 per year for 16 years at 6%. $   $350 per year...
PRESENT VALUE OF AN ANNUITY Find the present values of these ordinary annuities. Discounting occurs once...
PRESENT VALUE OF AN ANNUITY Find the present values of these ordinary annuities. Discounting occurs once a year. Round your answers to the nearest cent. $600 per year for 16 years at 12%. $   $300 per year for 8 years at 6%. $   $900 per year for 16 years at 0%. $   Rework previous parts assuming that they are annuities due. Round your answers to the nearest cent. $600 per year for 16 years at 12%. $   $300 per year...
Find the mean, median, and mode of the following set of data. (Enter solutions for mode...
Find the mean, median, and mode of the following set of data. (Enter solutions for mode from smallest to largest. If there are any unused answer boxes, enter NONE in the last boxes.) (a) 6 6 7 8 9 12 Mean Median Mode Mode (b) 6 6 7 8 9 108 Mean Median Mode Mode
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT