当前位置: 代码迷 >> C语言 >> 将学生分数以棒图的形式显示出来?请教
  详细解决方案

将学生分数以棒图的形式显示出来?请教

热度:507   发布时间:2006-07-16 23:28:10.0

#include <stdio.h>
#include <graphics.h>
int main(void){
char* categories[] = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"};
float a[] = {3.9,5.3,7.2,9.6,12.9,17.0,23.2,31.4,39.8,50.2,62.9,76.0,92.0,105.7,122.8,131.7,150.7,179.3,203.2,211.0};
char s[10];
int graphdriver = VGA;
int graphmode = VGAHI,i,j,x,n,dx,ddx,y,dy;

initgraph(&graphdriver,&graphmode,"");
cleardevice();
setviewport(20,20,570,450,1);
setcolor(1);
setbkcolor(7);
n = 20;
dx = n;
ddx = 0.8*dx;
y = 390;
for(i=0;i<=n-1;i++){
x = dx*i + 100;
dy = a[i]*1.5;
setfillstyle(1,i);
rectangle(x,y,x+ddx,y-dy);
floodfill(x+1,y-dy+1,1);
}
setcolor(WHITE);
rectangle(80,390,x+ddx+20,15);
j = 0;
for(i=108;i<=x+ddx;i+=20){
line(i,390,i,400);
outtextxy(i-4,405,categories[j]);
j++;
}
sprintf(s,"%d",j);
for(j=0;j<=300;j+=50){
line(70,390-1.5*j,80,390-1.5*j);
sprintf(s,"%d",j);
outtextxy(45,390-1.5*j-3,s);
}
outtextxy(150,420,"Every year 1990-2000");
settextstyle(0,1,1);
outtextxy(30,40,"Production");
getch();
closegraph();

return 0;
}


----------------解决方案--------------------------------------------------------

强 好强


----------------解决方案--------------------------------------------------------
可以解释一下嘛?
----------------解决方案--------------------------------------------------------
哪有这么多问题.要多几个就把它做成函数,多调用几次不就可以了嘛....

反正神都直接给出答案了.你自己看看他的应该也是全屏的吧.

C里面的图形处理不都是全屏幕的么?

我这个暑假要上个网也真是不容易的喃.不好意思咯!
----------------解决方案--------------------------------------------------------