C语言程序设计论文范本模板Word下载.docx
《C语言程序设计论文范本模板Word下载.docx》由会员分享,可在线阅读,更多相关《C语言程序设计论文范本模板Word下载.docx(15页珍藏版)》请在冰点文库上搜索。
![C语言程序设计论文范本模板Word下载.docx](https://file1.bingdoc.com/fileroot1/2023-4/30/baa16d04-28bc-49d3-9efe-61827be0ccd9/baa16d04-28bc-49d3-9efe-61827be0ccd91.gif)
(1)主函数模块
(2)设置系统进入图形模块
(3)初始化图形系统模块
(4)计算器计算函数模块
(5)窗口函数模块
(6)设计鼠标图形函数模块
(7)获取特殊键函数模块
六、软件环境:
Visualc++6.0
七、课程设计要求:
在计算机上操作,通过Visualc++6.0,设计出“计算器”程序。
八、应提交的材料:
实习报告一份,内容包含“计算器"
程序代码。
设计报告:
程序代码:
#include〈dos。
h>
#include<
math.h>
#include<
conio。
#include〈stdio.h>
#include〈stdlib。
#include〈stdarg。
graphics。
h〉
string。
#include〈ctype.h〉
#defineUP0x48
#defineDOWN0x50
#defineLEFT0x4b
#defineRIGHT0x4d
#defineENTER0x0d
void*rar;
structpalettetypepalette;
intGraphDriver;
intGraphMode;
intErrorCode;
intMaxColors;
intMaxX,MaxY;
doubleAspectRatio;
voiddrawboder(void);
voidinitialize(void);
voidcomputer(void);
voidchangetextstyle(intfont,intdirection,intcharsize);
voidmwindow(char*header);
intspecialkey(void);
intarrow();
intmain()
{
initialize();
computer();
closegraph();
return(0);
}
voidinitialize(void)
intxasp,yasp;
GraphDriver=DETECT;
initgraph(&GraphDriver,&GraphMode,"
”);
ErrorCode=graphresult();
if(ErrorCode!
=grOk)
{
printf("
GraphicsSystemError:
%s\n”,
grapherrormsg(ErrorCode));
exit
(1);
}
getpalette(&palette);
MaxColors=getmaxcolor()+1;
MaxX=getmaxx();
MaxY=getmaxy();
getaspectratio(&
xasp,&
yasp);
AspectRatio=(double)xasp/(double)yasp;
voidcomputer(void)
{
structviewporttypevp;
intcolor,height,width;
intx,y,x0,y0,i,j,v,m,n,act,flag=1;
floatnum1=0,num2=0,result;
charcnum[5],str2[20]={"
”},c,temp[20]={””};
charstr1[]=”1230。
456+-789*/Qc=^%"
;
mwindow(”Calculator"
);
color=7;
getviewsettings(&
vp);
width=(vp。
right+1)/10;
height=(vp.bottom-10)/10;
x=width/2;
y=height/2;
setfillstyle(SOLID_FILL,color+3);
bar(x+width*2,y,x+7*width,y+height);
setcolor(color+3);
rectangle(x+width*2,y,x+7*width,y+height);
setcolor(RED);
outtextxy(x+3*width,y+height/2,”0.”);
x=2*width—width/2;
y=2*height+height/2;
for(j=0;
j〈4;
++j)
for(i=0;
i〈5;
++i)
{
setfillstyle(SOLID_FILL,color);
setcolor(RED);
bar(x,y,x+width,y+height);
rectangle(x,y,x+width,y+height);
sprintf(str2,"
%c”,str1[j*5+i]);
outtextxy(x+(width/2),y+height/2,str2);
x=x+width+(width/2);
}
y+=(height/2)*3;
x=2*width-width/2;
x0=2*width;
y0=3*height;
x=x0;
y=y0;
gotoxy(x,y);
arrow();
putimage(x,y,rar,XOR_PUT);
m=0;
n=0;
strcpy(str2,”"
);
while((v=specialkey())!
=45)
while((v=specialkey())!
=ENTER)
putimage(x,y,rar,XOR_PUT);
if(v==RIGHT)
if(x〉=x0+6*width)
x=x0;
m=0;
else
x=x+width+width/2;
m++;
}
if(v==LEFT)
if(x<
=x0)
x=x0+6*width;
m=4;
}
x=x-width-width/2;
m--;
if(v==UP)
if(y<
=y0)
y=y0+4*height+height/2;
n=3;
y=y—height—height/2;
n--;
if(v==DOWN)
if(y>
=7*height)
y=y0;
y=y+height+height/2;
n++;
putimage(x,y,rar,XOR_PUT);
c=str1[n*5+m];
if(isdigit(c)||c=='
.’)
if(flag==-1)
strcpy(str2,”—”);
flag=1;
sprintf(temp,"
%c"
,c);
strcat(str2,temp);
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,str2);
if(c=='
+'
)
num1=atof(str2);
strcpy(str2,"
”);
act=1;
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,”0。
"
if(c==’—’)
if(strcmp(str2,"
”)==0)
flag=-1;
strcpy(str2,””);
act=2;
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"
0.”);
if(c==’*’)
strcpy(str2,"
act=3;
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"
/’)
act=4;
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
0."
^'
);
act=5;
setfillstyle(SOLID_FILL,color+3);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"
if(c==’%’)
strcpy(str2,””);
act=6;
bar(2*width+width/2,height/2,15*width/2,3*height/2);
outtextxy(5*width,height,"
='
num2=atof(str2);
switch(act)
case1:
result=num1+num2;
break;
case2:
result=num1—num2;
case3:
result=num1*num2;
break;
case4:
result=num1/num2;
case5:
result=pow(num1,num2);
case6:
result=fmod(num1,num2);
bar(2*width+width/2,height/2,15*width/2,3*height/2);
sprintf(temp,”%f”,result);
outtextxy(5*width,height,temp);
c'
num1=0;
num2=0;
bar(2*width+width/2,height/2,15*width/2,3*height/2);
0。
if(c==’Q’)exit(0);
putimage(x,y,rar,XOR_PUT);
return;
}
voidmwindow(char*header)
intheight;
cleardevice();
setcolor(MaxColors—1);
setviewport(20,20,MaxX/2,MaxY/2,1);
height=textheight(”H"
);
settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
settextjustify(CENTER_TEXT,TOP_TEXT);
outtextxy(MaxX/4,2,header);
setviewport(20,20+height+4,MaxX/2+4,MaxY/2+20,1);
drawboder();
voiddrawboder(void)
structviewporttypevp;
setlinestyle(SOLID_LINE,0,NORM_WIDTH);
vp);
rectangle(0,0,vp。
right-vp。
left,vp。
bottom-vp.top);
intarrow()
intsize;
intraw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4};
setfillstyle(SOLID_FILL,2);
fillpoly(8,raw);
size=imagesize(4,4,16,16);
rar=malloc(size);
getimage(4,4,16,16,rar);
putimage(4,4,rar,XOR_PUT);
return0;
/
intspecialkey(void)
intkey;
while(bioskey
(1)==0);
key=bioskey(0);
key=key&0xff?
key&0xff:
key>
>
8;
return(key);
总结:
1)实际操作过程中遇到的问题及解决方法:
1。
忘记加分号。
分号是C语句中不可缺少的一部分,语句末尾必须有分号.a=1b=2编译时,编译程序在“a=1”后面没发现分号,就把下一行“b=2”也作为上一行语句的一部分,这就会出现语法错误。
改错时,有时在被指出有错的一行中未发现错误,就需要看一下上一行是否漏掉了分号.{z=x+y;
t=z/100;
printf(”%f"
,t);
}对于复合语句来说,最后一个语句中最后的分号不能忽略不写(这是和PASCAL不同的).
2.输入输出的数据的类型与所用格式说明符不一致inta=3;
floatb=4.5;
printf(“%f%d\n"
a,b);
它们并不是按照赋值的规则进行转换(如把4.5转换为4),而是将数据在存储单元中的形式按格式符的要求组织输出(如b占4个字节,只把最后两个字节的数据按%d,作为整数输出)
2)设计总结及心得体会.
通过C语言编程的学习,培养了我独立思考和综合运用平时知识的能力,巩固了课程学习的内容,掌握了工程软件设计的基本方法,强化了上机动手编程能力。
更加了解了C语言的便利性和可用性.同时了解到了程序设计需要团队合作,通过这次实习活动增进了同学之间的默契,体会到了毕业后工作中团队合作的重要性和必要性。
当一个程序从自己的手中诞生的时候,心中充满了自豪感和成就感,让我对动手操作实践更有兴趣了。
八、时间:
实验心得
通过本次C语言上机实验,我对这个介于人类与非人类之间的计算机编程语言有了一定的体验。
其间开心过、郁闷过、无奈过、彷徨过……随着实验的胜利成功与实验报告的胜利完成,有点微微的自豪感使人难忘。
感谢高克宁老师的高标准、严要求,感谢实验课上小老师们的耐心指点,也感谢我在实验中经历过的点点滴滴……伴随着学习的深入,我发现高深的东西还有很多很多,等待着我自己去挖掘。
对C语言,我会更加努力一周课时:
12学时