900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 计算机专业课程设计报告c语言 计算机程序设计(C语言)课程设计报告.doc

计算机专业课程设计报告c语言 计算机程序设计(C语言)课程设计报告.doc

时间:2023-01-02 23:58:43

相关推荐

计算机专业课程设计报告c语言 计算机程序设计(C语言)课程设计报告.doc

计算机程序设计(C语言)课程设计报告.doc

计算机程序设计C语言课程设计报告题目电子动画时钟 学院 机电工程学院专业 班级090109班学号 姓名 指导教师 设计日期 一、概述选题背景 随着社会的进步和科技的发展,电子钟表逐渐成为了人们生活中不可缺少的一部分。设计思路(一)功能模块设计,1.电子时钟执行主流程2.电子时钟界面显示3.电子时钟按键控制模块4.时钟动画处理模块(二)数据结构设计1.time结构体2.全局变量(三)函数功能描述1.keyhandle2.timeupchange3.timedownchange4.digitclock5.drawcursor6.clearcursor7.void clockhandle8.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.unsigned char ti_hour保存小时。3.unsigned char ti_hund保存百分之一秒,例如,ti_hund500,表示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.时钟动画处理模块时钟动画处理模块主要由clockhandle函数来实现,程序中旧时钟指针的擦除是借助setwritemodemode函数设置画线的方式来实现。如果mode1,则表示画线时用现在特性的线所画之处原有的线性异或(XOR操作,实际上画出的线是原有线与现在规定的线进行异或后的结果。因此,当线的特性不变时,进行两次画线操作相当于没有画线,即在当前位置处清除了原来的画线。2.时钟按键控制模块在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。3.数字时钟处理模块(1)调用digitclockint x,int y,int clock函数。在数字时钟r指定位置显示时,分,秒,其中digithourdouble h,int digitourdouble h和digitsecdoubles用于完成数值的double型向int型转换。(2)调用drawcursorint count,clearcursorint count函数来完成旧光标的擦除和新光标的绘制。2.4、程序结构图(也就是模块之间的关系) 数字时钟模块按键控模块界面显示模块时钟动画处理模块电子时钟 三 、详细设计3.1程序预处理模块。包括加载头文件,定义常量,变量,结构体数组和函数原型声明。 3.2主控模块main.main函数主要实现了对电子时钟的初始化工作,及clockhandle函数的调用。3.3时钟动画处理模块。3.4时针按键控制模块。在电子时钟中,按键控制模块最主要的工作就是必须能读取用户按键,对按键值进行判断,并调用相应函数来执行相关操作。流程图如下。3.5数字时针处理模块。在数字时钟处理模块中,主要实现数字时钟的显示和数字的时钟修改。其中,在数字时钟的修改中,用户可以按Tab键定位需要修改的内容的位置,然后通过按光标上移或下移键来修改时间。四、调试程序错误1 错误现象Declaration syntan error错误原因声明错误,缺分号。修改方法在声明语句后添加分号。错误2 错误现象Two few parameters in call to setlinestyle in function main 错误原因语句缺少参数。 修改方法在main函数中找到缺少参数的语句添加相应的参数。错误3错误原因Function call missing)in function clockhandle错误原因在clockhandle函数调用的是后函数表达式缺少一个)。修改方法找到错误语句添加缺少的表达式符号。五、心得总结程序优点本程序旨在训练学生的基本编程能力,本程序中涉及时间结构体,数组,绘图等方面的知识,通过本程序的训练使学生能对C语言有一个更深刻的了解。掌握利用C语言相关函数开发电子时钟的基本原理,为进一步开发出高质量的程序打下坚实的基础。程序缺点程序各个模块之间的控制连接比较繁琐,容易出现错误。六附程序清单includegraphics.hincludestdio.hincludemath.hincludedos.hdefine PI 3.1415926define UP 0 x4800define DOWN 0 x5000define Esc 0 x11bdefine TAB 0 xf09int keyhandle int,int;int timeupchange int;int timedownchange int;int digithour double;int digitmin double;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 ; mainint driver,mode0,i,j;driver DETECT;initgraph setlinestyle 0,0,3;setbkcolor0;line82,430,558,430;line70,62,70,418;line82,50,558,50;line570,62,570,418;line70,62,570,62;line76,56,297,56;line340,56,564,56;/*arcint x, int y, int. stangle, int endangle, int radius*/arc82,62,90,180,12;arc558,62,0,90,12;setlinestyle 0,0,3;arc82,418,180,279,12;setlinestyle 0,0,3;arc558,418,270,360,12;setcolor15;outtextxy300,53,CLOCK;setcolor7;rectangle342,72,560,360;setwritemode0;setcolor15;outtextxy433,75,CLOCK;setcolor7;line392,310,510,310;line392,330,510,330;arc392,320,90,270,10;arc510,320,270,90,10;setcolor5;fori431;i470;i39 forj317;j324;j7 setlinestyle0,0,3; circlei,j,1;setcolor15 ;line424,315,424,325;fori0,m0,h0;i11;i,h x100*sin h*60m/360*PI451 ; y200-100*cos h*60m/360*PI ; setlinestyle0,0,3 ; circlex,y,1 ; fori0,m0 ;i59;m,i x100*sin m/30*PI451; y200-100*cosm/30*PI ; setlinestyle0,0,1 ; circlex,y,1 ;setcolor4 ;outtextxy182,125, HELP ;setcolor5 ;outtextxy140,185, TAB Cursor move ;outtextxy140,225, UP Time ;outtextxy140,265, DOWN Time ;outtextxy140,305, Esc Quit system ;outtextxy140,345, Version 2.0 ;setcolor12;outtextxy150,400, Nothing is more important than time ;clockhandle ;closegraph ;return0;void clockhandle int k0,count ;setcolor15 ;gettimet ;ht0.ti_hour ;mt0.ti_min ;x50*sinh*60m/360*PI451 ;y200-50*cosh*60m /360*PI ;line451,200,x,y;x180*sinm/30*PI 451 ;y1200-80*cosm/30*PI ;line451,200,x1,y1 ; digitclock408,318,digithourh; digitclock446,318,digitminm;setwritemode1 ;forcount2;kEsc; setcolor12 ; sound500; delay700; sound200; delay300;nosound ;st0.ti_sec ;mt0.ti_min ;ht0.ti_hour ;x298*sins/30*PI451 ;y2200-98*coss/30*PI ;line451,200,x2,y2 ;whilet0.ti_secst0.ti_minmt0.ti_hourh gettimet; ifbioskey10 kbioskey0; countkeyhandlek,count ; ifcount5 count1 ; setcolor15 ;digitclock 485,318,digitsecs1 ;setcolor12 ;x298*sins/30*PI451 ;y2200-98*coss/30*PI ;line451,200,x2,y2 ;ift0.ti_minm setcolor15 ; x180*sinm/30*PI451 ; y1200-80*cosm/30*PI ; line451,200,x1,y1 ;mt0.ti_min ;digitclock446,318,digitminm ;x180*sinm/30*PI451 ;y1200-80*cosm/30*PI ;line451,200,x1,y1 ;ift0.ti_hour*60t0.ti_minh*60m setcolor15 ;x50*sinh*60m/360*PI451 ; y200-50*cosh*60m/360*PI;line450,200,x,y ; ht0.ti_hour ; digitclock408,318,digithour h ;x50*sinh*60m/360*PI ;line451,200,x,y ;int keyhandleint key ,int count switchkey case UP timeupchangecount-1; break ;case DOWN timedownchange count-1 ;break ;case TAB setcolor 15 ;clearcursorcount ;drawcursorcount ;count ;break;return count ;int timeupchangeint count ifcount1 t0.ti_hour; ift0.ti_hour24 t0.ti_hour0; settimet ; if count2 t0.ti_min; ift0.ti_min60 t0.ti_min0 ; settimet ;ifcount3 t0.ti_sec;ift0.ti_sec60 t0.ti_sec0 ;settimet ;int timedownchangeint count ifcount1 t0.ti_hour ; ift0.ti_hour0 t0.ti_hour23 ; settimet ; ifcount2 t0.ti_min; ift0.ti_min0 t0.ti_min59 ; settimet ;ifcount3 t0.ti_sec ; ift0.ti_sec0 t0.ti_sec59; settime t ; void digitclockint x, int y, int clockchar buffer110; setfillstyle0,2 ; bar x,y,x15,328 ; if clock60 clock0 ; sprintfbuffer1,d,clock ; outtextxyx,y,buffer1 ;int digithourdouble h int i; fori0;i23;i ifhi return i ; int digitmindouble m int i ; fori0;i59 ;i ifmi return i;int digitsecdouble s int i; fori0; i59;i ifsi return i ;void drawcursor int countswitchcount case 1line 424,315,424,325;break ; case 2line465,315,465,325 ; break; case 3line505,315,505,325 ; break ; void clearcursor int count switchcount case 2 line 424,315,424,325 ; break ; case 3line 465,315,465,325 ; break ; case 1 line 505,315,505,325 ; break ; 结束

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。