




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机程序设计(C语言)课程设计报告题目:电子动画时钟 学院: 机电工程学院专业: 班级:090109班学号: 姓名: 指导教师: 设计日期: 一、概述选题背景 :随着社会的进步和科技的发展,电子钟表逐渐成为了人们生活中不可缺少的一部分。设计思路:(一)功能模块设计,1.电子时钟执行主流程2.电子时钟界面显示3.电子时钟按键控制模块4.时钟动画处理模块(二)数据结构设计1.time结构体2.全局变量(三)函数功能描述1.keyhandle()2.timeupchange()3.timedownchange()4.digitclock()5.drawcursor()6.clearcursor()
2、7.void clockhandle()8.main()(四)程序实现(五)运行结果。 二、概要设计2.1、数据结构 此程序中,使用了C语言的time结构体和几个全局变量,1.time结构体struct timeunsigned char ti_min; /*分钟*/unsigned char ti_hour; /*小时*/unsigned char ti_hund; /*百分之一秒*/unsigned char ti_sec; /*秒*/;time结构体定义在dos.h文件中,可用来保存系统的当前时间,其中各字段的值的含义如下。1.unsigned char ti_min:保存分钟值。2.u
3、nsigned char ti_hour:保存小时。3.unsigned char ti_hund:保存百分之一秒,例如,ti_hund=500,表示1/500秒。4.unsigned char ti_sec:保存秒数。2.2、全局变量 下面对程序用到的全局变量及数组进行说明.1. double h,m,s: 此3个全局变量分别用来保存小时,分钟,秒数。 2. double x,x1,x2,y,y1,y2:保存数字时钟中小时,分,秒在屏幕中显示的坐标值。3.struct time t1:定义一个time结构类型的数组,此数组只有t0一个元素。 2.3 模块列表 1.时钟动画处理模块时钟动画处理
4、模块主要由clockhandle()函数来实现,程序中旧时钟指针的擦除是借助setwritemode(mode)函数设置画线的方式来实现。如果mode=1,则表示画线时用现在特性的线所画之处原有的线性异或(XOR)操作,实际上画出的线是原有线与现在规定的线进行异或后的结果。因此,当线的特性不变时,进行两次画线操作相当于没有画线,即在当前位置处清除了原来的画线。2.时钟按键控制模块在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。3.数字时钟处理模块(1)调用digitclock(int x,int y,int clock)函数。在数字
5、时钟r指定位置显示时,分,秒,其中digithour(double h),int digitour(double h)和digitsec(doubles)用于完成数值的double型向int型转换。(2)调用drawcursor(int count),clearcursor(int count)函数来完成旧光标的擦除和新光标的绘制。2.4、程序结构图(也就是模块之间的关系) 数字时钟模块按键控模块界面显示模块时钟动画处理模块电子时钟 三 、详细设计3.1程序预处理模块。包括加载头文件,定义常量,变量,结构体数组和函数原型声明。 3.2主控模块main().main()函数主要实现了对电子时钟的
6、初始化工作,及clockhandle()函数的调用。3.3时钟动画处理模块。3.4时针按键控制模块。在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。流程图如下。3.5数字时针处理模块。在数字时钟处理模块中,主要实现数字时钟的显示和数字的时钟修改。其中,在数字时钟的修改中,用户可以按Tab键定位需要修改的内容的位置,然后通过按光标上移或下移键来修改时间。四、调试程序错误1: 错误现象:Declaration syntan error错误原因:声明错误,缺分号。修改方法:在声明语句后添加分号。错误2: 错误现象:Two few para
7、meters in call to setlinestyle in function main 错误原因:语句缺少参数。 修改方法:在main()函数中找到缺少参数的语句添加相应的参数。错误3:错误原因:Function call missing)in function clockhandle错误原因:在clockhandle函数调用的是后函数表达式缺少一个)。修改方法:找到错误语句添加缺少的表达式符号。五、心得总结程序优点:本程序旨在训练学生的基本编程能力,本程序中涉及时间结构体,数组,绘图等方面的知识,通过本程序的训练使学生能对C语言有一个更深刻的了解。掌握利用C语言相关函数开发电子时钟的
8、基本原理,为进一步开发出高质量的程序打下坚实的基础。程序缺点:程序各个模块之间的控制连接比较繁琐,容易出现错误。六附程序清单#include#include#include#include#define PI 3.1415926#define UP 0x4800#define DOWN 0x5000#define Esc 0x11b#define TAB 0xf09int keyhandle (int,int);int timeupchange (int);int timedownchange (int);int digithour (double);int digitmin (double)
9、;int digitsec (double);void digitclock (int,int,int);void drawcursor (int) ;void clearcursor (int) ;void clockhandle () ;double h,m,s ;double x,x1,x2,y,y1,y2;struct time t1 ; main()int driver,mode=0,i,j;driver =DETECT;initgraph (&driver, &mode,c:tc);setlinestyle (0,0,3);setbkcolor(0);line(82,430,558
10、,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,564,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,41
11、8,270,360,12);setcolor(15);outtextxy(300,53,CLOCK);setcolor(7);rectangle(342,72,560,360);setwritemode(0);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)
12、 setlinestyle(0,0,3); circle(i,j,1);setcolor(15) ;line(424,315,424,325);for(i=0,m=0,h=0;i=11;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
13、 ) ; circle(x,y,1) ;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);outtextxy(150,400, Nothing is mo
14、re 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=200-80*cos(m/30*PI) ;line(451,200,x1,y1
15、) ; 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-98*cos(s/30*PI) ;line(451,200,x2,y2 ) ;while(t0.ti
16、_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(451,200,x2,y2) ;if(t0.ti_min!=m ) setcolor(15) ; x1=80*s
17、in(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)+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(
18、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 keyhandle(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(co
19、unt) ;count+ ;break;return count ;int timeupchange(int count ) if(count=1) t0.ti_hour+; if(t0.ti_hour=24) t0.ti_hour=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) t0.ti_min=59 ; settime(t) ;if(count=3) t0.ti_sec- ; if(t0.ti_sec=0) t0.ti_sec=59; settime (t) ; void digitclock(int x, int y, int c
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GFRP筋-重晶石防辐射混凝土粘结性能试验研究
- 关汉卿《救风尘》的电视剧改编研究
- 创客大赛培训
- 儿童肺炎合并心衰补液诊疗要点
- 肺患者健康宣教
- 家庭科学教育实施策略
- 颐和园介绍课件
- 健康传播常用方法
- 小班培训诈骗案例分享
- 预防要先行班会课件
- 化工公司安全知识竞赛题库(共1000题)
- 中国移动公开竞聘考试题库(含答案)
- DLT 572-2021 电力变压器运行规程
- HJ 636-2012 水质 总氮的测定 碱性过硫酸钾消解紫外分光光度法
- 成都市2022级(2025届)高中毕业班摸底测试(零诊)数学试卷(含答案)
- 社会主义核心价值观融入幼儿园班级管理课程教学探索
- 《公平竞争审查条例》微课
- 四年级下册混合计算400题及答案
- 餐厅值班管理培训
- OQC出货检验技能培训
- 旅游产业行业分析
评论
0/150
提交评论