Write a function of the form void setupRandArray int n int x

Write a function of the form: void setupRandArray (int n, int x[], int minVal, int maxVal) which sets up random values for the n-dimensional array x[]. Each random value is an integer between minVal and maxVal. Write a function of the form void printIntArray(int n, int x[]) which prints the array x to the screen in the following format (print results on a new line): 92 70 65 89 91 89 73 80 98 Write a function of the form void printArraywithLabel (int n, int x[], char str []) Which prints the array x to the screen but also prints the string str (which is a label or variable name). For example, suppose we pass in an array of integers and the str string is: \"scores\", then the function will print out: scores: 92 78 65 89 91 87 73 80 98 Write a function float getAvergae (int n, int x []) that given an array and its dimension computes and returns the average value of all the elements of the array. Similarly, write a function float getStandardDev (int n, int x []) that computes and returns the standard deviation. Write a function called int getMaximum (int n, int x []) that given an array and its dimension computes and returns the maximum value. Similarly, write a function called int getMinimum (int n, int x []) that returns the minimum value. Write a function of the form: int getCountInRange (int n, int x [], int minVal, int maxVal) that given an array of integers and its dimension, returns the number of elements that are between minVal and maxVal. Write a function of the form int getValuesInRange (int n, int x [], int out [], int minVal, int maxVal) which returns an array (through the out [] array) containing all of the values that are in range. The total number of values found is also returned as an int. Write a function of the form int getIndexInRange (int n, int x [], int index [], int minVal, int maxVal) which returns an array of all the index values for which the elements of x [] are in range. The total number of indices is returned as well. Write a program that stores a set of random best grades and produces the following output. Test your program several times with a class which has a low, medium, and high variance of scores.

Solution

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include<iostream>
using namespace std;
int a[10];
void setupRandArray(int,int[],int,int);
void printIntArray(int,int[]);
void printArrayWithLabel(string,int[]);
float getAverage(int,int[]);
int getMaximum(int,int[]);
void getValuesInRange(int,int[],int,int);
void getCountInRange(int,int[],int,int);
void getIndexInRange(int,int[],int,int);
int main ()
{
setupRandArray(10,a,10,15);
printIntArray(10,a);
printArrayWithLabel(\"marks\",a);
cout<<\"Average:\"<<getAverage(10,a)<<endl;
cout<<\"Maximum:\"<<getMaximum(10,a)<<endl;
getValuesInRange(10,a,11,13);
getCountInRange(10,a,12,15);
getIndexInRange(10,a,10,14);
return 0;
}
//setup rand array
void setupRandArray(int n,int x[],int minVal,int maxVal)
{
srand ( time(NULL) );
for(int i=0;i<n;i++)
{
   x[i]=(rand() % (maxVal-minVal+1) + minVal);
       }
  
   }
   ///print array method...
   void printIntArray(int n,int x[])
   {
       for(int i=0;i<10;i++)
{
   cout<<a[i]<<endl;
       }
      
   }
   //function for with label
   void printArrayWithLabel(string label,int x[])
   {
       cout<<label<<endl;
           for(int i=0;i<10;i++)
{
   cout<<a[i]<<endl;
       }
   }
   //methods for getting average
   float getAverage(int n,int x[])
   {
      float sum=0;
           for(int i=0;i<10;i++)
{
   sum=sum+x[i];
       }
       return (sum/n);
   }
   //method for max value
   int getMaximum(int n,int x[])
   {
      float max=x[0];
           for(int i=0;i<10;i++)
{
   if(x[i]>max)
   max=x[i];
       }
       return max;
   }
   //method to values in range
   void getValuesInRange(int n,int x[],int minVal,int maxVal)
   {
   cout<<\"values in range\"<<endl;
for(int i=0;i<n;i++)
{
   if(x[i]>minVal&&x[i]<maxVal)
   {
       cout<<x[i]<<endl;
           }
       }
   }
   //getting count in range
void getCountInRange(int n,int x[],int minVal,int maxVal)
{
   int count=0;
   for(int i=0;i<n;i++)
{
   if(x[i]>minVal&&x[i]<maxVal)
   {
       count++;
           }
       }
       cout<<\"Count:\"<<count<<endl;
}
//indexes in range
void getIndexInRange(int n,int x[],int minVal,int maxVal)
{
   cout<<\"Indexes in range\"<<endl;
for(int i=0;i<n;i++)
{
   if(x[i]>minVal&&x[i]<maxVal)
   {
       cout<<i<<endl;
           }
       }
}

 Write a function of the form: void setupRandArray (int n, int x[], int minVal, int maxVal) which sets up random values for the n-dimensional array x[]. Each ra
 Write a function of the form: void setupRandArray (int n, int x[], int minVal, int maxVal) which sets up random values for the n-dimensional array x[]. Each ra
 Write a function of the form: void setupRandArray (int n, int x[], int minVal, int maxVal) which sets up random values for the n-dimensional array x[]. Each ra

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site