终结版的大程序

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#define S 16
#define HZK  "C:\\tc\\HZK16"
char tt[100];
void disphz(int x,int y,char *q,int color,int m);
void cursor(int x,int y);
struct jilu
{
    char name[10];
    char kong;
    char kind;
    long start;
    char length;
    char xiaoshu;
    char c[14];
} u[4];
struct people
{
    char name1[10];
    double english;
    double math;
    double computer;
    double zongfen;
} x[100],y;
int wenjian(struct people *x)
{
    FILE *fp;
    long jizong,i,j,k,t;
    short touchang,jiluchang;
    char english1[10],math[10],computer[10],hao;
    double xiaoshu;
    fp=fopen(tt,"rb");
    fseek(fp,4,1);
    fread(&jizong,4,1,fp);
    fread(&touchang,2,1,fp);
    fread(&jiluchang,2,1,fp);
    fseek(fp,32,0);
    for(;;)
    {
        fread(&u[0],32,1,fp);
        if(strcmp(u[0].name,"姓名")==0)
            break;
    }
    fseek(fp,32,0);
    for(;;)
    {
        fread(&u[1],32,1,fp);
        if(strcmp(u[1].name,"英语")==0)
            break;
    }
    fseek(fp,32,0);
    for(;;)
    {
        fread(&u[2],32,1,fp);
        if(strcmp(u[2].name,"数学")==0)
            break;
    }
    fseek(fp,32,0);
    for(;;)
    {
        fread(&u[3],32,1,fp);
        if(strcmp(u[3].name,"计算机")==0)
            break;
    }
    t=0;
    for(i=0; i<=jizong-1; i++)
    {
        xiaoshu=0;
        fseek(fp,touchang,0);
        fseek(fp,jiluchang*i,1);
        fread(&hao,1,1,fp);
        if(hao=='*')
            continue;
        fseek(fp,u[0].start-1,1);
        fgets(x[t].name1,u[0].length+1,fp);
        for(j=u[0].length-1; j>=0; j--)
        {
            if(x[t].name1[j]==' ')
                x[t].name1[j]=0;
            else
                break;
        }
        fseek(fp,-u[0].start-u[0].length,1);
        fseek(fp,u[1].start,1);
        fgets(english1,u[1].length+1,fp);
        x[t].english=atof(english1);
        fseek(fp,-u[1].start-u[1].length,1);
        fseek(fp,u[2].start,1);
        fgets(math,u[2].length+1,fp);
        x[t].math=atof(math);
        fseek(fp,-u[2].start-u[2].length,1);
        fseek(fp,u[3].start,1);
        fgets(computer,u[3].length+1,fp);
        x[t].computer=atof(computer);
        x[t].zongfen=x[t].english+x[t].math+x[t].computer;
        t++;
    }
    for(i=0; i<=t-2; i++)
    {
        k=i;
        for(j=i+1; j<=t-1; j++)
            if(x[k].zongfen<x[j].zongfen)
                k=j;
        y=x[k];
        x[k]=x[i];
        x[i]=y;
    }
    for(j=0; j<=t-2; j++)
        if(x[j].zongfen==x[j+1].zongfen)
        {
            if(x[j].english<x[j+1].english)
                y=x[j],x[j]=x[j+1],x[j+1]=y;
            if(x[j].english==x[j+1].english)
            {
                if(x[j].computer<x[j+1].computer)
                    y=x[j],x[j]=x[j+1],x[j+1]=y;
            }
        }
    fclose(fp);
    return t;
}
int huatu(struct people *x,int t)
{
    union
    {
        int key;
        char c[2];
    } m;
    int i,b,c,j,d=1,e=1,k,button,flag,a1=70;
    int x1,y1,x0,y0,v;
    char p;
    int gdriver=VGA, gmode=VGAHI;
    initgraph(&gdriver, &gmode, "c:\\TC20\\BGI");
    cleardevice();
    for(k=0; k<=t-1; )
    {
        setfillstyle(1,1);
        bar(500,40,540,60);
        disphz(545,40,"英语",14,1);
        setfillstyle(1,2);
        bar(500,60,540,80);
        disphz(545,60,"数学",14,1);
        setfillstyle(1,3);
        bar(500,80,540,100);
        disphz(545,80,"计算机",14,1);
        b=70;
        c=100;
        line(70,360,600,360);
        line(600,360,590,360);
        line(600,360,590,370);
        line(70,20,70,360);
        line(70,20,60,30);
        line(70,20,80,30);
        outtextxy(600,365,"y");
        outtextxy(60,10,"x");
        outtextxy(72,362,"o");
        outtextxy(72,340,"10");
        outtextxy(72,320,"20");
        outtextxy(72,300,"30");
        outtextxy(72,280,"40");
        outtextxy(72,260,"50");
        outtextxy(72,240,"60");
        outtextxy(72,220,"70");
        outtextxy(72,200,"80");
        outtextxy(72,180,"90");
        outtextxy(72,160,"100");
        if(k==0)
        {
            setfillstyle(1,2),bar3d(150,400,170,410,10,1);
            outtextxy(160,405,"P");
        }
        else
        {
            setfillstyle(1,1),bar3d(150,400,170,410,10,1);
            outtextxy(160,405,"P");
        }
        if(k==t-2)
        {
            setfillstyle(1,2),bar3d(350,400,370,410,10,1);
            outtextxy(360,405,"N");
        }
        else
        {
            setfillstyle(1,1),bar3d(350,400,370,410,10,1);
            outtextxy(360,405,"N");
        }
        setfillstyle(1,1),bar3d(550,400,570,410,10,1);
        outtextxy(560,405,"X");
        for(i=0; i<=2; i++)
        {
            if(i+k>t-1)
                break;
            if(i>=1)
                b+=40,c+=40;
            for(j=0; j<=2; j++)
            {
                b+=30;
                c+=30;
                if(j==0)
                    setfillstyle(d,1),bar3d(b,360-(long)(x[i+k].english*2),c,360,20,1);
                if(j==1)
                    setfillstyle(d,2),bar3d(b,360-(long)(x[i+k].math*2),c,360,20,1);
                if(j==2)
                    setfillstyle(d,3),bar3d(b,360-(long)(x[i+k].computer*2),c,360,20,1);
            }
            disphz(b-40,370,x[i+k].name,14,1);
        }
        while(1)
        {
            _AX=3;
            geninterrupt(0x33);
            x1=_CX,y1=_DX;
            button=_BX;
            if(x0!=x1||y0!=y1)
            {
                cursor(x0,y0);
                cursor(x1,y1);
            }
            x0=x1,y0=y1;
            if(bioskey(1))
            {
                m.key=bioskey(0);
                if((m.c[0]=='p'||m.c[0]=='P')&&k>=3)
                {
                    k-=3;
                    break;
                }
                if((m.c[0]=='n'||m.c[0]=='N')&&k<=t-4)
                {




                    k+=3;
                    break;
                }
                if(m.c[0]=='x'||m.c[0]=='X')
                {
                    v=2;
                    break;
                }
            }
            else if(button&1!=0)
            {
                if(k>=3&&(x1>=150&&x1<=170)&&(y1>=400&&y1<=410))
                {
                    k-=3;
                    delay(50000);
                    break;
                }
                else if(k==0&&(x1>=150&&x1<=170)&&(y1>=400&&y1<=410))
                {
                    delay(50000);
                    break;
                }


                else if((x1>=350&&x1<=370)&&(y1>=400&&y1<=410)&&k<=t-4)
                {
                    k+=3;
                    delay(50000);
                    break;
                }
                else if((x1>=550&&x1<=570)&&(y1>=400&&y1<=410))
                {
                    flag=2;
                    delay(50000);
                    break;
                }
            }
        }
        if(v==2||flag==2)
            break;
        cleardevice();
        /*printf("%lf%lf%lf\n",x[k].math,x[k].english,x[k].computer);*/
    }




    closegraph();
    return 0;
}
void huatu2 (struct people *p,int x)
{
    int a=0,b=0,c=0,d=0,e=0,f=0,i;
    int gdriver=VGA,gmode=VGAHI;
    initgraph(&gdriver,&gmode,"c:\\TC20\\BGI");
    for(i=0; i<x; i++)
    {
        if(p[i].zongfen/3<60)
            e++;
        if(p[i].zongfen/3>=60&&p[i].zongfen/3<70)
            d++;
        if(p[i].zongfen/3>=70&&p[i].zongfen/3<80)
            c++;
        if(p[i].zongfen/3>=80&&p[i].zongfen/3<90)
            b++;
        if(p[i].zongfen/3>=90)
            a++;
    }
    setfillstyle(1,14);
    bar(500,110,540,130);
    outtextxy(545,120,"90~100");
    pieslice(320,240,0,3600*(a*0.1/x),100);
    setfillstyle(1,4);
    bar(500,130,540,150);
    outtextxy(545,140,"80~90");
    pieslice(320,240,3600*(a*0.1/x),3600*(a*0.1/x)+3600*(b*0.1/x),100);
    setfillstyle(1,3);
    bar(500,150,540,170);
    outtextxy(545,160,"70~80");
    pieslice(320,240,3600*(a*0.1/x)+3600*(b*0.1/x),3600*(a*0.1/x)+3600*(b*0.1/x)+3600*(c*0.1/x),100);
    setfillstyle(1,2);
    bar(500,170,540,190);
    outtextxy(545,180,"60~70");
    pieslice(320,240,3600*(a*0.1/x)+3600*(b*0.1/x)+3600*(c*0.1/x),3600*(a*0.1/x)+3600*(b*0.1/x)+3600*(c*0.1/x)+3600*(d*0.1/x),100);
    setfillstyle(1,1);
    bar(500,190,540,210);
    outtextxy(545,200,"0~60");
    pieslice(320,240,3600*(a*0.1/x)+3600*(b*0.1/x)+3600*(c*0.1/x)+3600*(d*0.1/x),3600*(a*0.1/x)+3600*(b*0.1/x)+3600*(c*0.1/x)


+3600*(d*0.1/x)+3600*(e*0.1/x),100);
    getch();
    closegraph();
}




void cursor(int x,int y)
{




    setwritemode(XOR_PUT);
    line(x,y,x,y+11);
    line(x,y,x+12,y);
    line(x,y+12,x+12,y);
    line(x+4,y+8,x+9,y+13);
    line(x+8,y+4,x+13,y+9);
    line(x+9,y+13,x+13,y+9);
    setwritemode(COPY_PUT);








}
void voice()
{
    char bits;
    union
    {
        int divisor;
        char c[2];
    } countt;
    int i;
    for(i=0; i<100; i++)
    {
        countt.divisor=600;
        outportb(0x43,0xb6);
        outportb(0x42,countt.c[0]);
        outportb(0x42,countt.c[1]);
        bits=inport(0x61);
        outportb(0x61,bits|3);
        delay(500);
        outportb(0x61,bits&0xfc);
        outportb(0x61,bits);
    }




}




void disphz(int x,int y,char *p,int color,int m)
{
    int i,j,n,k;
    char qh,wh;
    FILE *fp;
    long offset;
    char buffer[S*S/8];
    char mask[]= {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
    if((fp=fopen(HZK,"rb"))==NULL)
        exit(0);
    while(*p!='\0')
    {
        qh=*p-0xa0;
        p++;
        wh=*p-0xa0;
        p++;
        offset=(94L*(qh-1)+(wh-1))*S*S/8;
        fseek(fp,offset,0);
        fread(buffer,S*S/8,1,fp);
        for(i=0; i<S; i++)
        {
            for(j=0; j<S; j++)
            {
                if((buffer[S/8*i+j/8]&mask[j%8])!=0)
                    for(n=0; n<m; n++)
                        for(k=0; k<m; k++)
                            putpixel(x+j*m+n,y+i*m+k,color);
            }
        }
        x+=S*m+5;
    }
    fclose(fp);
}




void huatu3()
{
    int gdriver=VGA, gmode=VGAHI;
    int ge=0,x=0,y=0,i,l;
    char a[2]= {0},c[2]= {0},d[]="c:\\ss1.dbf";
    initgraph(&gdriver, &gmode, "c:\\TC20\\BGI");
    cleardevice();
    setcolor(15);
    bar(100,190,400,220);
    disphz(100,140,"请输入地址",6,1);
    setcolor(1);
    outtextxy(200,145,":");
    disphz(100,250,"例如",6,1);
    setcolor(1);
    outtextxy(140,255,":");
    outtextxy(160,255,d);
    for(;;)
    {
        while(!bioskey(1))
        {
            setcolor(15);
            line(102+x,218,109+x,218);
            delay(50);
            setcolor(0);
            line(102+x,218,109+x,218);
            delay(50);
        }
        a[0]=bioskey(0);
        if(a[0]=='\r')
            break;
        if(a[0]==8&&x==0)
            ;
        else if(a[0]==8&&x!=0)
        {
            setcolor(15);
            line(102+x,218,109+x,218);
            ge-=1;
            tt[ge]=0;
            x-=15;
            setcolor(15);
            outtextxy(102+x,198,c);
            c[0]=tt[ge-1];
        }
        else if((a[0]>=65&&a[0]<=90)||(a[0]>=97&&a[0]<=120)||a[0]=='.'||a[0]=='\\'||a[0]==':'||a[0]==' '||(a[0]>=48&&a[0]<=57))
        {
            if(x+109<=400)
            {
                tt[ge]=a[0];
                outtextxy(102+x,198,a);
                setcolor(15);
                line(102+x,218,109+x,218);
                c[0]=tt[ge];
                ge+=1;
                x+=15;
            }
        }
    }
    closegraph();
    /*if(b[strlen(b)-4]!='.')
        strcat(b,".dbf");*/
}
void fengmian()
{
    int gdriver=VGA, gmode=VGAHI;
    initgraph(&gdriver, &gmode, "c:\\TC20\\BGI");
    cleardevice();
    setbkcolor(0);
    setcolor(10);
    circle(110,150,30);
    circle(180,150,30);
    circle(250,150,30);
    circle(320,150,30);
    circle(390,150,30);
    circle(460,150,30);
    circle(530,150,30);
    setcolor(14);
    settextstyle(1,0,4);
    outtextxy(95,130,"C");
    disphz(170,140,"语",2,1);
    disphz(240,140,"言",2,1);
    disphz(310,140,"程",2,1);
    disphz(380,140,"序",2,1);
    disphz(450,140,"设",2,1);
    disphz(520,140,"计",2,1);
    setcolor(9);
    disphz(200,240,"程序功能",9,1);
    settextstyle(0,0,2);
    outtextxy(280,240,":");
    outtextxy(240,260,"1");
    outtextxy(240,280,"2");
    disphz(260,260,"显示学生直方图",14,1);
    disphz(260,280,"显示饼状图",14,1);
    setcolor(8);
    rectangle(170,200,470,420);
    disphz(200,300,"姓名",6,1);
    outtextxy(240,300,":");
    disphz(250,300,"边浩东",6,1);
    disphz(200,320,"班级",6,1);
    outtextxy(240,320,":");
    disphz(250,320,"计科一七二",6,1);
    disphz(200,340,"学号",6,1);
    outtextxy(240,340,":");
    setcolor(3);
    outtextxy(250,340,"2017211773");
    getch();
    cleardevice();
}
void weiye()
{
    int gdriver=VGA, gmode=VGAHI,a,b,c=1;
    int d[]= {"此","程","序","完","成","于","二","零","一","八","年","六","月","二","号"},i,e;
    int h,n,z,x,f[]= {"指","导","老","师","王","金","鹏"},m;
    int g[]= {"感","谢","老","师","的","辛","勤","教","导"};
    int k[]= {"祝","老","师","身","体","健","康","万","事","如","意"};
    initgraph(&gdriver, &gmode, "c:\\TC20\\BGI");
    cleardevice();
    e=80;
    h=200;
    c=1;
    e=80;
    getch();
    for(i=1; i<=15; i++)
    {
        disphz(e,h-120,d[i-1],c,1);
        delay(50000);
        voice();
        c++;
        e+=30;
    }


    m=180;
    c=1;
    for(i=1; i<=7; i++)
    {
        disphz(m,h-80,f[i-1],c,1);
       delay(50000);
        voice();
        c++;
        m+=30;
    }
  
    n=150;
    c=1;
    for(i=1; i<=9; i++)
    {
        disphz(n,h-40,g[i-1],c,1);
       delay(50000);
        voice();
        c++;
        n+=30;
    }


    z=120;
    c=1;
    for(i=1; i<=11; i++)
    {
        disphz(z,h,k[i-1],c,1);
        delay(50000);
        voice();
        c++;
        z+=30;
    }
    
    e=80;
    for(i=1; i<=15; i++)
    {
        disphz(e,h-120,d[i-1],0,1);
        e+=30;
    }
    m=180;
    for(i=1; i<=7; i++)
    {
        disphz(m,h-80,f[i-1],0,1);
        m+=30;
    }
    n=150;
    for(i=1; i<=9; i++)
    {
        disphz(n,h-40,g[i-1],0,1);
        n+=30;
    }
    z=120;
    for(i=1; i<=11; i++)
    {
        disphz(z,h,k[i-1],0,1);
        z+=30;
    }
    a=240,b=240;
    while(b>=-30)
    {
        disphz(a,b,"愿岁月静我们不散",14,1);
        sleep(1);
        disphz(a,b,"愿岁月静我们不散",0,1);
        b-=30;
    }
    getch();
}
int main()
{
    int b,c;
    fengmian();
    huatu3();
    b=wenjian(x);
    c=huatu(&x[0],b);
    if(c==0)
        huatu2(&x[0],b);
    weiye();
    return 0;
}

猜你喜欢

转载自blog.csdn.net/najiuzheyangbaacm/article/details/80576518