课程设计报告日历管理器_第1页
课程设计报告日历管理器_第2页
课程设计报告日历管理器_第3页
课程设计报告日历管理器_第4页
课程设计报告日历管理器_第5页
已阅读5页,还剩26页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、c+课程设计报告(2011)c+课程设计报告( 2010 - 2011 年度第 二 学期)日历管理器的设计与实现专业计算机科学与技术学生姓名班级学号指导教师完成日期2011年 7月 日1目 录1 概 述11.1 课程设计目的11.2 课程设计内容12 系统需求分析12.1 系统目标12.2 主体功能12.3 开发环境23 系统概要设计23.1 系统的功能模块划分23.2 系统流程图34系统详细设计34.1系统主界面设计34.2 计算当前日期模块设计54.3年份跳转模块设计54.4 界面修改模块模块设计75 测试75.1 测试方案75.2 测试结果76 小结8参考文献10附 录11附录1 源程序

2、清单113日历管理器的设计与实现1 概 述 1.1 课程设计目的1、巩固并加深学生对c+语言程序设计知识的理解;2、培养学生面向对象的程序设计思想,使学生认识面向过程和面向对象两种设计方法的区别;3、进一步掌握和应用vc+ 6.0集成开发环境;4、提高运用c+语言解决实际问题的能力; 5、初步掌握开发小型实用软件的基本方法,能独立设计、实现具有实际功能的小系统;6、掌握书写程序设计开发文档的能力(书写课程设计实验报告)。1.2 课程设计内容课程名称:日历管理器说明:模仿现实生活中的挂历,显示日历。要求:1)当前页以系统当前日期的月份为准,显示当前月的每一天(显示出日及对应的星期几),当系统日期

3、变到下一月时,系统自动翻页到下一月。2)可以实现日期的加法运算,即在日期相加的菜单选项中增加日期加天数,结果为新日期。3)根据用户输入的年份,自动产生每个月的日期列表。包括输入非法数据(如负数、日期超过31天等情况)的识别显示功能。4)自定义显示日历的形式,如显示星期及英文形式的月份的功能 2 系统需求分析2.1 系统目标能模仿现实生活中的挂历,显示当前日期,且能实现日期的跳转来方便用户。2.2 主体功能1)当前页以系统当前日期的月份为准,显示当前月的每一天(显示出日及对应的星期几),当系统日期变到下一月时,系统自动翻页到下一月。2)可以实现日期的加法运算,即在日期相加的菜单选项中增加日期加天

4、数,结果为新日期。3)根据用户输入的年份,自动产生每个月的日期列表。包括输入非法数据(如负数、日期超过31天等情况)的识别显示功能。2.3 开发环境visual c+ 6.03 系统概要设计3.1 系统的功能模块划分此次系统的功能模块主要分为:当前日期计算模块、日期跳转模块和界面修改模块。当前日期计算模块:计算系统当前日期,并第一时间显示出来,方便用户能第一时间了解当前日期。日期跳转模块:主要针对用户想查看其他年份的日期情况设计,用户在想查看某个年份日期的时候只需操作一下,输入想查看的年份,该模块便会位用户显示出该年的日期情况。界面修改模块:现代产品功能丰富,因为用户的需求很多,该模块旨在提供

5、给用户更多的选择空间。该模块在内部提空多种界面颜色,用户只需在需要时执行操作便可更换界面上某个位置显示的颜色,大大增加软件的趣味性。日历管理系统当前日期计算模块日期跳转模块界面修改模块图 3-1 系统功能模块图3.2 系统流程图开始计算当前日期是否要跳转日期结束确定是否为合法输入是否是否输出显示本年日历输入目的年份输出显示目的年份日历图3-2 系统流程图4系统详细设计4.1系统主界面设计在该系统中我使用了mfc对主界面进行编辑,主界面最显眼的是日历部分,在日历上方是菜单栏,可以提供一些操作的按钮,实现该系统的多元功能。实际效果如下图所示:图4-1 菜单栏效果图图4-2 系统主界面图该系统中还会

6、出现一些输入框和提示框,这些框如下图:图4-3 处于编辑模式下的输入框在这个编辑输入框中的显示“enter year!”的部件是一个标签,起提示作用;写着“编辑”二字的框是个文本框,用来获取用户输入的年份数据;写着“ok”和“cancle”的两个部件分别是两个功能按钮,在编码完成后即可用来实现操作。图4-4 编辑模式下的信息提示框4.2 计算当前日期模块设计该系统在这个模块中建立了ccalender类,并建立m_cnday、m_cnyear、m_nuseryear函数来调用系统当前日期以实现该模块功能。该系统还建立了dialogtime类,在这个类中系统使用了switch语句,建立了m_szd

7、ays7数组来对日期进行从周日到周六的排序,以此实现显示出的日历和我们生活中的日历类似。要实现对日期的排列,首先需要对年份进行闰年的判断,其判断流程图如下图:开始获取年份是否为世纪年能否被4整除能否被100整除能否被400整除是是否闰年否是平年结束否否是图4-3 判断闰年流程图4.3年份跳转模块设计该系统在这个模块中建立了yeardialog类,在类中通过使用ddx_text、ddv_minmaxuint函数、调用m_nuseryear、m_cnyear等函数来实现日期跳转到用户输入的年份。要正确跳转到目的年份首先需要确定目的年的第一天的日期,以此类推可以推出全年的日期。流程图如下:x=0x=

8、6星期六开始w=y+y/4+c/4-2c+26(m+1)/10+d-1x=(w/2)后取余的余数x=1x=2x=3x=4x=5星期日星期一星期二星期三星期四星期五结束是否是否是否是否是否是否是分别输入y=年份 c=世纪-1 m=月 w=星期图 4-4 判断目的年份日期流程图4.4 界面修改模块模块设计该系统在这个模块中在ccalender类里建立了m_crwindow、m_crmonths、m_crweekdays、m_crdays、m_crtoday、m_crtodaysbox多个函数,各函数代表的是相关界面部分颜色信息,系统首先给界面函数设置了初始值,又建立了getwindowcolor(

9、)、getmonthscolor()、getweekdayscolor()、getdayscolor()、gettodaycolor()、gettodaysboxcolor()函数来获取用户操作后输入的值,以此改变界面多个部分颜色,从而达到该模块能修改界面的功能。5 测试5.1 测试方案运行该系统:1、测试系统能否显示当前日期;2、操作相应按钮,观察能否准确跳转到输入的年份日历表,且当输入数据为非法数据时能否出现提醒;3、能否更改界面颜色。5.2 测试结果1、能准确显示当前日期,且以粉色突出显示;图5-1 当前日期显示图2、能跳转到用户输入的年份,且当输入非法数据时提醒;图5-2 年份跳转提示

10、窗口图图5-3 非法数据提示框图3、对于窗口、月份、星期、当前日期等部分,用户都可以实现对其颜色的更改操作。图5-4 界面颜色更改效果图根据测试情况,以上测试均能有效实现功能,测试成功。6 小结为期两周的课程设计终于结束了。在这次的课程设计中我不但提升了自己查阅资料的能力,也更加深入的了解和熟悉了vc+软件的使用和c+这门课程。事实上去年我们也做过一次类似的课程设计,那次的课程设计我以为是比较难的了,那次实验前的准备工作就耗费了我大量的时间和精力,没想到这次试验实验课题下来的时候,我才认识到我们的课程设计会越来越多,也会越来越难,这是我们作为程序设计专业的学生必须去承受的,因为只有实践操作才能

11、不断提升我们的能力。我也认识到了原来自己学习到的c+语言知识是那么片面,多么欠缺,这当然也提升了我对专业知识更浓厚的兴趣。在这次课程设计中我遇到的问题也是不断而来,首先是源程序中的错误导致程序无法运行,都是自己输入程序时不小心导致的,这花费了我大量的时间去核对源代码,都是些标点的错误使用和大小写的不区分,这给了我一次小小的教训;其次是功能的欠缺和不完善导致软件功能的不理想,这直接影响到了这次课程设计的质量,为了完善功能,我不断查阅资料并求助同学,最终将问题妥善解决。忙碌的课程设计就快结束了,这几天的忙碌也让我在放假前体验了学习的紧张氛围,虽然自己的成果并没有让我感到满意,但起码让我对自己有了一

12、定的认识,也敲响了我的警钟,提醒我要重视自己的专业课,不要懈怠,同时我也了解到其他同学的帮助对自己的重要性。我以后我要更加认真的学习专业课程和做好课程设计,以认真的态度去完成自己的学业。29参考文献1谭浩强.c程序设计(第三版)m.北京:清华大学出版社,2005. 2谭浩强.c程序设计题解与上机指导(第三版)m.北京:清华大学出版社,2005.3陈清华,朱红.visual c+程序设计案例精选与编程指导m.南京:东南大学出版社,2003.4董士海.图像格式编程指南m.北京:清华大学出版社,1994.7张岳新.visual c+程序设计基础m.苏州:苏州大学出版社,2000.8陆润民.c语言绘图

13、教程m.北京:清华大学出版社,1996.附 录附录1 源程序清单#include<afxwin.h>#include"calender.h"int ccalender:m_cnday = 3;/wednesdayint ccalender:m_cnyear = 2003;/current yearint ccalender:m_nuseryear = 2003;colorref ccalender:m_crwindow = rgb(255,255,255);colorref ccalender:m_crmonths =rgb(0 ,0 ,255);colorre

14、f ccalender:m_crweekdays = rgb(0 ,255,0 );colorref ccalender:m_crdays = rgb(255,0 ,0 );colorref ccalender:m_crtoday = rgb(255,0 ,0 );colorref ccalender:m_crtodaysbox = rgb(255,255,255);/-ccalender:ccalender()m_nuseryear = m_cnyear;/-void ccalender:setyear(int nyear=2003)int ndiff = 0;int nleapyear =

15、 0;int i = 0;m_nuseryear = nyear;m_cnday = 3;/wednesday 1st jan 2003if( m_cnyear > nyear )ndiff = m_cnyear - nyear;for( i=nyear; i<m_cnyear; i+ )if( i%4 = 0 )nleapyear+;ndiff += nleapyear;ndiff = ndiff % 7;for( i=ndiff; i>=1; i- )m_cnday-;if( m_cnday<0 )m_cnday = 6;else if( m_cnyear <

16、 nyear )ndiff = nyear - m_cnyear;for( i=m_cnyear; i<nyear; i+ )if( i%4 = 0 )nleapyear+;ndiff += nleapyear;ndiff = ndiff % 7;for( i=ndiff; i>=1; i- )m_cnday+;if( m_cnday >= 7 )m_cnday = 0;/-int ccalender:getyear()return m_nuseryear;/-void ccalender:showday(cdc *d)int nx = 5;int ny = 50;int i

17、,j,k;i = j = k = 0;cstring m_szdays7;m_szdays0 = "sun"m_szdays1 = "mon"m_szdays2 = "tue"m_szdays3 = "wed"m_szdays4 = "thu"m_szdays5 = "fri"m_szdays6 = "sat"d->setbkmode(transparent);d->settextcolor(m_crdays);for( i=0; i<4

18、; i+ )for( j=0; j<3; j+ )for( k=0; k<7; k+ )d->textout(nx,ny,m_szdaysk,3);nx += 35;nx += 23;nx = 5;ny += 185;/-void ccalender:showmonth(cdc *d)cfont myfont;myfont.createfont(20,10,0,0,0,0,0,0,0,0,0,0,0,"arial");d->selectobject(&myfont);d->setbkmode(transparent);d->set

19、textcolor(m_crmonths);d->textout(85 ,22 ,"january");d->textout(352,22 ,"febuary");d->textout(632,22 ,"march");d->textout(103,208,"april");d->textout(370,208,"may");d->textout(635,208,"june");d->textout(103,392,"jul

20、y");d->textout(360,392,"august");d->textout(615,392,"september");d->textout(85 ,578,"octuber");d->textout(345,578,"november");d->textout(615,578,"december");/-void ccalender:showcalender(cdc *d)int i,j,k,count;int x = 5;int y = 82

21、;int curday;int curmonth;int month;char str3;int m_nmonths12;ctime t = ctime:getcurrenttime();curday = t.getday();curmonth = t.getmonth();m_nmonths0 = 31;m_nmonths1 = ( m_nuseryear%4 = 0 )? 29 : 28;m_nmonths2 = 31;m_nmonths3 = 30;m_nmonths4 = 31;m_nmonths5 = 30;m_nmonths6 = 31;m_nmonths7 = 31;m_nmon

22、ths8 = 30;m_nmonths9 = 31;m_nmonths10 = 30;m_nmonths11 = 31;count = i = j = k = 0;d->setbkmode(transparent);month=1;for(j=0; j<4; j+ )for( k=0; k<3; k+ )if ( j=0 && k=0 )x = 5; y = 82;else if( j=0 && k=1 )x = 270; y = 82;else if( j=0 && k=2 )x = 540; y = 82;else if(

23、j=1 && k=0 )x = 5; y = 265;else if( j=1 && k=1 )x = 270; y = 265;else if( j=1 && k=2 )x = 540; y = 265;else if( j=2 && k=0 )x = 5; y = 448;else if( j=2 && k=1 )x = 270; y = 448;else if( j=2 && k=2 )x = 540; y = 448;else if( j=3 && k=0 )x = 5; y

24、 = 631;else if( j=3 && k=1 )x = 270; y = 631;else if( j=3 && k=2 )x = 540; y = 631;x += m_cnday*35;for( i=1; i<=m_nmonthscount; i+ )if( curday = i && curmonth = month )d->settextcolor( m_crtoday );sprintf(str,"%3d",i);d->textout(x,y,str,strlen(str);elsed-&g

25、t;settextcolor( (m_cnday=0)? m_crweekdays : rgb(0,0,0);sprintf(str,"%3d",i);d->textout(x,y,str,strlen(str);x+=35;m_cnday+;if( m_cnday>=7 )m_cnday = 0;if( k=0 ) x=5;if( k=1 ) x=270;if( k=2 ) x=540;y+=20;count+;month+;/-void ccalender:setdayscolor(colorref crcolor)m_crdays = crcolor;/-

26、void ccalender:setmonthscolor(colorref crcolor)m_crmonths = crcolor;/-void ccalender:settodaycolor(colorref crcolor)m_crtoday = crcolor;/-void ccalender:settodaysboxcolor(colorref crcolor)m_crtodaysbox = crcolor;/-void ccalender:setwindowcolor(colorref crcolor)m_crwindow = crcolor;/-void ccalender:s

27、etweekdayscolor(colorref crcolor)m_crweekdays = crcolor;/-colorref ccalender:getdayscolor()return m_crdays;/-colorref ccalender:getmonthscolor()return m_crmonths;/-colorref ccalender:gettodaycolor()return m_crtoday;/-colorref ccalender:gettodaysboxcolor()return m_crtodaysbox;/-colorref ccalender:get

28、windowcolor()return m_crwindow;/-colorref ccalender:getweekdayscolor()return m_crweekdays;/-#ifndef calender_h#define calender_hclass ccalenderprivate:static int m_cnday;static int m_cnyear;static int m_nuseryear;static colorref m_crwindow;static colorref m_crmonths;static colorref m_crweekdays;stat

29、ic colorref m_crdays;static colorref m_crtoday;static colorref m_crtodaysbox;public:ccalender();void setyear(int nyear);int getyear();void showday(cdc *d);void showmonth(cdc *d);void showcalender(cdc *d);void setwindowcolor(colorref crcolor);void setmonthscolor(colorref crcolor);void setweekdayscolo

30、r(colorref crcolor);void setdayscolor(colorref crcolor);void settodaycolor(colorref crcolor);void settodaysboxcolor(colorref crcolor);colorref getwindowcolor();colorref getmonthscolor();colorref getweekdayscolor();colorref getdayscolor();colorref gettodaycolor();colorref gettodaysboxcolor();#endif#i

31、nclude "resource.h"class dialogtime:public cdialogpublic:dialogtime(int n):cdialog(n)bool oninitdialog()return cdialog:oninitdialog();void dodataexchange(cdataexchange *pdx)cdialog:dodataexchange(pdx);cedit *e = (cedit*)getdlgitem(idc_edit1);char sday10;char smonth10;char str50;int n;ctime

32、 t = ctime:getcurrenttime();n = t.getdayofweek();switch(n)case 1:sprintf(sday,"%s","sunday"); break;case 2: sprintf(sday,"%s","monday"); break; case 3: sprintf(sday,"%s","tuesday"); break;case 4: sprintf(sday,"%s","wednesday&

33、quot;);break;case 5: sprintf(sday,"%s","thursay"); break; case 6: sprintf(sday,"%s","friday"); break;case 7: sprintf(sday,"%s","saturday"); break;n = t.getmonth();switch(n)case 1 : sprintf(smonth,"%s","january"); break;c

34、ase 2 : sprintf(smonth,"%s","febuary"); break; case 3 : sprintf(smonth,"%s","march"); break;case 4 : sprintf(smonth,"%s","april"); break;case 5 : sprintf(smonth,"%s","may"); break; case 6 : sprintf(smonth,"%s",

35、"june"); break;case 7 : sprintf(smonth,"%s","july"); break;case 8 : sprintf(smonth,"%s","august"); break;case 9 : sprintf(smonth,"%s","september"); break; case 10: sprintf(smonth,"%s","octuber"); break;case 11:

36、 sprintf(smonth,"%s","november"); break;case 12: sprintf(smonth,"%s","december"); break;sprintf(str,"%s, %s %d,%d %d:%d:%d",sday,smonth,t.getday(),t.getyear(),t.gethour(),t.getminute(),t.getsecond(),t.getsecond();cstring today = str;ddx_text(pdx,idc_

37、edit1,today);#include <afxwin.h>#include "mydoc.h"#include "myframe.h"#include "myview.h"#include "myapp.h"#include "calender.h"#include "resource.h"myapp a ;bool myapp:initinstance( )cruntimeclass *d, *f, *v ;d = runtime_class ( mydo

38、c ) ;f = runtime_class ( myframe ) ;v = runtime_class ( myview ) ;csingledoctemplate *t ;t = new csingledoctemplate ( idr_menu1, d, f, v ) ;adddoctemplate ( t ) ;ccommandlineinfo c ;parsecommandline ( c ) ;if ( !processshellcommand ( c ) )return false ;return true;class myapp : public cwinapppublic

39、:bool initinstance( ) ; ;#include "resource.h"class mydialog:public cdialogpublic:mydialog(int n):cdialog(n)/*/;#include <afxwin.h>#include <afxdlgs.h>#include "mydoc.h"#include "mydialog.h"#include "yeardialog.h"#include "dialogtime.h"#i

40、nclude "resource.h"implement_dyncreate ( mydoc, cdocument ) begin_message_map(mydoc,cdocument)on_command_range(40005,40009,oncolor)on_command_range(40005,40010,ontodaybox)on_command(40011,restoredefault)on_command(40001,onprevious)on_command(40002,onnext)on_command(40003,oncurrent)on_comma

41、nd(40004,onshow)on_command(40012,onabout)end_message_map()void mydoc:oncolor(int id)ccolordialog cd;ccalender cal;if( cd.domodal() = idok )colorref crcolor = cd.getcolor();switch(id)case 40005:cal.setwindowcolor(crcolor);break;case 40006:cal.setmonthscolor(crcolor);break;case 40007:cal.setweekdaysco

42、lor(crcolor);break;case 40008:cal.setdayscolor(crcolor);break;case 40009:cal.settodaycolor(crcolor);break;case 40010:cal.settodaysboxcolor(crcolor);break;updateallviews(0);void mydoc:restoredefault()ccalender cal;cal.setwindowcolor(rgb(255,255,255);cal.setmonthscolor(rgb(0 ,0 ,255);cal.setweekdaysco

43、lor(rgb(0 ,255,0 );cal.setdayscolor(rgb(255,0 ,0 );cal.settodaycolor(rgb(255,0 ,0 );cal.settodaysboxcolor(rgb(255,255,255);updateallviews(0);void mydoc:onprevious()cal.setyear(cal.getyear()-1);updateallviews(0);void mydoc:onnext()cal.setyear(cal.getyear()+1);updateallviews(0);void mydoc:oncurrent()c

44、al.setyear(2003);updateallviews(0);void mydoc:onabout()mydialog d(idd_dialog1);d.domodal();void mydoc:onshow()yeardialog d(idd_dialog2);if( d.domodal() = idok )cal.setyear(d.getyear();updateallviews(0);void mydoc:ontodaybox()dialogtime d(idd_dialog3);d.domodal();#include"calender.h"class m

45、ydoc : public cdocumentdeclare_dyncreate ( mydoc ) private:ccalender cal;public:declare_message_map()void oncolor(int id);void restoredefault();void onprevious();void onnext();void oncurrent();void onshow();void onabout();void ontodaybox(); ;#include <afxwin.h>#include "myframe.h"imp

46、lement_dyncreate ( myframe, cframewnd )class myframe : public cframewnd declare_dyncreate ( myframe ) ;#include <afxwin.h>#include <afxdlgs.h>#include "mydoc.h"#include "myview.h"#include "resource.h"implement_dyncreate ( myview, cscrollview ) begin_message_

47、map ( myview, cscrollview )on_wm_create( )on_wm_size( )on_wm_erasebkgnd( )end_message_map( )bool myview:precreatewindow ( createstruct& cs )cs.style |= ws_clipchildren | ws_clipsiblings ;return cview:precreatewindow ( cs ) ;void myview:ondraw ( cdc *p )char str20;mydoc *pdoc = (mydoc*) getdocume

48、nt();cal.setyear(cal.getyear();cal.showday(p);cal.showcalender(p);cal.showmonth(p);sprintf(str,"calender %d",cal.getyear();pdoc->settitle(str);void myview:onsize(uint type,int cx,int cy)setscrollsizes(mm_text,csize(800,780);void myview:onerasebkgnd(cdc *pdc)crect r;cbrush mybrush;getclientrect(&r);mybrush.createsolidbrush(cal.getwindowcolor();pdc->selectobject(&mybrush);pdc-&

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论