
一道C++日历题,哪位大哥帮我做一下啊~急!!!! 有加分
Writeaprogramthatprintsacalendarforayear.PrompttheuserforwhichdayoftheweekJanuary1iso...
Write a program that prints a calendar for a year. Prompt the user for which day of the week
January 1 is on and whether the year is a leap year. The day that January 1 is on is coded as
follows:
Sun 1
Mon 2
Tue 3
Wed 4
Thu 5
Fri 6
Sat 7
-----------------
Sample Output:
Enter the day for Jan 1:
[1 - Su, 2 - Mo, 3 - Tu, 4 - We, 5 - Th, 6 - Fr, 7 - Sa] : 5
Is this a leap year: [0 - No, 1 - Yes] : 1
January
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
(以此类推) 展开
January 1 is on and whether the year is a leap year. The day that January 1 is on is coded as
follows:
Sun 1
Mon 2
Tue 3
Wed 4
Thu 5
Fri 6
Sat 7
-----------------
Sample Output:
Enter the day for Jan 1:
[1 - Su, 2 - Mo, 3 - Tu, 4 - We, 5 - Th, 6 - Fr, 7 - Sa] : 5
Is this a leap year: [0 - No, 1 - Yes] : 1
January
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
(以此类推) 展开
1个回答
展开全部
//********************************************************
//日历
//********************************************************
#include <iostream>
using namespace std;
class calendar{
bool leap;
bool ready;
public:
int startm[13];
int days[13];
string mname[13];
void init(int week_s,bool leep_s);
void printmonth(int month_s);
};
void calendar::init(int week_s,bool leap_s){
days[0]=0; days[1]=31; days[2]=28; days[3]=31;
days[4]=30; days[5]=31; days[6]=30; days[7]=31;
days[8]=31; days[9]=30; days[10]=31; days[11]=30;
days[12]=31;
mname[0]=""; mname[1]="January"; mname[2]="February";
mname[3]="March"; mname[4]="Apri"; mname[5]="May";
mname[6]="June"; mname[7]="July"; mname[8]="August";
mname[9]="September"; mname[10]="October"; mname[11]="November";
mname[12]="December";
leap = false;
if(leap_s){
days[2]=29;
leap = true;
}
startm[1]=week_s;
for(int i=2;i<13;i++){
startm[i]=(days[i-1]+startm[i-1]-1)%7+1;
}
ready = true;
}
void calendar::printmonth(int month_s){
if(ready){
printf("\t\t\t%s\n",mname[month_s].c_str());
printf("Su\tMo\tTu\tWe\tTh\tFr\tSa\n");
int countt=0;
int countd=1;
for(int i=1;i<startm[month_s];i++){
printf("\t");
countt++;
}
do{
if(countt%7==0&&countt)
printf("\n");
printf("%d\t",countd);
countd++;
countt++;
}while(countd<=days[month_s]);
}
else
printf("The data is not ready.\n");
}
void main(){
int week;
int leap;
calendar obj;
printf("Enter the day for Jan 1:\n[1 - Su, 2 - Mo, 3 - Tu, 4 - We, 5 - Th, 6 - Fr, 7 - Sa] :");
scanf("%d",&week);
printf("Is this a leap year: [0 - No, 1 - Yes] :");
scanf("%d",&leap);
fflush(stdin);
obj.init(week,(bool)leap);
for(int i =1;i<13;i++){
obj.printmonth(i);
getchar();
fflush(stdin);
}
}
//日历
//********************************************************
#include <iostream>
using namespace std;
class calendar{
bool leap;
bool ready;
public:
int startm[13];
int days[13];
string mname[13];
void init(int week_s,bool leep_s);
void printmonth(int month_s);
};
void calendar::init(int week_s,bool leap_s){
days[0]=0; days[1]=31; days[2]=28; days[3]=31;
days[4]=30; days[5]=31; days[6]=30; days[7]=31;
days[8]=31; days[9]=30; days[10]=31; days[11]=30;
days[12]=31;
mname[0]=""; mname[1]="January"; mname[2]="February";
mname[3]="March"; mname[4]="Apri"; mname[5]="May";
mname[6]="June"; mname[7]="July"; mname[8]="August";
mname[9]="September"; mname[10]="October"; mname[11]="November";
mname[12]="December";
leap = false;
if(leap_s){
days[2]=29;
leap = true;
}
startm[1]=week_s;
for(int i=2;i<13;i++){
startm[i]=(days[i-1]+startm[i-1]-1)%7+1;
}
ready = true;
}
void calendar::printmonth(int month_s){
if(ready){
printf("\t\t\t%s\n",mname[month_s].c_str());
printf("Su\tMo\tTu\tWe\tTh\tFr\tSa\n");
int countt=0;
int countd=1;
for(int i=1;i<startm[month_s];i++){
printf("\t");
countt++;
}
do{
if(countt%7==0&&countt)
printf("\n");
printf("%d\t",countd);
countd++;
countt++;
}while(countd<=days[month_s]);
}
else
printf("The data is not ready.\n");
}
void main(){
int week;
int leap;
calendar obj;
printf("Enter the day for Jan 1:\n[1 - Su, 2 - Mo, 3 - Tu, 4 - We, 5 - Th, 6 - Fr, 7 - Sa] :");
scanf("%d",&week);
printf("Is this a leap year: [0 - No, 1 - Yes] :");
scanf("%d",&leap);
fflush(stdin);
obj.init(week,(bool)leap);
for(int i =1;i<13;i++){
obj.printmonth(i);
getchar();
fflush(stdin);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询