This assignment is designed to aid students in the understan
This assignment is designed to aid students in the understanding of pointers. Problem Statement An instructor has given a test and wants to collect statistics about the scores students have received. The instructor is interested in finding out the average test score of the students. The median value of the test scores. This highest test score, the lowest test score and the standard deviation of the test scores. His output includes the information listed above which includes a table displaying the distance each test score is from the mean. language C++
Solution
#include <iostream>
using namespace std;
#include<math.h>
double highest(int array[],int size) //function to calculate highest score ,array name is passed as argument
{
int i,largest=0;
for(i=0;i<size;i++)
{
if(array[i]>largest)
largest = array[i];
}
return largest;
}
double lowest(int array[],int size) //function to calculate lowest score
{
int i,smallest=100;
for(i=0;i<size;i++)
{
if(array[i]<smallest)
smallest = array[i];
}
return smallest;
}
double averageArray(int array[],int size) //average of array elements
{
int i;
double sum=0;
for(i=0;i<size;i++)
sum=sum+array[i];
return sum/size;
}
double varianceArray(int array[5],double average,int size) //variance
{
int i;
double variance=0;
for(i=0;i<size;i++)
variance=variance+(array[i]-average)*(array[i]-average);
return variance/size;
}
double stdDevArray(int array[],double variance,int size) //standard deviation
{
return sqrt(variance);
}
double medianArray(int array[],int n) //median
{
int i,j,temp;
double median;
for(i=0;i<n;i++) //sorting
{
for(j=0;j<n-1-i;j++)
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
if(n%2 ==0)
median = (array[n/2] +array[n/2 +1])/2;
else
median = array[n/2];
return median;
}
int main()
{
int i,array[20],size;
double average,stddev,median,variance,largest,smallest;
cout<<\"\ Enter the size of Array\";
cin>>size;
cout<<\"\ Enter the elements\";
for(i=0;i<size;i++)
cin>>array[i];
largest = highest(array,size); //array name is passed as argument, base address of array is used like pointer
cout<<\"\ Higest Score =\"<<largest;
smallest = lowest(array,size);
cout<<\"\ Lowest Score =\"<<smallest;
average = averageArray(array,size);
cout<<\"\ Average = \"<<average;
variance = varianceArray(array,average,size);
cout<<\"\ Variance = \"<<variance;
stddev= stdDevArray(array,variance,size);
cout<<\"\ Standard Deviation=\"<<stddev;
median = medianArray(array,size);
cout<<\"\ median =\"<<median;
cout<<\"\ Difference of scores and Median\";
for(i=0;i<size;i++)
{
cout<<\"\ Score \"<<i+1<<\" :\"<<( median - array[i]);
}
return 0;
}
output:
Success time: 0 memory: 3476 signal:0


