c++电子日历

2020-05-03 17:43

项目一 电子日历

一、

设计要求

设计并实现如下功能:

1、 设置日期。日期由键盘上输入。 2、 用日/月/年格式输出日期

3、 在输入日期合法的情况下可实现日期增加一天的操作

二、

设计思想 1、 类的结构图

2、 程序主要功能说明

功能:输入一个年,月,日。在合法的情况下,打印出日,月,年。并且再有选择的情况下,输出后一天的日期。

Date - year:int - month:int - day:int 三、

源代码

#include #include class date{ private: int year; int month; int day; public:

void show() {

cout<<\请输入年份:\ cin>>year;

cout<<\请输入月份 \cin>>month;

while(month>12||month<=0) { }

cout<<\请输入日数\cin>>day;

cout<<\输入错误请重新输入\cin>>month;

} }

int day1; while(1) {

switch(month) {

case 1:case 3:case 5:case 7:case 8:case 10:case 12:day1=31;break; case 4:case 6:case 9:case 11:day1=30;break;

case 2:if(year%4==0&&year0!=0||year@0==0)day1=29; }

else day1=28; break;

if(day>day1||day<=0) }

else break;

{

cout<<\输入错误请重新输入\cin>>day;

}

void shuchu() {

cout<

void nextday()

{

char t; int day2;

}

else day+=1; if(month==13) { month=1; year=year+1; }

cin>>t; if(t=='y'||t=='Y') {

switch(month) {

case 1:case 3:case 5:case 7:case 8:case 10:case 12:day2=31;break; }

if(day==day2) {

day=1;

case 4:case 6:case 9:case 11:day2=30;break;

case 2:if(year%4==0&&year0!=0||year@0==0) day2=29;

else day2=28; break;

month=month+1;

}

if(t=='n'||t=='N') { exit(0); }

} };

int main() { date today; today.show();

today.shuchu();

cout<<\后一天的日期请按:y today.nextday(); today.shuchu();

return 0;

}

四、 测试结果

\结束请按:n \


c++电子日历.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:污水处理厂曝气沉砂池操作规程

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: