Two-one dimentionl Random/ Set Array! help me!!!

Scenario: You're conducting a study on the number of people that ride the METRO each day. After collecting the data, you will perform statistical analysis.

Program: To actually collect data, you would need access to the METRO's computers. For the purposes of this assignment, you will simulate the values by creating two one-dimensional arrays of 30 random numbers each. Each array represents one month of data. For one set, randomly create integer values between 65,000 and 85,000 using the rand function. For the other set, use the srand function. Your seed value will be set using the following formula:

seed = (year you were born - day of the month you were born) * (month you were born) + how many classes you are taking this semester

For example, if you were born on March 10, 1985 and you are taking 4 classes this semester, then your seed value is (1985 - 10) * 3 + 4 = 5929.

Look in the Assignments link for the two files with the code for the statistics library that you will use. Copy the code in stat_lib_header.rtf into a new header (.h) file. Copy the code in stat_lib.rtf into a new source (.cpp) file. You should rename the files such that the header file and the source file have the same name.

Add a new function to the library to generate the seed value based on the equation above. Call this new function before creating the second set of data.

Incorporate the library into your project, and call the functions in the library to calculate the max., min., mean, median, variance, and standard deviation for each data set. Since the median requires that your array be sorted, call the sorting function before calling the function to find the median. Output all results to the screen as double precision numbers with two decimal places. For the first set of data, also search for the value 68,280 and return its index.
_______________________________ lib.
double maxval(const double x[], int n);
double minval(const double x[], int n);
double mean(const double x[], int n);
double median(const double x[], int n);
double variance(const double x[], int n);
double std_dev(const double x[], int n);
void sort(double x[], int n);
int search(const double A[], int n, double value);
________________________________________________code.
#include <cmath>
using namespace std;

/*---------------------------------------------------------*/
/* This function returns the maximum */
/* value in teh array x with n elements. */

double maxval(const double x[], int n)
{
// Declare local objects.
double maxVal;

// Determine maximum value in the array.
maxVal = x[0];
for (int k=1; k<n; ++k)
{
if (x[k] > maxVal)
maxVal = x[k];
}

// Return maximum value.
return maxVal;
}
/*---------------------------------------------------------*/
/* This function returns the minimum */
/* value in teh array x with n elements. */

double minval(const double x[], int n)
{
// Declare local objects.
double min_x;

// Determine minimum value in the array.
min_x = x[0];
for (int k=1; k<=n-1; ++k)
{
if (x[k] < min_x)
min_x = x[k];
}

// Return minimum value.
return min_x;
}
/*---------------------------------------------------------*/
/* This function returns the average or */
/* mean value of an array with n elements. */

double mean(const double x[], int n)
{
// Declare and initialize objects.
double sum(0);

// Determine mean value.
for (int k=0; k<n; ++k)
{
sum += x[k];
}

// Return mean value.
return sum/n;
}
/*---------------------------------------------------------*/
/* This function returns the median */
/* value in an array x with n elements. */
/* The values in x are assumed to be ordered. */

double median(const double x[], int n)
{
// Declare objects.
double median_x;
int k;

// Determine median value.
k = floor(double(n)/2);
if (n%2 != 0)
median_x = x[k];
else
median_x = (x[k-1] + x[k])/2;

// Return median value.
return median_x;
}
/*---------------------------------------------------------*/
/* This function returns the variance */
/* of an array with n elements. */

// Function prototype.
double mean(const double x[], int n);

double variance(const double x[], int n) // Function header.
{
// Declare objects.
double sum(0), mu;

// Determine variance.
mu = mean(x,n);
for (int k=0; k<n; ++k)
{
sum += (x[k] - mu)*(x[k] - mu);
}

// Return variance.
return sum/(n-1);
}
/*---------------------------------------------------------*/
/* This function returns the standard deviation */
/* of an array with n elements. */

// Function prototype.
double variance(const double x[], int n);

double std_dev(const double x[], int n) // Function header.
{

// Return standard deviation.
return sqrt(variance(x,n));
}
/*---------------------------------------------------------*/
/* This function sorts an array with n elements */
/* into ascending or increasing order. */

void sort(double x[], int n)
{
// Declare objects.
int m;
double hold;

// Implement selection sort algorithm.
for (int k=0; k<=n-2; ++k)
{
// Find position of smallest value in array
// beginning at k
m = k;
for (int j=k+1; j<n-1; ++j)
{
if (x[j] < x[m])
m = j;
}
// Exchange smallest value with value at k
hold = x[m];
x[m] = x[k];
x[k] = hold;
}

return;
}
/*---------------------------------------------------------*/
/* This function returns the position of the search value */
/* in array A. It returns -1 if the value is not found. */

int search(const double A[], int n, double value)
{
int index(0);
while (index < n && A[index] < value)
{
++index;
}
if(index < n && A[index] >= value-0.001 && A[index] <= value+0.001)
return(index);
else
return(-1);
}
/*---------------------------------------------------------*/
Topic archived. No new replies allowed.