I have to write a program that will find the mode of a group of numbers. How should I tackle it using a pointer to find the number that appears most and producing a number of how many times the mode appears.
--------------------------------------------------------------------------------
This is what the output should look like:
Output for ex. 1 data:
The data set has 1 mode.
The value 2 appeared 3 times in the data set.
Output for ex. 2 data:
The data set has 2 modes.
The value 2 appeared 2 times in the data set.
The value 4 appeared 2 times in the data set.
Output for ex. 3 data:
The data set has no mode.
Output for ex. 4 data:
The data set has 3 modes.
The value 1.7 appeared 3 times in the data set.
The value 3.1 appeared 3 times in the data set.
The value 5 appeared 3 times in the data set.
--------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
//function prototype
void mode( double x[], int n);
int main ( )
{
const int N = 100;
double x[N];
void mode (double x[],int n);
int n;
ifstream inFile;
inFile.open("e:\\input1.txt");
n=0;
inFile>>x[n];
while (x[n]!=-9999)
{
n++;
inFile >>x[n];
}
inFile.close( );
mode(x,n);
inFile.open("e:\\input2.txt");
n=0;
inFile >>x[n];
while (x[n]!=-9999)
{
n++;
inFile >>x[n];
}
inFile.close( );
mode(x,n);
inFile.open("e:\\input3.txt");
n=0;
inFile >>x[n];
while (x[n]!=-9999)
{
n++;
inFile >>x[n];
}
inFile.close( );
mode(x,n);
system ("PAUSE");
return 0;
}
/*----------------------------------------------------*/
void mode(double x[], int n)
{
//locally stored variables
int number_of_modes=0;
int k;
double *ptr;
|
--------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
this is what I have thus far