Wednesday 15 September 2010

c - A function to enter data into an array that quits entry at a EOF but allows to resume entry -



c - A function to enter data into an array that quits entry at a EOF but allows to resume entry -

so have assignment write menu-driven mini-statistics package. user should able come in 200 items of float data.

the programme should calculate or show:

the info self in organized table format the number of items the mean the standard deviation the variance the median the mode of data the high values in data the low values in data

when entering info though if come in in ctrl-z or ctrl-d or end-of-file symbol on scheme drops out of info entry loop , takes main menu.

the menu options easy enough

enter data display processed data quit program

but when go come in info 1 time again inquire programme should inquire if wish add together more info data set or create new info set.

so i'm not sure how kind of function stores count of if have entered in data. i'm not quite sure how end of file entering info array.

i have pseudo code nil much else.

some advice appreciated.

i have other functions processing info array , displaying not sure how entry.

right here basic part of programme show how menu should flow , forth between entry , display entry function crap know.

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #include <ctype.h> #include <time.h> #define max 200 //menu functions void menu(); int displaymenu(); //data entry function void enterdata(double a[],int n); void displaydata(double a[],int n); //display info functions void func_printdata(double a[],int n); int func_item_number(double a[],int n); double func_largest(double a[],int n); double func_smallest(double a[],int n); double func_mean(double a[],int n); double func_median(double a[],int n); double func_mode(double a[],int n); double func_variance(double a[],int n); double func_standard_deviation(double a[],int n); int main(){ double x[max]; menu(); //needed basic programs run professor system("pause"); return(0); } void menu(){ int com; do{ com = displaymenu(); switch(com){ case 1: enterdata(x,max); break; case 2: displaydata(x,max); break; case 3: printf("have nice day\n"); break; } }while(com != 3); } int displaymenu(){ int choice; printf("*------------------------------------------------------------*\n"); printf("| mini stats bundle |\n"); printf("*------------------------------------------------------------*\n"); printf("* *\n"); printf("* programme perform following: *\n"); printf("* *\n"); printf("* 1. come in data. *\n"); printf("* *\n"); printf("* 2. display info , next statistics: *\n"); printf("* number of info items, high , low values *\n"); printf("* in data, mean, median, mode, variance *\n"); printf("* , standard deviation. *\n"); printf("* *\n"); printf("* 3. quit programme *\n"); printf("* *\n"); printf("*------------------------------------------------------------*\n"); printf("your choice? "); scanf("%d",&choice); printf("\n\n\n"); homecoming choice; } void enterdata(double a[], int n){ double a[]; int i; int j; int k; char ynchoice; printf("enter in data"); if(k =< 0){ for(i=0 ; < n; i++){ j=1+i k++; printf("item %d: ",j); while((scanf("%d",&a[i]))!= eof){ scanf("%f",&a[i]); else{ printf("do wish add together new info existing sample? (y/n) "); scanf("%c",&yesnochoice); if (ynchoice == 'y'||'y'){ } else{ } menu(); } return(0); void displaydata(double a[], int n){ double a[]; int data_item_number; double data_largest; double data_smallest; double data_mean; double data_median; double data_mode; double data_variance; double data_standard_deviation; data_item_number = func_item_number(a,max); data_largest = func_largest(a,max); data_smallest = func_smallest(a,max); data_mean = func_mean(a,max); data_median = func_median(a,max); data_mode = func_mode(a,max); data_variance = func_variance(a,max); data_standard_deviation = func_standard_deviation(a,max); printf("-----------------------------------------------------------*\n"); printf(" mini stats bundle |\n"); printf("-----------------------------------------------------------*\n"); printf("data items:\n"); printf(func_printdata(a,max)); printf("number of info items : %d\n",data_item_number); printf("largest info item : %f\n",data_largest); printf("smallest info item : %f\n",data_smallest); printf("mean : %f\n",data_mean); printf("median : %f\n",data_median); printf("mode : %f\n",data_mode); printf("variance : %f\n",data_variance); printf("standard deviation : %f\n",data_standard_deviation); printf("-----------------------------------------------------------*\n"); menu(); } // rest of functions processing info

you need devise different plan/logic signal end of data. if utilize eof method deciding end of data, left no way of beingness able come in options main menu.

for example, can inquire user number of info points. then, expect user input info points.

int numdata; scanf("%d", &numdata); ( = 0; < numdata; ++i ) { scanf("%lf", &a[i]); }

that's strategy. you'll need add together error handling code every scanf. have prepared deal bad input -- whether on purpose or accident.

c arrays

No comments:

Post a Comment