#includefloat a,b,c,xmin,xmax,max; /*定义全局变量*/
void menu()
{printf("\n************************************WELCOME***********
**************************\n");
printf("\n 1.input coefficient");
printf("\n 2.input extent");
printf("\n 3.draw function curve");
printf("\n 4.quit");
printf("\n***************************************************
*****************************\n");
}
fun1()
{
printf("input a,b,c\n");
scanf("%f,%f,%f",&a,&b,&c); /*输入系数a,b,c*/
}
fun2() /*输入x范围*/
{
printf("input xmin,xmax\n");
scanf("%f,%f",&xmin,&xmax);
}
funmax() /*求出x轴最大范围*/
{
float m,n;
if(xmin<0)
m=-xmin;
else
m=xmin;
if(xmax<0)
n=-xmax;
else
n=xmax;
if(m>=n)
max=m;
else
max=n;
}
float funx(float max_x) /*求出x轴对应系数*/
{
return(max_x/2/max);
}
float funy(float max_y) /*求出y轴对应系数*/
{
float d;
d=max_y/2/(a*max*max+b*max+c);
if(d>0.6)
d=0.6;
if(d<0.0026)
d=0.0026;
return(d);
}
fun3()
{
int max_x,max_y;
int graphdriver=DETECT,graphmode;
float x1,y1,x2,y2,x,coe_x,coe_y;
initgraph(&graphdriver,&graphmode,""); /*图形初始化*/
cleardevice(); /*清屏*/
max_x=getmaxx(); /*求出屏幕最大横坐标*/
max_y=getmaxy(); /*求出屏幕最大横坐标*/
funmax();
coe_x=funx(max_x);
coe_y=funy(max_y);
line(0,240,640,240); /*画直线*/
line(320,0,320,480);
line(640,240,635,235);
line(640,240,635,245);
line(320,0,315,5);
line(320,0,325,5);
outtextxy(320,240,"(0,0)"); /*在固定点输出字符串*/
outtextxy(620,240,"x");
outtextxy(320,10,"y");
x1=max_x/2+xmin*coe_x,y1=max_y/2-(a*xmin*coe_x*xmin*coe_x+b*xm
n*coe_x+c)*coe_y;
moveto((int)x1,(int)y1);
for(x=xmin*coe_x;x<=xmax*coe_x;x++)
{
x2=max_x/2+x,y2=max_y/2-(a*x*x+b*x+c)*coe_y;
lineto((int)x2,(int)y2);
}
getch();
closegraph(); /*关闭图形函数*/
}
main()
{
int n;
menu();
while(1)
{
scanf("%d",&n);
switch(n)
{ case 1:fun1();break;
case 2:fun2();break;
case 3:fun3();break;
case 4:exit(0);
default:printf("\n error \n");
}
}
总结:
这次课程设计,加强了我对c语言的了解。课程设计所面临的问题都是一些实际问题,在完成的过程中,解决实际问题的能力就很重要,还有一些是以前在课堂上没有学过的知识,这就要求我们去查一些资料,并学习。虽然个人的程序不同,但还需要与别人的合作,因为我还有些不明白的知识,尤其是自学的知识,运用还不熟练,特别需要虚心的请教老师。因此,老师在这次实践过程中给了我很大的帮助。
总之,这次课程设计带给我的不仅仅是完成后的喜悦,而是对我以后学习起到了很大的帮助。今后的学习中,还会遇到很多没学过的知识,就要求我们去自主学习,去了解,去充实自己的知识,作一个有学识的人!
10