绘制函数曲线
float x1,y1,x2,y2,x, y, coe_x,coe_y; initgraph(&graphdriver,&graphmode,""); cleardevice(); void far setviewport(int 10,int 10,int 600,int 600,clipflag 1); setbkcolor(blue); setcolor(yellow); coe_x=funx(max_x); coe_y=funy(max_y); void far line (int 20,int 210,int 580,int 210,color write); void far line(int 20,int 300,int 400,int 300,color write); outtextxy(290,220,"(0,0)"); outtextxy(590,220,"x"); outtextxy(290,10,"y"); x1=max_x/2+xmin*coe_x, y1=max_y/2-(a*xmin*coe_x*xmin*coe_x+b*xmin*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 k; menu(); while(1) { scanf("%d",&k); switch(k) { case 1: fun1(); case 2:fun2();break; case 3:fun3();break; case 4:exit(0);
default:printf("\n error \n"); } } }
总结:
这次课程设计,加强了我对c语言的了解。对一 些细节的掌握更加深刻,而且对一些没有学过的内 容通过查阅课外书也学会了,即增加了知识也加强 了自己动脑动手的能力。 同时也从中体会到了那种经过努力而得到成功的 喜悦,也对我以后工作学习带来了信心和帮助,从 而更加坚定了我对以后探索知识的信念,尽量的去 摄取更多的更深的知识,做一个合格的人
四、指导教师和学生签字 指导教师:________ 学生签名:刘峰________
五、成绩: 六、教师评语:
目录
(一).程序设计题目 (二).题目分析 (三).总体设计 (四).模块设计 (五).关键技术分析 (六).完整的源程序 (七).总结:
一·程序设计题目:绘制函数曲线。
二·题目分析:
(一). 经过对程序设计题目的分析可知,整个程序的设 计实现大致分为:绘制坐标.绘制图形。在绘制坐标 中,关键步骤是将笛卡儿坐标转化成屏幕坐标。 (二).需求分析: (1).首先要选择显示器适配器,由于不知道是什么类 型的适配器,所以用自动检测显示器适配器类 型。将相应的驱动器程序装入,并将其最高的 显示模式作为当前的显示模式。 (2).画图前一般要清除屏幕因, 因而必须使用清屏函数。 (3).为了简化运算,故而采用图 示口设置函数:既在图形方式下可以 在屏幕上某一区域设置一个窗口。这 样秒以后的画图均在这个窗口内进 行,且适用的坐标则以此窗口左边顶 上角为(0,0)点作参考而不再用屏 幕物理坐标(物理坐标把 显示屏左 上角定为(0,0)点)。在图示口内 可将画的图形显示出来每超出图示口 的不分可以不显示(剪断),也可以 显示(不减断)。
HELL0
Hale Waihona Puke printf("input a,b,c\n"); scanf("%f,%f,%f",&a,&b,&c); } fun2() { printf("input xmin,xmax\n"); scanf("%f,%f",&xmin,&xmax); } funmax() { float p,q; if(xmin<0) p=-xmin; else p=xmin; if(xmax<0) q=-xmax; else q=xmax; if(p>=q) max=p; else max=q; } float funx(float max_x),max x=600 { return(max_x/2/max); } float funy(float max_y),may y=420 float t; t=max_y/2/(a*max*max+b*max+c); return(t); } fun3() { int max_x=600,max_y=420; int graphdriver=DETECT,graphmode;
图2
五·关键技术分析
1.显示器设定:
int graphdriver=DETECT,graphmode
2.图形初始化:
initgraph(&graphdriver,&graphmode,"")
3.图示口设置:
void far setviewport(int 10,int 10,int 600,int 600,clipflag 1); setbkcolor(blue); setcolor(yellow);
4.绘制坐标轴:
void far line(int 0,int 210,int 600,int210,color write ); void far line(int 300,int 0,int 300,int420,color write); outtextxy(290,220,"(0,0)"); outtextxy(590,220,"x"); uttextxy(290,10,"y");
沈阳航空工业学院
课程设计
学 班 姓
号: 级: 名:
指导教师: 尹 航
沈阳航空工业学院
课程设计任务书
课程设计题目:绘制函数曲线 一、课程设计工作自2008年3月17日起至2008年3月24日止 二、课程设计内容:
用C语言编写软件完成以下任务: 在图形模式下,绘制一元二次函数ax2+bx+c.其中 系数a,b,c,以及X的取值范围,均由用户从键盘输 入。
6.目录选择功能:
switch(n) { case 1:fun1();break; case 2:fun2();break; case 3:fun3();break; case 4:exit(0); default:printf("\n error \n")
图3数据的输入
六·完整的源程序
#include<stdio.h> #include<graphics.h> float a,b,c,xmin,xmax,max; void menu() { printf("\n************************************ ***********\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() {
四·模块设计
fun3 Int grophdriver=DETECT,graphmode initgraph(&graphdriver,&graphmode,"") Void far cleardevice Void far setviewport(int 10,int10,int610,int430,clipflag 1) 绘制坐标 x1=max_x/2+xmin*coe_x,y1=max_y/2(a*xmin*coe_x*xmin*coe_x+b*xmin*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);
(4). 画出坐标轴。在屏幕上画图 时,同在纸上画图一样。在纸上画 线,画笔要放在开始画图的位置,并 经常要抬笔移动满意边到另一位置再 做画图动作。在屏上画图时也可想象 有一无形的画笔,可以控制它的定 位.移动(不画).可知道它能移动的 最大位置限定等。 .
三·总体设计:
开始 设置窗口 菜单 退出 输入xmin,xmax 输出 图像 输入a,b,c
5.坐标之间的转换:
x1=max_x/2+xmin*coe_x,y1=max_y/2(a*xmin*coe_x*xmin*coe_x+b*xmin*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) }