毕业论文万年历的设计
*******************
实践教学
*******************
兰州理工大学
计算机与通信学院
2014年秋季学期
面向对象 课程设计
题 目: 万年历的设计 专业班级: 姓 名: 学 号: 指导教师:
成 绩:
序言
《面向对象的程序设计》是计算机专业一门重要的专业基础课。此次课程设计的目的是以面向对象程序设计语言为基础,通过完成一些具有一定难度的课程设计题目的编写、调试、运行工作,进一步掌握面向过程和面向对象程序设计的基本方法和编程技巧,巩固所学理论知识,使理论与实际相结合。从而提高自我分析问题、解决问题的能力。通过课程设计,学生在下述各方面的能力应该得到锻炼:
(1)进一步巩固、加深学生所学专业课程《C++语言程序设计》的基本理论知识,理论联系实际,进一步培养学生综合分析问题、解决问题的能力。
(2)全面考核学生所掌握的基本理论知识及其实际业务能力,从而达到提高学生素质的最终目的。
(3)利用所学知识,开发小型应用系统,掌握运用C++语言编写调试应用系统程序,训练独立开发应用系统,进行数据处理的综合能力。
(4)对于给定的设计题目,如何进行分析,理清思路,并给出相应的数学模型。
(5)掌握面向对象的程序设计方法。
(6)进一步掌握在集成环境下如何调试程序、修改程序和程序的测试。
目录
摘 要.................................................................................................................... 2 第一章 系统总体设计........................................................................................ 3
一.理论说明................................................................................................ 3 二.流程图说明............................................................................................ 4
1.总体流程说明图.............................................................................. 4 2.部分流程说明图.............................................................................. 4
第二章 系统详细设计...................................................................................... 7
一. 主要组成部分...................................................................................... 7 二. 源程序.................................................................................................. 9 第三章 系统测试............................................................................................ 34 四 软件使用说明书............................................................................................ 40
一.系统运行环境...................................................................................... 40 二.系统操作提示...................................................................................... 40 总 结.................................................................................................................. 41 参考文献.............................................................................................................. 42 致谢...................................................................................................................... 42
摘 要
万年历作为日常中的小工具,具有多方面的功能,能有效帮助人们记录以及计算时间,在极大程度上帮助人们在日期以及时间方面有最直观的体现。
该设计通过C++的基本知识和技能设计出一个万年历程序,该程序需实现 时间和日期的显示以及计算。
一.实现提供时、分、秒组成的时间,并提供时间增加的方法(按秒); 二.实现记录年、月、日的过程,并提供日期增加的方法(按天); 三.通过上述两项,设计出除除具有年、月、日、时、分、秒外,还增加国名和与格林威治时间的差;
四. 输入年、月、日、时、分、秒,在屏幕上模拟显示一电子计时器,不断输出下一秒的时间和日期,以及格林威治的日期和时间。
该设计不仅体现了普通日历的功能,还加入了电子计时器的部分,使得万年历在原本的基础上有了更大的扩充。
关键字:时间,日期,格林威治时间差,电子计时器
第一章 系统总体设计
一.理论说明
关于万年历的基本要求,须体现时间,日期等,所以,定义时间类time,日期类date,完成关于年(year),月(month),日(day),时( minute;};
int getsecond(){return second;}返回时分秒的值;
成员函数
void sethour(int nhour){ minute;}; int getsecond(){return second;}; void sethour(int nhour){ year;};
int getmonth(){return month;}; int getday(){return day;};
string getweek(){ return week;};主要功能为返回年月日的值,实现方式为:调用成员函数
成员函数
void setyear(int nyear){year=nyear;}; void setmonth(int nmonth){month=nmonth;}; void setday(int nday){day=nday;};
void setweek(string c){week=c;};主要功能为给私有数据成员赋值,实现方式为通过调用析构函数实现。
类datetime公开继承类time和类date的属性,实现电子时钟的功能,完成时间由秒自增的过程。
定义函数week(),以及situation(),完成日期对应星期数以及时间差的计算过程,完善电子时钟以及万年历的功能。
2. 源程序
#include
bool isleapyear(int year)判断是否是闰年 { }
int mon_day(int year ,int month)判断月份对应的天数 {
if (isleapyear(year)&&month==2) { }
else return mon[month]; }
int getyearday(int year)返回一年天数 { } class time { private:
if(isleapyear(year))
return 366; return 29;
return (year%4==0 && year0!=0)||(year@0==0);
else return 365;
int minute;};
int getsecond(){return second;}; void sethour(int nhour){ year;}; int getmonth(){return month;};
int getday(){return day;};
string getweek(){ return week;}; void setyear(int nyear){year=nyear;}; void setmonth(int nmonth){month=nmonth;}; void setday(int nday){day=nday;}; void setweek(string c){week=c;};
void reset(int y=0,int m=0,int d=0); };
class datetime:public date,public time {
private:
public: datetime();
datetime(int nyear,int nmonth,int nday,int nhour,int nminute,int date operator +(const date &t); date operator -(const date &t);
nsecond);
datetime(int nyear,int nmonth,int nday,time & c); datetime(date & t,int nhour,int nminute,int nsecond);
datetime addbysecond(); datetime operator=(datetime & t); };
time::time()判断时间并进行赋值
datetime operator+(datetime & t);
{ }
if(d>maxday || d<=0) { d=1; } day=d; }
date::date(date & t) { }
date::~date(){};
void date::reset (int y,int m,int d) { }
datetime::datetime():date(),time(){};
datetime::datetime(int nyear,int nmonth,int nday,int nhour,int this->year =y; this->month =m; this->day =d; year=t.year ; month=t.year; day=t.day; [m];
nminute,int nsecond):date(nyear,nmonth,nday),time(nhour,nminute,nsecond)
{}
nyear,int
nmonth,int
nday,time
&
datetime::datetime(int
c):time(c),date(nyear,nmonth,nday)
{}
&
t,int
nhour,int
nminute,int
datetime::datetime(date
nsecond):date(t),time(nhour,nminute,nsecond)
{}
datetime datetime::addbysecond()
{
this->setsecond(this->getsecond()+1);
if(this->getsecond()>59)
{
this->setsecond(0);
this->setminute(this->getminute()+1); if(this->getminute()>59)
{
this->setminute(0);
this->sethour(this->gethour()+1); if(this->gethour()>23) {
this->sethour(0);
this->setday(this->getday()+1);
if(this->getday()>mon_day( this->getyear() ,this->getmonth()))
{
this->setday(1);
this->setmonth(this->getmonth()+1); if(this->getmonth() >12) {
this->setmonth(1);
this->setyear(this->getyear()+1);
}
}
} } }
return *this; }
datetime datetime::operator=(datetime & t) {
this->setyear(t.getyear());
this->setmonth(t.getmonth()); }
datetime datetime::operator+(datetime & t) {
if((this->getyear()+t.getyear())<1900) {
this->setyear(1900); }
else this->setyear((this->getyear()+t.getyear()));
if((this->getmonth()+t.getmonth())>12 || (this->getmonth()+t.getmonth())<=0) {
this->setmonth(1); }
this->setday(t.getday()); this->sethour(t.gethour()); this->setminute(t.getminute()); this->setsecond(t.getsecond()); return *this;
else this->setmonth((this->getmonth()+t.getmonth())); int maxday=0;
if((this->getyear()+t.getyear())==2) {
if(isleapyear((this->getyear()+t.getyear()))) {
maxday=29; } else {
maxday=28; } } else {
maxday=mon[this->getmonth()+t.getmonth()]; }
if((this->getday()+t.getday())>maxday ||(this->getday()+t.getday())<=0) {
this->setday(1); }
this->setday((this->getday()+t.getday())); return *this; }
int dayinyear(datetime & t)日期在年中的天数 {
int i=0,day=0;
for(i=1;i { day+=mon_day(t.getyear(),i); } void getweek( datetime &t)判断天数对应星期 { int week=0; int diffday; } day+=t.getday(); return day; if(t.getyear()==1900) { if(t.getmonth()==1) { diffday=t.getday()-1; } else { diffday=dayinyear(t)-1; } } else { int d1=getyearday(1900)-1; int d2=dayinyear(t); int d3=0; int year=0; for(year=1901;year d3+=getyearday(year); } } diffday=d1+d2+d3; week=diffday%7; switch(week) { case 0: t.setweek(\星期一\ case 1: t.setweek(\星期二\ case 2: t.setweek(\星期三\ case 3: t.setweek(\星期四\ case 4: t.setweek(\星期五\ case 5: t.setweek(\星期六\ case 6: } cout< } int getmonthfirst(datetime & t)返回对应月的第一天星期数 { datetime temp(t.getyear(),t.getmonth(),1,t.gethour(),t.getminute(),t.getsecond()); getweek( temp);判断对应星期数 if(temp.getweek()==\星期一\ } void showmonth(datetime & t)打印当前月日历 { int i=0; cout<<\ \ \ return 1; else if(temp.getweek()==\星期二\ return 2; else if(temp.getweek()==\星期三\ return 3; else if(temp.getweek()==\星期四\ return 4; else if(temp.getweek()==\星期五\ return 5; else if(temp.getweek()==\星期六\ return 6; else return 7; \ \ \ \ int j=0; int k=1; int num=getmonthfirst(t); cout<<\ \ for(k=1;k<=8-num;k++) cout< cout< for(i=k;i<=mon_day(t.getyear(),t.getmonth());i++) { int flag=1; int first=k; if(i<10) { cout<<\ \ } else cout< { cout< } } k=i+1; } void stuation1(datetime & t)计算两日期相差天数 { int nyear=0;int nmonth=0;int nday=0; int nhour=0;int nminute=0;int nsecond; cout<<\请输入 年 月 日:\cin>>nyear>>nmonth>>nday; cout<<\请输入 时 分 秒:\ cin>>nhour>>nminute>>nsecond; datetime temp ( nyear, nmonth,nday, nhour, nminute,nsecond); int diffday=0; if(t.getyear()==nyear) { if(t.getmonth()==nmonth) { diffday=abs(t.getday()-nday); } else { diffday=abs(dayinyear(t)-dayinyear(temp)); } } else if(nyear int d1=getyearday(temp.getyear())-dayinyear(temp); int d2=dayinyear(t); int d3=0; int year=0; for(year=nyear;year d3+=getyearday(year); diffday=d1+d2+d3; } else { int d1=getyearday(t.getyear())-dayinyear(t); int d2=dayinyear(temp); int d3=0; int year=0; for(year=t.getyear();year d3+=getyearday(year); diffday=d1+d2+d3; } int monthsurplus(datetime & t)当月剩余天数 { return mon_day(t.getyear(),t.getmonth())-t.getday(); } cout<<\与原日期相隔的天数为:\ } int yearsurplus(datetime & t)当年剩余天数 { return getyearday(t.getyear())-dayinyear(t); } void stuation2(datetime & t ) { int diffday=0; int lastday=0; int lastmonth=0; int lastyear=0; cout<<\请输入相隔的天数:\ cin>>diffday; if(diffday>0) { if(diffday<=monthsurplus(t))月未变 { lastday=diffday+t.getday(); lastmonth=t.getmonth(); lastyear=t.getyear(); } else if(diffday<=yearsurplus(t))年未变 { lastyear=t.getyear(); int k=1; int i=monthsurplus(t); while(i { i+=(mon_day(t.getyear(),t.getmonth()+k)); k++; } lastmonth=t.getmonth()+k-1; int _day(t.getyear(),_day(lastyear,j); j++; } lastmonth=j-1; int total=0; int j1=1; for(;j1 { total+=mon_day(lastyear,j1); } lastday=surplusday-total; } } elsediffday<0 { if (abs(diffday) { lastday=t.getday(); lastmonth=t.getmonth(); lastyear=t.getyear(); } else if(abs(diffday)<=dayinyear(t)) { lastyear=t.getyear(); int j=0,total=0; int k=t.getmonth(); int i=t.getday(); while(i { i+=mon_day(t.getyear(),k-1); k--; } lastmonth=k; for(j=t.getmonth();j>=(lastmonth+1);j--) { total+=mon_day(t.getyear(),j); } lastday=diffday-total; } else { int i=dayinyear(t); int k=t.getyear(); while(i i+=getyearday(k-1); k--; } lastyear=k; int mtotal=0; int j=0; for(j=t.getyear();j>=lastyear+1;j--) { mtotal+=getyearday(j); } int nday=abs(diffday)-mtotal; int _day(lastyear,12-flag); flag--; } lastmonth=flag; int dtotal=0; for(m=12;m>=lastmonth+1;m--) { dtotal+=mon_day(lastyear,m); } lastday=nday-dtotal; } } cout<<\日期为:\ cout< } void Tprojection(datetime & sytime) { int option=0; cout<<\ 您已进入万年历系统 \ cout<<\您已进入日期推算菜单 \ cout<<\ 1.计算两日期相差天数 \ cout<<\ 2.计算日期前后推算 \ cout<<\请选择:\”1或2:”; cin>>option; system(\清屏 switch(option) { case 1: stuation1(sytime);计算两日期相差天数 break; case 2: stuation2(sytime);计算日期前后推算 break;
推荐访问:电子万年历毕业设计
单片机万年历设计