数据库读取
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #include<graphics.h> 5 #include<conio.h> 6 #include<math.h> 7 #include<dos.h> 8 #define S 16 9 #define bgi "c:\\bgi" 10 #define ppqq 30000 11 #define PI acos(-1.0) 12 #define HZK "c:\\tc\\hzk\\hzk16" 13 long app=0,opple=0,Akm=0,sdibt=0; 14 int x=60,y=80; 15 char app1[123]; 16 void cursor();/*被调函数的生命声明*/ 17 void dispz(); 18 void my_sound(); 19 void load_pic(); 20 void save_pic(); 21 void input(); 22 void newxy(); 23 void read_date(); 24 long Mouse_operate(); 25 void disphz(); 26 int oi=0; 27 struct HEAD 28 { 29 char file_type; 30 char file_date[3]; 31 long file_num; 32 short file_width; 33 short rec_width; 34 } head; 35 struct file 36 { 37 char field_name[10]; 38 char field_type[2]; 39 long field_start; 40 char field_width; 41 char field_dight; 42 } Fild; 43 struct ranklist 44 { 45 char name[123]; 46 double english; 47 double math; 48 double sum; 49 double computer; 50 } p; 51 union input 52 { 53 int key; 54 char cmp[2]; 55 } key; 56 int cmp(const void *a,const void *b)/*按照成绩排序,总分第一优先级,次优先级是英语成绩*/ 57 { 58 struct ranklist *c=(struct ranklist *)a; 59 struct ranklist *d=(struct ranklist *)b; 60 if(c->sum==d->sum) 61 return d->english-c->english; 62 return d->sum-c->sum; 63 } 64 65 void read_date(struct ranklist *student)/*数据库的读取及文本框的输入*/ 66 { 67 long n,i,j,m,p3,cpu,flag=0,lenth=0,k=0; 68 char str[134],kk[123],arr[]= {"Please input your secret"},ch; 69 double score; 70 int kkp; 71 char name[123]; 72 long start1,start2,start3,count=0,p1,p2,p4,start4; 73 FILE *fp; 74 int gmode,gdriver=DETECT; 75 76 initgraph(&gdriver,&gmode,bgi); 77 m=app; 78 79 while(1)/*判断文件是否能打开*/ 80 { 81 if(Akm==0) 82 { 83 cleardevice(); 84 setcolor(4); 85 setcolor(15); 86 bar(110,120,310,150); 87 disphz(110,100,"请输入数据库文件名,回车键结束",15,1); 88 disphz(110,180,"提示",15,1); 89 setcolor(15); 90 outtextxy(142,215,"1."); 91 disphz(155,210,"可以带盘符和路径,如:",15,1); 92 setcolor(15); 93 outtextxy(380,215,"c:\\tc\\ss.dbf"); 94 setcolor(15); 95 outtextxy(145,235,"2.dbf"); 96 disphz(185,230,"可省略",15,1); 97 98 do 99 { 100 flag++; 101 if(flag%2==0) 102 setcolor(15); 103 else 104 setcolor(0); 105 line(110+lenth*16,150,110+lenth*16+10,150); 106 delay(200); 107 } 108 while(!kbhit()); 109 setcolor(15); 110 line(110+lenth*16,150,110+lenth*16+10,150); 111 } 112 else 113 { 114 setcolor(15); 115 outtextxy(110,135,app1); 116 k=0; 117 setcolor(0); 118 rectangle(270,240,640,370); 119 120 setfillstyle(1,0); 121 floodfill(273,243,0); 122 } 123 Akm++; 124 memset(app1,0,sizeof(app1)); 125 memset(str,0,sizeof(str)); 126 while(1) 127 { 128 129 key.key=bioskey(0); 130 kkp=bioskey(2); 131 ch=key.cmp[0]; 132 if((ch!=8&&ch!='\r'&&(ch>='a'&&ch<='z')||((ch>='A'&&ch<='Z')&&(kkp&64||kkp&1||kkp&2))||(ch>='0'&&ch<='9'||ch=='.')||ch=='\\'||ch==':'||ch=='_')&&strlen(str)<12)/*输入文本框时非法字符的限制*/ 133 { 134 str[k++]=ch; 135 str[k]='\0'; 136 137 } 138 else if(ch==8) 139 { 140 if(k-1>=0) 141 { 142 str[k-1]='\0'; 143 k--; 144 } 145 } 146 else if(ch=='\r') 147 break; 148 setcolor(15); 149 settextstyle(0,0,2); 150 outtextxy(110,135,app1); 151 setcolor(0); 152 settextstyle(0,0,2); 153 outtextxy(110,135,str); 154 strcpy(app1,str); 155 setcolor(15); 156 line(110+lenth*16,150,110+lenth*16+10,150); 157 lenth=strlen(str); 158 do 159 { 160 flag++; 161 if(flag%2==0) 162 setcolor(15); 163 else 164 setcolor(0); 165 line(110+lenth*16,150,110+lenth*16+10,150); 166 delay(200); 167 } 168 while(!kbhit()); 169 } 170 strcpy(app1,str); 171 if(strlen(app1)>=4&&app1[strlen(app1)-4]!='.')/*如果app1数组是否有.dbf,若无则加上.dbf*/ 172 { 173 strcat(app1,".dbf"); 174 app1[strlen(app1)]='\0'; 175 } 176 if((fp=fopen(app1,"rb"))==NULL) 177 { 178 179 180 setcolor(1); 181 rectangle(270,240,580,370); 182 183 setfillstyle(1,1); 184 floodfill(273,243,1); 185 setcolor(15); 186 outtextxy(290,300,"1."); 187 disphz(275,245,"打不开文件,请选择以下两种方案",15,1); 188 disphz(310,295,"如果想重新输入请按数字一",15,1); 189 setcolor(15); 190 outtextxy(290,320,"2."); 191 disphz(310,315,"如果想退出请按数字二",15,1); 192 while(1) 193 { 194 cpu=getch(); 195 if(cpu=='1') 196 break; 197 else if(cpu=='2') 198 { 199 sdibt=2; 200 break; 201 } 202 } 203 204 if(sdibt==2) 205 return; 206 207 } 208 else break; 209 } 210 211 fclose(fp); 212 fp=fopen(app1,"rb"); 213 fread(&head,12,1,fp); 214 fseek(fp,20,1); 215 for(i=0;; i++) 216 { 217 fread(&Fild,18,1,fp); 218 if(strcmp(Fild.field_name,"数学")==0) 219 { 220 start2=Fild.field_start; 221 p1=Fild.field_width; 222 count++; 223 } 224 if(strcmp(Fild.field_name,"姓名")==0) 225 { 226 start1=Fild.field_start; 227 count++; 228 p2=Fild.field_width; 229 } 230 if(strcmp(Fild.field_name,"英语")==0) 231 { 232 start3=Fild.field_start; 233 count++; 234 p3=Fild.field_width; 235 } 236 if(strcmp(Fild.field_name,"计算机")==0) 237 { 238 start4=Fild.field_start; 239 count++; 240 p4=Fild.field_width; 241 } 242 if(count==4) 243 break; 244 fseek(fp,14,1); 245 } 246 fseek(fp,head.file_width,0); 247 for(m=0; m<head.file_num; m++) 248 { 249 fseek(fp,head.file_width+m*head.rec_width,0); 250 ch=fgetc(fp); 251 if(ch=='*') 252 continue; 253 fseek(fp,head.file_width+m*head.rec_width+start1,0); 254 for(j=0; j<p2; j++) 255 name[j]=fgetc(fp); 256 name[j]='\0'; 257 j=0; 258 for(i=0; i<p2; i++) 259 { 260 261 if(name[i]!=32) 262 kk[j++]=name[i]; 263 } 264 kk[j]='\0'; 265 strcpy(student[app].name,kk); 266 score=0; 267 fseek(fp,m*head.rec_width+head.file_width+start2,0); 268 fgets(str,p1,fp); 269 for(i=0; i<strlen(str); i++) 270 { 271 if(str[i]==' ') 272 continue; 273 if(str[i]!='.'&&str[i-1]!='.') 274 score+=str[i]-48; 275 if(str[i+1]!='.'&&str[i]!='.'&&str[i-1]!='.') 276 score*=10; 277 if(str[i-1]=='.') 278 { 279 score+=(str[i]-48)/10.0; 280 break; 281 } 282 } 283 student[app].math=score; 284 fseek(fp,m*head.rec_width+head.file_width+start3,0); 285 fgets(str,p3,fp); 286 score=0; 287 for(i=0; i<strlen(str); i++) 288 { 289 if(str[i]==' ') 290 continue; 291 if(str[i]!='.'&&str[i-1]!='.') 292 score+=str[i]-48; 293 if(str[i+1]!='.'&&str[i]!='.'&&str[i-1]!='.') 294 score*=10; 295 if(str[i-1]=='.') 296 { 297 score+=(str[i]-48)/10.0; 298 break; 299 } 300 } 301 student[app].english=score; 302 fseek(fp,m*head.rec_width+head.file_width+start4,0); 303 fgets(str,p4,fp); 304 score=0; 305 for(i=0; i<strlen(str); i++) 306 { 307 if(str[i]==' ') 308 continue; 309 if(str[i]!='.'&&str[i-1]!='.') 310 score+=str[i]-48; 311 if(str[i+1]!='.'&&str[i]!='.'&&str[i-1]!='.') 312 score*=10; 313 if(str[i-1]=='.') 314 { 315 score+=(str[i]-48)/10.0; 316 break; 317 } 318 } 319 student[app].computer=score; 320 student[app].sum=student[app].english+student[app].math+student[app].computer; 321 fseek(fp,head.file_width+m*head.rec_width,0); 322 app++; 323 } 324 qsort(student,app,sizeof(student[0]),cmp); 325 for(i=0; i<app; i++) 326 printf("%s %.2lf %.2lf %.2lf %.2lf\n",student[i].name,student[i].english,student[i].math,student[i].computer,student 327 328 [i].sum); 329 fclose(fp); 330 } 331 long Mouse_operate(long kk,long m,char dis[][100],int pos[],long *cmp)/*鼠标操作*/ 332 { 333 int buttons,sum=0,i; 334 335 char str[100]; 336 setwritemode(XOR_PUT); 337 338 if(Akm==0) 339 { 340 init(2,638,8,477); 341 x=320; 342 y=240; 343 } 344 Akm=2; 345 cursor(x,y); 346 for(;;) 347 { 348 newxy(&x,&y,&buttons); 349 if(kbhit()) 350 { 351 opple++; 352 return kk; 353 } 354 if(x>=100&&x<=165&&y>=435&&y<=455&&m) 355 { 356 setcolor(15); 357 disphz(pos[0],437,dis[0],15,1); 358 359 *cmp=0; 360 if(buttons) 361 { 362 if(kk-3>=0) 363 return kk-3; 364 return kk; 365 } 366 } 367 else if(x>=260&&x<=325&&y>=435&&y<=455&&m) 368 { 369 setcolor(15); 370 371 disphz(pos[1],437,dis[1],15,1); 372 *cmp=1; 373 374 *cmp=1; 375 376 if(buttons) 377 { 378 if(kk+3<m) 379 return kk+3; 380 return kk; 381 } 382 } 383 else if(x>=420&&x<=485&&y>=435&&y<=455&&m) 384 { 385 setcolor(15); 386 disphz(pos[2],437,dis[2],15,1); 387 388 *cmp=2; 389 if(buttons) 390 { 391 return -1; 392 } 393 } 394 else if(x>=285&&x<=350&&y>=435&&y<=455&&m==0) 395 { 396 setcolor(15); 397 disphz(285,440,"退出",15,1); 398 399 400 *cmp=4; 401 if(buttons) 402 return -1; 403 } 404 else 405 { 406 if(*cmp==4) 407 disphz(285,440,"退出",0,1); 408 else 409 disphz(pos[*cmp],437,dis[*cmp],0,1); 410 411 } 412 413 } 414 415 } 416 int init(int xmin,int xmax,int ymin,int ymax)/*鼠标初始化*/ 417 { 418 union REGS regs; 419 regs.x.ax=0; 420 int86(51,®s,®s); 421 if(regs.x.ax==0) 422 return 0; 423 regs.x.ax=7; 424 regs.x.cx=xmin; 425 regs.x.dx=xmax; 426 int86(51,®s,®s); 427 regs.x.ax=8; 428 regs.x.cx=ymin; 429 regs.x.dx=ymax; 430 int86(51,®s,®s); 431 return -1; 432 } 433 int read_mouse(int *mx,int *my,int *mbutton)/*检测鼠标位置的变化*/ 434 { 435 union REGS regs; 436 int x0=*mx,y0=*my,button0=*mbutton; 437 int xnew,ynew; 438 do 439 { 440 regs.x.ax=3; 441 int86(0x33,®s,®s); 442 xnew=regs.x.cx; 443 ynew=regs.x.dx; 444 *mbutton=regs.x.bx; 445 } 446 while(xnew==0&&ynew==y0&&*mbutton==button0); 447 *mx=xnew; 448 *my=ynew; 449 switch(*mbutton) 450 { 451 case 0: 452 return 0; 453 case 1: 454 return 1; 455 case 2: 456 return 2; 457 case 3: 458 return 3; 459 default : 460 return 4; 461 } 462 } 463 void newxy(int *mx,int *my,int *mbutt)/*读取鼠标的位置,并在原来和现在的位置画鼠标*/ 464 { 465 int ch,xx0=*mx,yy0=*my; 466 int xm,ym; 467 ch=read_mouse(&xm,&ym,mbutt); 468 cursor(xx0,yy0); 469 cursor(xm,ym); 470 *mx=xm; 471 *my=ym; 472 473 } 474 void cursor(int x,int y)/*画箭头鼠标*/ 475 { 476 int x1,x2,y1,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8; 477 x1=x-15; 478 y1=y+15; 479 480 line(x,y,x1,y1); 481 x2=x1+5; 482 y2=y1+10; 483 line(x1,y1,x2,y2); 484 x3=x-2; 485 y3=y+15; 486 line(x2,y2,x3,y3); 487 x4=x-2; 488 y4=y+35; 489 line(x3,y3,x4,y4); 490 x5=x+15; 491 y5=y+15; 492 line(x,y,x5,y5); 493 x6=x5-5; 494 y6=y5+10; 495 line(x5,y5,x6,y6); 496 x7=x+2; 497 y7=y+15; 498 line(x6,y6,x7,y7); 499 x8=x7; 500 y8=y+35; 501 line(x7,y7,x8,y8); 502 line(x4,y4,x8,y8); 503 } 504 505 void picture(struct ranklist b[])/*柱状图显示成绩机器操作*/ 506 { 507 int i,j,gmode,gdriver=DETECT,q,kmp,a[3]= {9,8,6},k=30,pos[10],p; 508 long m,kk=0,l=6,n=0,cmp,num=0,flag=0,mmk=89; 509 char arr; 510 char page[][77]= {"(F)","(B)","(Esc)"}; 511 char str[22][22]= {"10","20","30","40","50","60","70","80","90","100"},dis[3][100]= {"前页","后页","退出"}; 512 m=app; 513 514 initgraph(&gdriver,&gmode,bgi); 515 key.cmp[1]=2; 516 while(1) 517 { 518 519 if(key.cmp[1]==1) 520 break; 521 k=50; 522 q=10; 523 l=6; 524 if(mmk!=kk) 525 { 526 line(25,10,25,405); 527 line(20,15,25,10); 528 line(30,15,25,10); 529 line(25,403,550,403); 530 line(540,399,550,403); 531 line(540,407,550,403); 532 outtextxy(15,15,"y"); 533 outtextxy(15,400,"o"); 534 outtextxy(560,400,"x"); 535 disphz(80,15,"学生成绩柱状图分布",4,2); 536 for(i=0; i<=9; i++) 537 { 538 line(25,400-q*3,30,400-q*3); 539 outtextxy(0,400-q*3,str[i]); 540 q+=10; 541 } 542 kmp=0; 543 544 for(i=0; i<3; i++) 545 { 546 setfillstyle(1,a[i]); 547 bar(540,kmp,575,30+kmp); 548 if(i==0) 549 disphz(575,10+kmp,"英语",4,1); 550 if(i==1) 551 disphz(575,10+kmp,"数学",4,1); 552 if(i==2) 553 disphz(575,10+kmp,"计算机",4,1); 554 kmp+=50; 555 556 } 557 flag++; 558 for(i=0; i<3; i++) 559 { 560 if(i+kk>=m) 561 break; 562 563 disphz(k+60,405,b[i+kk].name,4,1); 564 for(j=0; j<3; j++) 565 { 566 if(j==0) 567 { 568 setfillstyle(1,9); 569 bar3d(k,400-b[i+kk].english*3,k+50,400,35,1); 570 571 } 572 else if(j==1) 573 { 574 setfillstyle(1,8); 575 bar3d(k,400-b[i+kk].math*3,k+50,400,35,1); 576 if(flag==1) 577 { 578 pos[num]=k; 579 num++; 580 } 581 } 582 else 583 { 584 setfillstyle(1,6); 585 bar3d(k,400-b[i+kk].computer*3,k+50,400,35,1); 586 } 587 k+=50; 588 589 } 590 k+=10; 591 } 592 pos[num]='\0'; 593 594 for(cmp=0; cmp<3; cmp++) 595 { 596 597 setfillstyle(1,4); 598 if((kk==0&&cmp==0)||(cmp==1&&(kk+3>=app))) 599 setfillstyle(1,8); 600 bar3d(pos[cmp],435,pos[cmp]+65,455,12,1); 601 disphz(pos[cmp],437,dis[cmp],0,1); 602 outtextxy(pos[cmp]+39,440,page[cmp]); 603 } 604 605 } 606 else 607 cursor(x,y); 608 609 opple=0; 610 mmk=kk; 611 p=x; 612 q=y; 613 cmp=1; 614 kk=Mouse_operate(kk,m,dis,pos,&cmp) ; 615 616 if(kk==-1||key.cmp[1]==1)/*如果键盘按到"esc",或者鼠标按退出键跳出循环*/ 617 break; 618 n=3; 619 while(n--) 620 delay(ppqq); 621 if(opple==1) 622 kk=keyboard(kk,m,1) ;/*如果键盘有按键,则调用键盘*/ 623 if(mmk!=kk) 624 cleardevice(); 625 626 } 627 closegraph(); 628 } 629 int keyboard(long kk,long m,int k)/*键盘操作判断翻页问题*/ 630 { 631 key.key=bioskey(0); 632 if((key.cmp[0]=='F'||key.cmp[0]=='f')&&k==1) 633 { 634 if(kk-3>=0) 635 return kk-3; 636 return kk; 637 } 638 else if((key.cmp[0]=='B'||key.cmp[0]=='b')&&k==1)/*k==1说明柱状图调用k==2则是饼状图调用*/ 639 { 640 if(kk+3<m) 641 return kk+3; 642 return kk; 643 } 644 else if((key.cmp[0]=='x'||key.cmp[0]=='X')&&k==2) 645 { 646 647 return -2; 648 } 649 return kk; 650 651 } 652 void ask_rate(long hh[],long kk[],char rate[][123])/*将每个分数段的人数百分比转换成字符串*/ 653 { 654 long i,j,p,k,flag,s; 655 656 for(i=0; i<5; i++) 657 { 658 s=hh[i]; 659 flag=0; 660 k=1; 661 while(s) 662 { 663 s/=10; 664 flag++; 665 k*=10; 666 } 667 k/=10; 668 j=0; 669 while(k) 670 { 671 if(j==flag-2) 672 rate[i][j]='.'; 673 else 674 { 675 rate[i][j]=hh[i]/k+48; 676 hh[i]-=k*(hh[i]/k); 677 k/=10; 678 } 679 j++; 680 } 681 if(j>0) 682 { 683 rate[i][j]='%'; 684 685 rate[i][j+1]='\0'; 686 } 687 else 688 rate[i][j]='\0'; 689 690 } 691 692 } 693 694 void graph(struct ranklist *b)/*画圆饼图(包括图例及其百分比)*/ 695 { 696 int gmode,gdriver=DETECT,kmp,i,j; 697 long kk[7]= {0},start=0,l=2,kkk=2,m=0,k=30,mmp=0; 698 long hh[123],s,flag=0,kkp; 699 char rate[123][123]; 700 char name[123][123]; 701 char dis[6][100]; 702 double x,y,death,x1,y1; 703 initgraph(&gdriver,&gmode,bgi); 704 cleardevice(); 705 strcpy(dis[4],"退出"); 706 disphz(28,15,"学生成绩饼状图分布",4,2); 707 for(i=0; i<app; i++) 708 { 709 if(b[i].sum/3<=60) 710 kk[0]++; 711 else if(b[i].sum/3<=70) 712 kk[1]++; 713 else if(b[i].sum/3<=80) 714 kk[2]++; 715 else if(b[i].sum/3<=90) 716 kk[3]++; 717 else 718 kk[4]++; 719 } 720 kmp=0; 721 722 for(i=0; i<5; i++) 723 { 724 setfillstyle(1,kkk++); 725 bar(490,kmp,515,20+kmp); 726 if(i==0) 727 outtextxy(515,10+kmp,"0--60"); 728 if(i==1) 729 outtextxy(515,10+kmp,"60--70"); 730 if(i==2) 731 outtextxy(515,10+kmp,"70--80"); 732 if(i==3) 733 outtextxy(515,10+kmp,"80--90"); 734 if(i==4) 735 outtextxy(515,10+kmp,"90--100"); 736 kmp+=30; 737 738 } 739 for(i=0; i<5; i++) 740 { 741 hh[i]=10000*kk[i]*1.0/app; 742 } 743 ask_rate(&hh,&kk,rate); 744 for(i=0; i<5; i++) 745 { 746 747 setfillstyle(1,l++); 748 if(i==4) 749 pieslice(360,240,start,360,100); 750 else 751 pieslice(360,240,start,start+kk[i]*360/app,100); 752 mmp=start+kk[i]*360/app; 753 x1=(double)start; 754 y1=(double)mmp; 755 756 death=(x1+y1)/2.0; 757 758 if(death>90&&death<=180) 759 death=180.0-death,x1=(double)360-(double)(150)*cos(death/180*PI),y1=(double)240-(double)150*sin(death/180*PI),flag=2; 760 761 else if(death>=180&&death<270) 762 death-=180.0,x1=(double)360-(double)(150)*cos(death/180*PI),y1=(double)240+(double)150*sin(death/180*PI),flag=3; 763 else if(death>=270&&death<=360) 764 death=(double)360-death,x1=(double)360+(double)(150)*cos(death/180*PI),y1=(double)240+(double)150*sin(death/180*PI),flag=4; 765 else if(death<=90) 766 x1=(double)360+(double)(150)*cos(death/180*PI),y1=(double)240-(double)150*sin(death/180*PI),flag=1; 767 start+=kk[i]*360/app; 768 outtextxy(x1,y1,rate[i]); 769 770 771 } 772 773 774 775 setfillstyle(1,4); 776 bar3d(280,435,350,455,12,1); 777 disphz(285,440,dis[4],0,1); 778 setcolor(15); 779 outtextxy(324,440,"(X)"); 780 while(1) 781 { 782 k=Mouse_operate(k,0,dis,hh,&i) ; 783 784 if(k==-1) 785 return; 786 else 787 k=keyboard(k,m,2); 788 if(k==-2) 789 return; 790 } 791 cleardevice(); 792 } 793 void disphz(int x,int y,char *p,int color,int m)/*从文字库重打印汉字*/ 794 { 795 int i,j,n,k; 796 FILE *fp; 797 char qh,wh; 798 long offset; 799 char buffer[S*S/8]; 800 char mask[]= {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; 801 if((fp=fopen(HZK,"rb"))==NULL) 802 exit(0); 803 while(*p!='\0') 804 { 805 qh=*p-0xa0; 806 p++; 807 wh=*p-0xa0; 808 p++; 809 offset=(94L*(qh-1)+wh-1)*S*S/8; 810 fseek(fp,offset,0); 811 fread(buffer,S*S/8,1,fp); 812 for(i=0; i<S; i++) 813 { 814 for(j=0; j<S; j++) 815 { 816 if((buffer[S/8*i+j/8]&mask[j%8])!=0) 817 for(n=0; n<m; n++) 818 for(k=0; k<m; k++) 819 putpixel(x+j*m+n,y+i*m+k,color); 820 } 821 } 822 x+=S*m+5; 823 } 824 fclose(fp); 825 return; 826 } 827 void save_pic()/*储存整个屏幕(动画)*/ 828 { 829 FILE *fp; 830 int i; 831 char far *p; 832 long j; 833 fp=fopen("pic.dat","wb"); 834 for(i=0; i<4; i++) 835 { 836 outportb(0x3ce,4); 837 outportb(0x3cf,i); 838 p=(char far*)0xa0000000L; 839 for(j=0; j<38400L; j++) 840 { 841 fputc(*p,fp); 842 p++; 843 } 844 } 845 fclose(fp); 846 outportb(0x3cf,0); 847 } 848 void load_pic(int kk)/*加载动画*/ 849 { 850 FILE *fp; 851 int i,k=1; 852 char far *p; 853 long j; 854 fp=fopen("pic.dat","rb"); 855 for(i=0; i<4; i++) 856 { 857 outportb(0x3c4,2); 858 outportb(0x3c5,k); 859 p=(char far*)0xa0000000L-kk*80; 860 for(j=0; j<38400; j++) 861 { 862 *p=getc(fp); 863 p++; 864 } 865 k*=2; 866 } 867 fclose(fp); 868 outportb(0x3c5,0xcf); 869 } 870 871 void title()/*封面(程序简介*/ 872 873 { 874 int i,n=0,k=0; 875 int gmode,gdriver=DETECT; 876 char ppq[][111]= {"1:","一","二"}; 877 char str[][123]= {"","程","序","设","计"},arr[][111]= {"程序功能","显示学生成绩分布图","显示各分数段圆饼图"}; 878 initgraph(&gdriver,&gmode,bgi); 879 cleardevice(); 880 setcolor(15); 881 rectangle(130,180,500,400); 882 setbkcolor(3); 883 outtextxy(170,180,":"); 884 settextstyle(1,0,9); 885 outtextxy(70,20,"c"); 886 for(i=1; i<=5; i++) 887 { 888 setcolor(1); 889 circle(100+n,80,50); 890 disphz(70+n,46,str[i-1],4,3); 891 if(i<=3) 892 { 893 disphz(170,180+k,arr[i-1],4,1); 894 setcolor(4); 895 if(i>=2) 896 disphz(145,180+k,ppq[i-1],4,1); 897 } 898 n+=120; 899 k+=30; 900 } 901 disphz(210,320,"按任意键继续",15,2); 902 getch(); 903 closegraph(); 904 } 905 void backspace()/*最后一屏结束语*/ 906 { 907 settextstyle(1,0,9); 908 setcolor(4); 909 outtextxy(220,220,"The End"); 910 getch(); 911 } 912 void introduce()/*动画*/ 913 { 914 int i,k=0,n=30,p=0,l=5,opp=0,kk=0; 915 char str[][12]= {"首","先","感","谢","王","老","师","一","年","来","的","谆","谆","教","悔","和","辛","勤","的","付","出"}; 916 char arr[][13]= {"本","程","序","是","于","二","零","一","八","年","六","月","一","号","独","立","设","计","完","成","的"}; 917 char bbq[][123]= {"设","计","人",":","夏","令","富"}; 918 cleardevice(); 919 920 921 for(i=0; i<49; i++) 922 { 923 924 if(i<21) 925 disphz(220+k,240,str[i],4,1); 926 else if(i>=21&&i<42) 927 disphz(180+opp,260,arr[i%21],4,1),opp+=20; 928 else 929 disphz(320+kk,290,bbq[i-42],4,2),kk+=30; 930 k+=20; 931 my_sound(0); 932 933 } 934 935 save_pic(); 936 for(i=0; i<280; i++) 937 { 938 load_pic(i); 939 my_sound((i+1)%66); 940 cleardevice(); 941 } 942 backspace(); 943 944 } 945 void music(unsigned int freq,int times) 946 { 947 int i; 948 union 949 { 950 int divisor; 951 char c[2]; 952 } count; 953 char bits; 954 count.divisor=1193180/freq; 955 outportb(0x43,0xb6); 956 outportb(0x42,count.c[0]); 957 outportb(0x42,count.c[1]); 958 bits=inportb(0x61); 959 outportb(0x61,bits|3); 960 for(i=0; i<times; i++) 961 delay(15000); 962 outport(0x61,bits&0xfc); 963 outportb(0x61,bits); 964 } 965 void my_sound(int l)/*背景音乐*/ 966 { 967 int freq[8]= {0,256,294,330,349,392,440,494}; 968 int song[]= { 8,8,5,5,3,6,5,3, 969 2,1,2,3,1,0, 970 3,1,3,3,1, 971 3,3,5,6,5,0, 972 6,6,6,5,4,4,4, 973 2,3,2,1,2,0, 974 3,1,0,3,1,0, 975 3,3,5,6,6,0, 976 8,5,5,6,3, 977 2,1,2,3,5,5, 978 8,5,5,6,3, 979 2,1,2,3,1,1 980 981 982 }; 983 float div[]= { 8,8,8,8,8,8,8,8, 984 8,8,8,8,4,4, 985 4,4,8,8,4, 986 8,8,8,8,4,4, 987 8,8,8,8,8,8,4, 988 8,8,8,8,4,4, 989 4,8,8,4,8,8, 990 8,8,8,8,4,4, 991 4,8,8,4,4, 992 8,8,8,8,4,4, 993 4,8,8,4,4, 994 8,8,8,8,4,4 995 996 }; 997 unsigned int f; 998 int times,i; 999 for(i=l; i<l+1; i++) 1000 { 1001 if(song[i]<0) 1002 f=freq[-song[i]]/2; 1003 else if(song[i]>7) 1004 f=freq[song[i]%7]*2; 1005 else if(song[i]==0) 1006 f=100000000000000; 1007 else 1008 f=freq[song[i]]; 1009 times=16/div[i]; 1010 if(l==0) 1011 f=500; 1012 music(f,times); 1013 } 1014 return 0; 1015 } 1016 1017 int main() 1018 { 1019 struct ranklist student[123]; 1020 title();/*封面*/ 1021 1022 read_date(student);/*读数据库及文本框输入*/ 1023 if(sdibt==0) 1024 { 1025 picture(student);/*画柱状图*/ 1026 graph(student);/*画圆饼图*/ 1027 introduce();/*动画*/ 1028 } 1029 return 0; 1030 }
本文来自博客园,作者:左手边五十米,转载请注明原文链接:https://www.cnblogs.com/moomcake/p/8796627.html