#include void graphit(int, int, double*, double, double, double); double rhi, rlow, rrange; main() { int m = 6; double dat[] = {15.0,25.0,35.0,45.0,55.0,65.0}; graphit(1,m,dat,25.0, 40.0, 55.0); graphit(2,m,dat,25.0, 40.0, 55.0); graphit(3,m,dat,25.0, 40.0, 55.0); } static inline int graphmark(double value) { return (int) 1+15*2*(value-rlow)/rrange; } void graphit(int ctype, int m, double *x, double lcl, double cl, double ucl) /* * ctype = chart type: 1=xbar, 2=R, 3=p * m = number of statistical values * x[] = vector of m statistics, with first value in x[0] * lcl = lower control limit * cl = center line * ucl = upper control limit */ { register int i,j; int ilcl, icl, iucl; double res; static char *fhd = "%4s %9s[i]%12s %s\n"; static char buf[] = " "; static char heading[] = "---------------------------------"; static char type[][20] = { "x-bar", "R", "p"}; char isave; // normalize data first and calculate heading strings here printf("\n\t\t\t*** %s CONTROL CHART ***\n",&type[ctype-1][0]); printf("\nLCL = %lf CL = %lf UCL = %lf\n\n",lcl,cl,ucl); for (i=0,rhi=ucl,rlow=lcl; i < m; ++i) { if (x[i] > rhi) rhi = x[i]; if (x[i] < rlow) rlow = x[i]; } rrange = rhi-rlow; ilcl = graphmark(lcl); icl = graphmark(cl); iucl = graphmark(ucl); heading[icl] = 'C'; heading[ilcl] = 'L'; heading[iucl] = 'U'; buf[icl] = buf[ilcl] = buf[iucl] = '|'; printf(fhd,"i.",&type[ctype-1][0]," ",heading); for (i=0; i=lcl)&&(x[i]<=ucl))? '*' : '#'; printf(" %s\n",buf); buf[j] = isave; } printf(fhd,"",&type[ctype-1][0],"",heading); buf[icl] = buf[ilcl] = buf[iucl] = ' '; }