Please provide the code in C++ for the following problem. . Problem statement: I
ID: 655265 • Letter: P
Question
Please provide the code in C++ for the following problem. .
Problem statement:
In statistics:
The mode of a set of values is the value that occurs most often or with the greatest frequency.
When a set of values is sorted in ascending or descending order, its median is the middle value. If the set contains an even number of values, the median is the mean, or average, of the two middle values.
Write a C++ application that do the following:
Define an array of size 10 and sore the values {1, 2, 3, 3, 3, 2, 2, 1, 3, 4, 5}. (Use array initializer.
Write a function that accepts as arguments the following:
A) An array of integers
B) 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.)
Write a function to sort the array. (use selection sort algorithm)
Write a function that determine the median of the array. This value should be returned as a double.
Write a function to display the contents of the array
NOTE: for all the above functions, demonstrate your pointer prowess by using pointer notation instead of array notation.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class a
{
public:
void mo (int *arr, int 10)
{
int ele, i,j,c=0,c1=0;
for(i=0;i<10;i++)
{
l=a[i];
for(j=0;j<10;j++)
{
if(a[j]==l)
{
c++;
}
if (c1>c)
{
mod=a[j];
}
}
}
cout<<"Mode is "<<mod;
}
void sort(int *arr)
{
int i,j,temp;
for(i=0;i<10;i++)
{
for(j=0;j<i;j++)
{
if(a[j]>a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
for(i=0;i<10;i++)
{
cout<<" "<<a[i];
}
}
};
void main()
{
int arr[]={1,2,3,3,3,2,2,1,3,4,5};
mo(arr, 10);
sort(arr);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.