C programming Measurement analysis Using computer programs for measurement of da
ID: 3882861 • Letter: C
Question
C programming
Measurement analysis
Using computer programs for measurement of data collection and analysis is very common. You should write a well-structured program where you can enter measurement values and analyze them. When the program starts, the user gets a menu where he can choose:
v (View) - displays the measured values stored
e (Enter) - allows the user to add measurement values
c (Compute) - presents max, min, mean and normalized metrics
r (Reset) - deletes all input measured values
q (Quit) completes the program
The user must make his choice by entering a letter.
(View ).Displays the program values currently stored in the program. Must be able to handle zero metrics.
(Enter). The user can enter the measured values (positive integers) here until he inputs zero or the total number of measured values stored is ten. Then the entry ends and the user returns to the main menu. Note that if the user selects this option multiple times, the new metrics will be added. Previously entered measurement values should remain. If you choose this option when the program already contains ten measured values, you can not enter any new values.
The output should be like this: Measurement tool VEckey r VECRR [N , measurements ) VECRQ ? e Enker measurement # 1 (or 0) 91 Enker measurement # 2 (oro ) : 2 Enker mucsurement # 3 (or 0) 7 3 Enter 4 (or 0) ? 0 muasurement # VEC Ro? TA 2 31 Vecka Enker measurement # 4 (or 0 ) 94 Enter measurement t 5 (or 0) 35 Enker unsure munt to (or 0).0 VEceQ 9 V V TA 2 3 4 5) VECREQ c Max value: 5 in ValA Ayr ValueE 300 -2 - 0 A 21 VECRO , Exit measurement tool!Explanation / Answer
#include<stdio.h>
int main(){
int data[10];
int count = 0;
char ch,ch1;
double sum;
int max,min,i;
do {
printf("Measurement Tool ");
printf("v (View) - displays the measured values stored ");
printf("e (Enter) - allows the user to add measurement values");
printf("c (Compute) - presents max, min, mean and normalized metrics ");
printf("r (Reset) - deletes all input measured values ");
printf("q (Quit) completes the program ");
printf("VECRQ?");
do {
scanf("%c",&ch);
} while (ch == ' ');
switch (ch){
case 'v':
if (count == 0){
printf("[ No Measurement ] ");
}
else {
printf("[ ");
for (i = 0; i<count; i++){
printf("%d ",data[i]);
}
printf("] ");
}
break;
case 'e':
for (i = 0; i<10; i++){
printf("Enter measurement # %d (or 0)? ",i+1);
scanf("%d", &data[count]);
if (data[count] == 0){
break;
}
count++;
}
break;
case 'c':
if (count == 0){
printf("[ No Measurement ] ");
}
else {
sum = 0;
max = data[0];
min = data[0];
for (i = 0; i<count; i++){
sum = sum + data[i];
if (max < data[i])
max = data[i];
if (min > data[i])
min = data[i];
}
printf("Max : %d ",max);
printf("Min : %d ",min);
printf("Average : %0.2f ",sum/count);
}
case 'r':
count == 0;
break;
}
fflush(stdin);
} while (ch != 'q');
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.