2022年2022年计算机程序设计课程设计报告 .pdf

上传人:Che****ry 文档编号:34875498 上传时间:2022-08-19 格式:PDF 页数:11 大小:784.22KB
返回 下载 相关 举报
2022年2022年计算机程序设计课程设计报告 .pdf_第1页
第1页 / 共11页
2022年2022年计算机程序设计课程设计报告 .pdf_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《2022年2022年计算机程序设计课程设计报告 .pdf》由会员分享,可在线阅读,更多相关《2022年2022年计算机程序设计课程设计报告 .pdf(11页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、计算机程序设计(C 语言)课程设计报告题目:电子动画时钟学院:机电工程学院专业:班级:090109 班学号:姓名:指导教师:名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 11 页 - - - - - - - - - 设计日期:一、概述选题背景 :随着社会的进步和科技的发展,电子钟表逐渐成为了人们生活中不可缺少的一部分。设计思路: ( 一) 功能模块设计,1. 电子时钟执行主流程2. 电子时钟界面显示3. 电子时钟按键控制模块4. 时钟动画处理模块 (二) 数据 结构 设

2、 计 1.time 结 构 体 2. 全 局 变 量 ( 三 ) 函 数 功 能 描 述1. keyhandle()2.timeupchange()3.timedownchange()4.digitclock()5.drawcu rsor()6.clearcursor()7.void clockhandle()8.main() ( 四)程序实现 ( 五) 运行结果。、概要设计2.1 、数据结构此程序中,使用了C 语言的 time 结构体和几个全局变量, l.time 结构体 struct timeunsigned char ti_min; /* 分钟 */ unsigned char ti_h

3、our; /* 小时*/ unsigned char ti_hund; /* 百分之一秒*/ unsigned char ti_sec; /* 秒*/ ; time 结构体定义在dos.h 文件中,可用来保存系统的当前时间,其中各字段的值的含义如下。1. unsigned char ti_min: 保存分钟值。2. unsigned char ti_hour: 保存小时。3. unsigned char ti_hund: 保存百分之一秒,例如, ti_hund=500 ,表示1/500 秒。4. unsigned char ti_sec: 保存秒数。2.2 、全局变量下面对程序用到的全局变量及

4、数组进行说明.1. double h,m,s: 此 3 个全局变量分别用来保存小时,分钟,秒数。2. double x,x1,x2,y,y1,y2: 保存数字时钟中小时,分,秒在屏幕中显示的坐标值。3. struct time t1: 定义一个time 结构类型的数组,此数组只有t0 一个2.3 模块列表1. 时钟动画处理模块时钟动画处理模块主要由clockhandle() 函数来实现,程序中旧时钟指针的擦除是借助 setwritemode(mode) 函数设置画线的方式来实现。如果mode=1 则 表示画线时用现在特性的线所画之处原有的线性异或( XOR 操作,实际上画出的线是原有线与现在规

5、定的线进行异或后的结果。因此,当线的特性不变时,进行两次画线操作相当于没有画线,即在当前位置处清除了原来的画线。2. 时钟按键控制模块在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。3. 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 11 页 - - - - - - - - - 数字时钟处理模块(1)调用 digitclock(int x,int y,int clock) 函数。在数字时钟r指定位置显示时,分

6、,秒,其中digithour(double h),i nt digitour(double h) 和digitsec(doubles) 用于完成数值的 double 型向 int 型转换。(2)调用drawcursor(int count),clearcursor(int count) 函数来完成旧光标的擦除和新光标的绘制。2.4、程序结构图 ( 也就是模块之间的关系 ) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 11 页 - - - - - - - - - 名师资

7、料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 11 页 - - - - - - - - - 三、详细设计3.1 程序预处理模块。包括加载头文件,定义常量,变量,结构体数组和函数原型声明。3.2 主控模块 main().main() 函数主要实现了对电子时钟的初始化工作,及clockha ndle() 函数的调用。3.3 时钟动画处理模块。3.4 时针按键控制模块。在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。流程

8、图如下。3.5 数字时针处理模块。在数字时钟处理模块中,主要实现数字时钟的显示和数字的时钟修改。其中,在数字时钟的修改中,用户可以按Tab 键定位需要修改的内容的位置,然后通过按光标上移或下移键来修改时间。四、调试程序错误 1: 错误现象:Declarati on syntan error 错误原因:声明错误,缺分号。修改方法:在声明语句后添加分号。错误 2:错误现象:Two few parameters in call to setlinestyle in function mai n 错误原因:语句缺少参数。修改方法:在 main() 函数中找到缺少参数的语句添加相应的参数。名师资料总结

9、- - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 11 页 - - - - - - - - - 错误 3:错误原因: Function call missing ) in function clockhandle 错误原因:在 clockhandle 函数调用的是后函数表达式缺少一个)。修改方法:找到错误语句添加缺少的表达式符号。五、心得总结程序优点:本程序旨在训练学生的基本编程能力,本程序中涉及时间结构体,数组, 绘图等方面的知识,通过本程序的训练使学生能对C 语言有一个更深刻的了解。

10、掌握利用 C 语言相关函数开发电子时钟的基本原理,为进一步开发出高质量的程序打下坚实的基础。程序缺点:程序各个模块之间的控制连接比较繁琐,容易出现错误。六?附程序清单#in clude #in clude #in clude #in clude #define PI 3.1415926 #define UP 0 x4800 #define DOWN 0 x5000 #define Esc 0 x11b #define TAB 0 xf09 int keyha ndle (in t,i nt); int timeupcha nge (in t); int timedow ncha nge (in

11、 t); int digithour (double); int digitm in (double); int digitsec (double); void digitclock (in t, in t,i nt); void drawcursor (int); void clearcursor (int); void clockha ndle (); double h,m,s ; double x,x1,x2,y,y1,y2; struct time t1; main () int driver,mode=0,i,j; driver =DETECT; in itgraph (&drive

12、r, &mode,c:tc); setli nestyle (0,0,3); setbkcolor(0); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 11 页 - - - - - - - - - line(82,430,558,430); line(70,62,70,418); line(82,50,558,50); line(570,62,570,418); line(70,62,570,62); line(76,56,297,56); line(340,56,5

13、64,56); /*arc(int x, int y, int. stangle, int endangle, int radius)*/ arc(82,62,90,180,12); arc(558,62,0,90,12); setlinestyle (0,0,3); arc(82,418,180,279,12); setlinestyle (0,0,3); arc(558,418,270,360,12); setcolor(15); outtextxy(300,53,CLOCK); setcolor(7); rectangle(342,72,560,360); setwritemode(0)

14、; setcolor(15); outtextxy(433,75,CLOCK); setcolor(7); line(392,310,510,310); line(392,330,510,330); arc(392,320,90,270,10); arc(510,320,270,90,10); setcolor(5); for(i=431;i=470;i+=39) for(j=317;j=324;j+=7) setlinestyle(0,0,3); circle(i,j,1); setcolor(15) ; line(424,315,424,325); for(i=0,m=0,h=0;i=11

15、;i+,h+) x=100*sin( (h*60+m)/360*PI)+451 ; y=200-100*cos( (h*60+m)/360*PI) ; setlinestyle(0,0,3) ; circle(x,y,1) ; for(i=0,m=0 ;i=59;m+,i+) x=100*sin (m/30*PI)+451; y=200-100*cos(m/30*PI ) ; setlinestyle(0,0,1 ) ; circle(x,y,1) ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - -

16、 - - - 第 7 页,共 11 页 - - - - - - - - - setcolor(4) ; outtextxy(182,125, HELP ) ; setcolor(5) ; outtextxy(140,185, TAB :Cursor move ) ; outtextxy(140,225, UP : Time +) ; outtextxy(140,265, DOWN : Time-) ; outtextxy(140,305, Esc : Quit system! ) ; outtextxy(140,345, Version : 2.0) ; setcolor(12); outte

17、xtxy(150,400, Nothing is more important than time ! ) ; clockhandle() ; closegraph() ; return(0); void clockhandle() int k=0,count ; setcolor(15) ; gettime(t) ; h=t0.ti_hour ; m=t0.ti_min ; x=50*sin(h*60+m)/360*PI)+451 ; y=200-50*cos(h*60+m) /360*PI) ; line(451,200,x,y); x1=80*sin(m/30*PI) +451 ; y1

18、=200-80*cos(m/30*PI) ; line(451,200,x1,y1) ; digitclock(408,318,digithour(h); digitclock(446,318,digitmin(m); setwritemode(1) ; for(count=2;k!=Esc;) setcolor(12) ; sound(500); delay(700); sound(200); delay(300); nosound() ; s=t0.ti_sec ; m=t0.ti_min ; h=t0.ti_hour ; x2=98*sin(s/30*PI)+451 ; y2=200-9

19、8*cos(s/30*PI) ; line(451,200,x2,y2 ) ; while(t0.ti_sec=s&t0.ti_min=m&t0.ti_hour=h) gettime(t); if(bioskey(1)!=0) k=bioskey(0); count=keyhandle(k,count) ; if(count=5) count=1 ; setcolor(15) ; digitclock (485,318,digitsec(s)+1) ; setcolor(12) ; x2=98*sin(s/30*PI)+451 ; y2=200-98*cos(s/30*PI ) ; line(

20、451,200,x2,y2) ; if(t0.ti_min!=m ) 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 8 页,共 11 页 - - - - - - - - - setcolor(15) ; x1=80*sin(m/30*PI)+451 ; y1=200-80*cos(m/30*PI ) ; line(451,200,x1,y1 ) ; m=t0.ti_min ; digitclock(446,318,digitmin(m) ) ; x1=80*sin(m/30*PI)

21、+451 ; y1=200-80*cos(m/30*PI) ; line(451,200,x1,y1 ) ; if(t0.ti_hour*60+t0.ti_min)!=(h*60+m) setcolor(15) ; x=50*sin(h*60+m)/360*PI)+451 ; y=200-50*cos(h*60+m)/360*PI); line(450,200,x,y ); h=t0.ti_hour ; digitclock(408,318,digithour (h) ) ; x=50*sin(h*60+m)/360*PI) ; line(451,200,x,y ) ; int keyhand

22、le(int key ,int count ) switch(key) case UP: timeupchange(count-1); break ; case DOWN :timedownchange (count-1) ; break ; case TAB :setcolor (15) ; clearcursor(count) ; drawcursor(count) ; count+ ; break; return count ; int timeupchange(int count ) if(count=1) t0.ti_hour+; if(t0.ti_hour=24) t0.ti_ho

23、ur=0; settime(t) ; if (count=2) t0.ti_min+; if(t0.ti_min=60) t0.ti_min=0 ; settime(t) ; if(count=3) t0.ti_sec+; if(t0.ti_sec=60) t0.ti_sec=0 ; settime(t) ; int timedownchange(int count ) if(count=1) t0.ti_hour- ; if(t0.ti_hour=0) t0.ti_hour=23 ; settime(t) ; if(count=2) t0.ti_min-; if(t0.ti_min=0) t

24、0.ti_min=59 ; settime(t) ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 9 页,共 11 页 - - - - - - - - - if(count=3) t0.ti_sec- ; if(t0.ti_sec=0) t0.ti_sec=59; settime (t) ; void digitclock(int x, int y, int clock) char buffer110; setfillstyle(0,2) ; bar (x,y,x+15,328)

25、 ; if (clock=60) clock=0 ; sprintf(buffer1,%d,clock) ; outtextxy(x,y,buffer1) ; int digithour(double h) int i; for(i=0;i=23;i+) if(h=i) return i ; int digitmin(double m) int i ; for(i=0;i=59 ;i+) if(m=i) return i; int digitsec(double s) int i; for(i=0; i=59;i+) if(s=i) return i ; void drawcursor (in

26、t count) switch(count) case 1:line (424,315,424,325);break ; case 2:line(465,315,465,325) ; break; case 3:line(505,315,505,325) ; break ; void clearcursor (int count) switch(count) case 2: line (424,315,424,325) ; break ; case 3:line (465,315,465,325) ; break ; case 1: line (505,315,505,325) ; break ; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 10 页,共 11 页 - - - - - - - - - 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 11 页,共 11 页 - - - - - - - - -

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com