编写一个c++程序,要求输入年份月份,并且输入该月的1号为周几,输出该月的日历 5
2个回答
展开全部
#include <iostream>
class Calendar {
public:
enum Week
{
Monday=1,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday
};
enum Month {
January=1,
February,
March,
April,
May,
June,
July,
August,
September,
October,
November,
December
};
int year;
Month month;
Week week;
bool isLeapYear()const{
return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ;
}
/*初始化*/
Calendar(int year_, Month month_,Week week_):
year(year_),month(month_),week(week_){
}
void print() const{
//获得月份时间
int month_size = day_[month];
if (month==Month::February) {
if (isLeapYear()) {
month_size = 29;
}
}
int week_ = int(week);
//
std::cout << "year:" << year <<std::endl;
std::cout << "month:" << int(month) << std::endl;
for (auto ii = 0; ii < month_size;++ii) {
std::cout << "day:" << (ii+1)<<"is:";
std::cout << week_;
std::cout << std::endl;
++week_;
if (week_>Sunday) {
week_ = int(Monday);
}
}
}
private:
const static int day_[13] ;
};
// 0 1 2 3 4 5 6 7 8 9 10 11 12
const int Calendar::day_[13]{-1,31,28,31,30,31,30,31,31,30,31,30,31};
int main() {
Calendar c(200, Calendar::Month::April,Calendar::Week::Friday);
c.print();
#ifdef _MSC_VER
system("pause");
#endif
}
展开全部
#include<iostream>
#include<stdio.h>
using namespace std;int main(){
int year; int month; int monthcodearr[12]={1,4,4,7,2,5,7,3,6,1,4,6};
char week[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int day;
printf("input the date(YYYY-MM-DD)\n");
scanf("%d-%d-%d",&year,&month,&day); //这里主要是格式化输入。2011-6-20要按照这个格式输入。
int yearcode;
int monthcode;
if(year > 2000) {
yearcode = 4-2*((year-2000)/4)+(year-2000)%4+1; }
else if(year == 2000) {
yearcode = 4;
}
else {
yearcode = 4+2*(2000-year)/4-(2000-year)%4;
}
monthcode = monthcodearr[month-1];
int weekcode = (yearcode+monthcode+day)%7;
cout<<yearcode<<endl;
cout<<monthcode<<endl;
cout<<day<<endl;
cout<<weekcode<<endl;
cout<<week[weekcode]<<endl;
}
#include<stdio.h>
using namespace std;int main(){
int year; int month; int monthcodearr[12]={1,4,4,7,2,5,7,3,6,1,4,6};
char week[7][10]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
int day;
printf("input the date(YYYY-MM-DD)\n");
scanf("%d-%d-%d",&year,&month,&day); //这里主要是格式化输入。2011-6-20要按照这个格式输入。
int yearcode;
int monthcode;
if(year > 2000) {
yearcode = 4-2*((year-2000)/4)+(year-2000)%4+1; }
else if(year == 2000) {
yearcode = 4;
}
else {
yearcode = 4+2*(2000-year)/4-(2000-year)%4;
}
monthcode = monthcodearr[month-1];
int weekcode = (yearcode+monthcode+day)%7;
cout<<yearcode<<endl;
cout<<monthcode<<endl;
cout<<day<<endl;
cout<<weekcode<<endl;
cout<<week[weekcode]<<endl;
}
追问
是c++程序不是c语言哦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询