www.pudn.com > c.rar > ZUOBIAO.C, change:1997-07-23,size:3910b


#include "stdio.h" 
#include "stdlib.h" 
#include "math.h" 
#include "dos.h" 
#include "graphics.h" 
#define MAX 24 
#define MIN 12 
int num=0; 
int num_month=0; 
void iapcir(); 
void load(float *month,float *data) 
{ 
FILE *fp; 
char s[80]; 
goto_xy(2,0); 
printf("enter filename: "); 
gets(s); 
if((fp=fopen(s,"rb"))==NULL){ 
	printf("\t\nCannot open the file or file not find!\n"); 
	exit(1); 
} 
while(!feof(fp)) 
{ 
fscanf(fp,"%f%f",&month[num_month],&data[num]); 
num++; 
num_month++; 
} 
fclose(fp); 
} 
/*save the data file*/ 
save(float *data,int num_save) 
{ 
FILE *fp; 
int t; 
char s[80]; 
goto_xy(4,0); 
printf("Enter save filename: "); 
gets(s); 
if((fp=fopen(s,"w"))==0){ 
goto_xy(4,2); 
printf("Cannot creat this file\a\n"); 
exit(1); 
} 
putw(num_save,fp); 
for(t=0;t<num_save;++t)fprintf(fp,"%f",data[t]); 
fclose(fp); 
} 
/*********************/ 
 
main() 
{ 
int line1,line2,num1=0,num2=0,number=0; 
float kk[MAX]; 
float change1,change2; 
float a[2],dt[3];/****************************/ 
float kk_month[MIN]; 
int i; 
cls(); 
load(kk_month,kk); 
init(); 
clrscr(); 
setbkcolor(BLUE); 
setcolor(RED); 
line(100,300,600,300); 
line(100,500,100,20); 
line(600,300,590,297);/**arrow**/ 
line(600,300,590,303); 
line(100,20,103,30); 
line(100,20,97,30);/**arrow**/ 
for(line1=150;line1<=550;line1+=50) 
{ 
line(line1,300,line1,295); 
number+=50; 
} 
outtextxy(140,306,"50"); 
outtextxy(540,306,"450"); 
for(line2=500;line2>300;line2-=50) 
{ 
line(100,line2,105,line2); 
} 
for(line2=300;line2>15;line2-=21.667) 
{ 
line(100,line2,105,line2); 
} 
outtextxy(85,276.333,"1"); 
outtextxy(83,171.0,"6"); 
outtextxy(78,45,"12"); 
outtextxy(55,16,"Month"); 
outtextxy(585,305,"Vault"); 
outtextxy(90,300,"0"); 
for(num1=0;num1<num-1;num1++) 
{ 
outtextxy(100+kk[num1],300-250*kk_month[num2]/12.0,"*"); 
num2++; 
} 
setcolor(GREEN); 
for(num1=0,num2=0;num1<num-2;num1++) 
{ 
change1=250.0*kk_month[num2]/12.0; 
change2=250.0*kk_month[num2+1]/12.0; 
line(100+kk[num1],300-change1,100+kk[num1+1],300-change2); 
delay(200); 
num2++; 
if(change1<=0||num2>=12) 
{ 
printf("\b Vaults < 0 Or months>12!Please check your data file!\n\a"); 
} 
} 
iapcir(kk_month,kk,num-1,a,2,dt);/**********/ 
setcolor(YELLOW); 
line(100+a[0]+a[1],300-250.0/12.0,100+a[0]+a[1]*13.0,300-250.0*13.0/12.0); 
for(;;) 
if(kbhit())if(getch()==27)break; 
cleardevice(); 
closegraph(); 
} 
/**********************/ 
void iapcir(x,y,n,a,m,dt) 
int n,m; 
float x[],a[],dt[]; 
float y[]; 
{int i,j,k; 
float z,p,c,g,q,d1,d2,s[20],t[20],b[20]; 
for(i=0;i<=m-1;i++)a[i]=0.0; 
if(m>n)m=n; 
if(m>20)m=20; 
z=0.0; 
for(i=0;i<=n-1;i++)z=z+x[i]/(1.0*n); 
b[0]=1.0;d1=1.0*n;p=0.0;c=0.0; 
for(i=0;i<=n-1;i++) 
{p=p+(x[i]-z);c=c+y[i];} 
c=c/d1;p=p/d1; 
a[0]=c*b[0]; 
if(m>1) 
{t[1]=1.0;t[0]=-p; 
d2=0.0;c=0.0;g=0.0; 
for(i=0;i<=n-1;i++) 
{q=x[i]-z-p;d2=d2+q*q; 
c=c+y[i]*q; 
g=g+(x[i]-z)*q*q; 
} 
c=c/d2;p=g/d2;q=d2/d1; 
d1=d2; 
a[1]=c*t[1];a[0]=c*t[0]+a[0]; 
} 
for(j=2;j<=m-1;j++) 
{s[j]=t[j-1]; 
s[j-1]=-p*t[j-1]+t[j-2]; 
if(j>=3) 
for(k=j-2;k>=1;k--) 
s[k]=-p*t[k]+t[k-1]-q*b[k]; 
s[0]=-p*t[0]-q*b[0]; 
d2=0.0;c=0.0;g=0.0; 
for(i=0;i<=n-1;i++) 
{q=s[j]; 
for(k=j-1;k>=0;k--) 
q=q*(x[i]-z)+s[k]; 
d2=d2+q*q;c=c=y[i]*q; 
g=g+(x[i]-z)*q*q; 
} 
c=c/d2;p=g/d2;q=d2/d1; 
d1=d2; 
a[j]=c*s[j];t[j]=s[j]; 
for(k=j-1;k>=0;k--) 
{a[k]=c*s[k]+a[k]; 
b[k]=t[k];t[k]=s[k]; 
} 
} 
dt[0]=0.0;dt[1]=0.0;dt[2]=0.0; 
for(i=0;i<=n-1;i++) 
{q=a[m-1]; 
for(k=m-2;k>=0;k--) 
q=a[k]+q*(x[i]-z); 
p=q-y[i]; 
if(fabs(p)>dt[2])dt[2]=fabs(p); 
dt[0]=dt[0]+p*p; 
dt[1]=dt[1]+fabs(p); 
} 
return; 
} 
/************************/ 
cls() 
{ 
union REGS r; 
r.x.ax=0x0600; 
r.x.bx=0x1700; 
r.x.cx=0x0000; 
r.x.dx=0x184f; 
int86(0x10,&r,&r); 
} 
/*****************/ 
init() 
{ 
int driver=DETECT,mode=2; 
initgraph(&driver,&mode,"c:\\tc"); 
} 
/*****************/ 
goto_xy(int row,int col) 
{ 
union REGS r; 
r.h.ah=2; 
r.h.bh=0; 
r.h.dh=row; 
r.h.dl=col; 
int86(0x10,&r,&r); 
}