Must include stdio.h library & code must work. Write a menu-driven mini-statisti
ID: 3533083 • Letter: M
Question
Must include stdio.h library & code must work.
Write a menu-driven mini-statistics package. A user should be able to enter up to 200 items of float data. The program should calculate the number of items in the data, the mean, the standard deviation, the variance, the median, and the mode of the data. A sample run follows. The symbol <EOF> in the sample run below should be replaced with CTRL-Z or CTRL-D or the end-of-file symbol on your system.
Mini-Stat Package
-----------------------
This program will perform the following:
1) Enter data.
2) Display the data and the following statistics:
the number of date item, the high and low values in the data, the mean, median, mode, variance and standard deviation.
3) Quit the Program
--------------------------------------------------------------------------------------------------------------------------------
Your Choice? 1
Enter one data item after each prompt. Press return after each one. Signal with <EOF> when you are done with data input.
Item #1 : 25
Item #2 : 36
Item #3 : 27.5
Item #4 : 28
Item #5 : 32
Item #6 : 33.25
Item #7 : <EOF>
This program will perform the following:
1) Enter data.
2) Display the data and the following statistics:
the number of date item, the high and low values in the data, the mean, median, mode, variance and standard deviation.
3) Quit the Program
Explanation / Answer
Please Rate:THanks
//header section
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
//setting up of prototypes
void readData(float[],int&);
float mean(float[],int);
float sd(float[],int);
float min(float[],int);
float max(float[],int);
float median(float[],int);
//main function
main()
{
//declaring variables to store numbers, and user coice etc..,
float data[200];
int choice,count=0,i;
//prompting user to enter choice
do
{
printf(" This program will perform the following:");
printf(" 1.Enter Data 2.Display the data and the following statistics: ");
printf("the number of date item, the high and low values in the data, the mean, median, mode, variance and standard deviation.");
printf(" 3.Quit the program ");
printf(" Your Choice?");
scanf("%d",&choice);
printf(" Enter one data item after each prompt. Press return after each one. Enter -1 with when you are done with data input. ");
//based on the choice select an appropriate case
switch(choice)
{
case 1:
//calling readData function
readData(data,count);
break;
case 2:
//display statastice
for(i=0;i<count;i++)
printf("%.2f ",data[i]);
printf(" Total no of data items: %d",count);
printf(" Highest value in the data: %.2f",max(data,count));
printf(" Lowest value in the data: %.2f",min(data,count));
printf(" Mean: %.2f",mean(data,count));
printf(" Median: %.2f",median(data,count));
printf(" Standard Deviation: %.2f",sd(data,count));
printf(" Variance: %.2f ",pow((sd(data,count)),2));
break;
case 3:exit(0);//exit
}
}while(1);//end of do-while
}//end of main
//function definition of readData
void readData(float data[],int &count)
{
float value;
int i=0;
//reading data and storing in data
printf("Item #%d: ",count+1);
scanf("%f",&value);
while(value!=-1)
{
data[count++]=value;
printf("Item #%d: ",count+1);
scanf("%f",&value);
}
}
//finding mean
float mean(float data[],int count)
{
int i;
float mean=0.0;
for(i=0;i<count;i++)
mean+=data[i];
return mean/count;
}
//finding standard deviation
float sd(float data[],int count)
{
float avg=mean(data,count);
float SD=0.0;
int i;
for(i=0;i<count;i++)
SD+= pow((data[i]-avg),2);
return sqrt(SD/count);
}
//finding maximum value
float max(float data[],int count)
{
int i=1;
float max=data[0];
for(;i<count;i++)
if(max<data[i])
max=data[i];
return max;
}
//finding minimum value
float min(float data[],int count)
{
int i=1;
float min=data[0];
for(;i<count;i++)
if(min>data[i])
min=data[i];
return min;
}
//finding median
float median(float data[],int count)
{
int i,j;
float tmp;
for(int i=0;i<count-1;i++)
for(int j=i+1;j<count;j++)
if(data[i]>data[j])
{
tmp=data[i];
data[i]=data[j];
data[j]=tmp;
}
if(count%2==0)
return (data[count/2-1]+data[count/2])/2;
else
return data[count/2];
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.