您的位置:首页 > 其它

第一次作业

2017-03-15 16:48 169 查看
#include<iostream>

using namespace std;

#define Firstyear 2010     //初始年份

int yearCount(int year) {   //测算距初始年份的天数
int Count = 0;
for (int i = Firstyear;i < year;i++) {
if (i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {  //判定闰年
Count += 366;
}
else {
Count += 365;
}
}
return Count;

}

int monthCount(int year, int month) {
int Count = 0;
for (int i = 1;i < month;i++) {
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
Count += 31;
}
else if(i==2)
{

            if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {  //判定闰年,确定是否有闰月
Count += 29;
}
else
{
Count += 28;
}
}
else
{
Count += 30;
}
}
return Count;

}

int Judge(int year,int month,int day) {
if (year < 2010) {
return 0;
}
int i = month;
if (i < 1 || i>12) {
return 0;
}
if (day > 31 || day < 1) {
return 0;
}
if (i == 2)
{
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {  //判定非闰年闰年,确定闰月。推出日期是否恰当
if (day > 29) {
return 0;
}
}
else {
if (day > 28) {
return 0;
}
}
}
else if(i==4||i==6||i==9||i==11)
{
if (day > 30) {
return 0;
}
}
return 1;

}

void console() {
int year, month, day;
int days = 0;
cout << "请依次输入年月日(用空格隔开)" << endl;
cin >> year >> month >> day;
int a = Judge(year, month, day);
if (a == 0) {
cout << "输入了错误的日期形式,请重新输入" << endl;
console();
}
days = yearCount(year) + monthCount(year, month) + days;
if (days % 5 == 0 || days % 5 == 4) {
cout << "在晒网" << endl;
}
else
{
cout << "在打渔" << endl;
}
console();

}

void main()

{
console();
}

以上为此次作业代码

设计思路图如下

作业总结:本来这次还想试试文件操作,但因对c++了解的还是太过浅显,因此只能作罢。以后要是有时间的话,应该还会再试着完善。深刻的心得说有的话就是自己懂得还是太少了,还是应当多多学习。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vr