You are to design a program that will allow some number of grades (up to a max o
ID: 3550313 • Letter: Y
Question
You are to design a program that will allow some number of grades (up to a max of 100) to be input by the user. After the data has been collected, your program should calculate and output the mean and median of the collected data, as well as the sorted grade information.
for outer = 0; outer < X; outer++
for inner = 0; inner < X-1; inner++
if array[inner] > array[inner+1]
Create a program using Visual C++.Net. Make sure to capture a screen shot of your program running your test cases! The best way to do this is to click on the console window you want to capture and then press the Alt and PrintScreen keys at the same time. Then paste your captured screen image into your Word document. Your Word document should contain your test cases, the screen shots documenting your test cases, followed by a copy of your source code.
Explanation / Answer
please rate -thanks
#include <iostream>
#include <iomanip>
using namespace std;
void sort (int[],int);
double median (int a[], int max);
double mean(int a[], int max);
int main()
{const int elements=100;
int a[elements],i,max;
double result;
cout<<"How much data do you have? ";
cin>>max;
while(max>elements||max<1)
{cout<<"must be between 1 and "<<elements<<" ";
cout<<"How much data do you have? ";
cin>>max;
}
cout<<"Enter the numbers: ";
for(i=0;i<max;i++)
{cout<<"Enter element "<<i+1<<": ";
cin>>a[i];
if(a[i]<0||a[i]>100)
{cout<<"must be between 1 and 100 ";
i--;
}
}
result=mean(a,max);
cout<<"The mean is "<<setprecision(2)<<fixed<<result<<" ";
result=median(a,max);
cout<<"The median is "<<result<<" ";
cout<<"The sorted array: ";
for(i=0;i<max;i++)
{cout<<a[i]<<" ";
if((i+1)%5==0)
cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}
double mean(int a[], int max)
{int i,sum=0;
for(i=0;i<max;i++)
sum+=a[i];
return (double)sum/max;
}
void sort (int a[], int max)
{int i,j,t;
for(i=0;i<max;i++)
for(j=0;j<max-1;j++)
if(a[j]>a[j+1])
{t=a[j+1];
a[j+1]=a[j];
a[j]=t;
}
}
double median (int a[], int max)
{double m;
sort(a,max);
if(max%2==0)
return ((double)(a[max/2-1]+a[max/2])/2.);
else
return a[max/2];
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.