2个回答
展开全部
这是我原来的代码,可运行,你看着改吧,C++写的。
#include"iostream"
#include"iomanip"
#include"windows.h"
using namespace std;
int tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
int y,m,d,leap;
class Calendar
{
public:
int Leap(int year);
int day_of_year(int y1,int m1,int d1);
int weekday(int yy,int mm,int dd);
int outyear();
int outhead();
int outmon(int month);
int outmonth(int moon);
};
Calendar::Leap(int year)
{
int t=0,i;
y=year;
for(i=1;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0)
t++;
}
return t;
}
Calendar::day_of_year(int y1,int m1,int d1)
{
int k;
leap=(y1%4==0&&y1%100!=0||y1%400==0);
for(k=1;k<m1;k++)
d1=d1+tab[leap][k];
return d1;
}
Calendar::weekday (int yy,int mm,int dd){
int leapyear,days;
leapyear=Leap(y);
days=y*365+leapyear+day_of_year (yy,mm,dd);
return (days+6)%7;
}
Calendar::outmonth(int moon)
{
int j,k;
outmon(moon);
outhead();
k=7*weekday(y,m,1);
cout<<setw(3)<<" "<<setw(k)<<" "<<setw(4)<<1;
for(j=2;j<=tab[leap][moon];j++){
if(!weekday(y,moon,j))cout<<endl;
cout<<setw(3)<<" ";cout<<setw(4)<<j;
}
cout<<endl<<endl;
return 0;
}
Calendar::outyear ()
{
int i,j,k;
for(i=1;i<=12;i++){
outmon(i);
outhead();
k=7*weekday(y,i,1);
cout<<setw(3)<<" "<<setw(k)<<" "<<setw(4)<<1;
for(j=2;j<=tab[leap][i];j++){
if(!weekday(y,i,j))cout<<endl;
cout<<setw(3)<<" ";cout<<setw(4)<<j;
}
cout<<endl<<endl;
}
return 0;
}
Calendar::outhead ()
{
cout<<setw(3)<<" "<<setw(4)<<"日"<<setw(3)<<" "<<setw(4)<<"一"<<setw(3)<<" "<<setw(4)<<"二"<<setw(3)<<" "<<setw(4)<<"三"<<setw(3)<<" "<<setw(4)<<"四"<<setw(3)<<" "<<setw(4)<<"五"<<setw(3)<<" "<<setw(4)<<"六"<<setw(3)<<" "<<endl;
return 0;
}
Calendar::outmon (int month)
{
switch(month){
case 1:cout<<setw(25)<<" "<<"一月\n\n";
break;
case 2:cout<<setw(25)<<" "<<"二月\n\n";
break;
case 3:cout<<setw(25)<<" "<<"三月\n\n";
break;
case 4:cout<<setw(25)<<" "<<"四月\n\n";
break;
case 5:cout<<setw(25)<<" "<<"五月\n\n";
break;
case 6:cout<<setw(25)<<" "<<"六月\n\n";
break;
case 7:cout<<setw(25)<<" "<<"七月\n\n";
break;
case 8:cout<<setw(25)<<" "<<"八月\n\n";
break;
case 9:cout<<setw(25)<<" "<<"九月\n\n";
break;
case 10:cout<<setw(25)<<" "<<"十月\n\n";
break;
case 11:cout<<setw(25)<<" "<<"十一月\n\n";
break;
case 12:cout<<setw(25)<<" "<<"十二月\n\n";
break;
}
return 0;
}
main()
{
void output();
Calendar cal;
int chioce;
while(1){
cout<<"功能:\n";
cout<<"1 查询特定年份年历\n2 查询特定月份月历\n0 退出\n";
cout<<"请选择功能:\n";
cin>>chioce;
system("cls");
if(chioce==0)break;
if(chioce!=0&&chioce!=1&&chioce!=2){
cout<<"没有这个选项,请重新选取:\n";
continue;
}
if(chioce==1){
cout<<"请输入您要查询的年份:\n";
cin>>y;
cal.outyear ();
cout<<"请选择功能:\n";
}
if(chioce==2){
cout<<"请输入要查询的年月(型如“2009 3”):\n";
cin>>y>>m;
cal.outmonth(m);
cout<<"请选择功能:\n";
}
}
}
#include"iostream"
#include"iomanip"
#include"windows.h"
using namespace std;
int tab[2][13]={
{0,31,28,31,30,31,30,31,31,30,31,30,31},
{0,31,29,31,30,31,30,31,31,30,31,30,31}
};
int y,m,d,leap;
class Calendar
{
public:
int Leap(int year);
int day_of_year(int y1,int m1,int d1);
int weekday(int yy,int mm,int dd);
int outyear();
int outhead();
int outmon(int month);
int outmonth(int moon);
};
Calendar::Leap(int year)
{
int t=0,i;
y=year;
for(i=1;i<year;i++){
if(i%4==0&&i%100!=0||i%400==0)
t++;
}
return t;
}
Calendar::day_of_year(int y1,int m1,int d1)
{
int k;
leap=(y1%4==0&&y1%100!=0||y1%400==0);
for(k=1;k<m1;k++)
d1=d1+tab[leap][k];
return d1;
}
Calendar::weekday (int yy,int mm,int dd){
int leapyear,days;
leapyear=Leap(y);
days=y*365+leapyear+day_of_year (yy,mm,dd);
return (days+6)%7;
}
Calendar::outmonth(int moon)
{
int j,k;
outmon(moon);
outhead();
k=7*weekday(y,m,1);
cout<<setw(3)<<" "<<setw(k)<<" "<<setw(4)<<1;
for(j=2;j<=tab[leap][moon];j++){
if(!weekday(y,moon,j))cout<<endl;
cout<<setw(3)<<" ";cout<<setw(4)<<j;
}
cout<<endl<<endl;
return 0;
}
Calendar::outyear ()
{
int i,j,k;
for(i=1;i<=12;i++){
outmon(i);
outhead();
k=7*weekday(y,i,1);
cout<<setw(3)<<" "<<setw(k)<<" "<<setw(4)<<1;
for(j=2;j<=tab[leap][i];j++){
if(!weekday(y,i,j))cout<<endl;
cout<<setw(3)<<" ";cout<<setw(4)<<j;
}
cout<<endl<<endl;
}
return 0;
}
Calendar::outhead ()
{
cout<<setw(3)<<" "<<setw(4)<<"日"<<setw(3)<<" "<<setw(4)<<"一"<<setw(3)<<" "<<setw(4)<<"二"<<setw(3)<<" "<<setw(4)<<"三"<<setw(3)<<" "<<setw(4)<<"四"<<setw(3)<<" "<<setw(4)<<"五"<<setw(3)<<" "<<setw(4)<<"六"<<setw(3)<<" "<<endl;
return 0;
}
Calendar::outmon (int month)
{
switch(month){
case 1:cout<<setw(25)<<" "<<"一月\n\n";
break;
case 2:cout<<setw(25)<<" "<<"二月\n\n";
break;
case 3:cout<<setw(25)<<" "<<"三月\n\n";
break;
case 4:cout<<setw(25)<<" "<<"四月\n\n";
break;
case 5:cout<<setw(25)<<" "<<"五月\n\n";
break;
case 6:cout<<setw(25)<<" "<<"六月\n\n";
break;
case 7:cout<<setw(25)<<" "<<"七月\n\n";
break;
case 8:cout<<setw(25)<<" "<<"八月\n\n";
break;
case 9:cout<<setw(25)<<" "<<"九月\n\n";
break;
case 10:cout<<setw(25)<<" "<<"十月\n\n";
break;
case 11:cout<<setw(25)<<" "<<"十一月\n\n";
break;
case 12:cout<<setw(25)<<" "<<"十二月\n\n";
break;
}
return 0;
}
main()
{
void output();
Calendar cal;
int chioce;
while(1){
cout<<"功能:\n";
cout<<"1 查询特定年份年历\n2 查询特定月份月历\n0 退出\n";
cout<<"请选择功能:\n";
cin>>chioce;
system("cls");
if(chioce==0)break;
if(chioce!=0&&chioce!=1&&chioce!=2){
cout<<"没有这个选项,请重新选取:\n";
continue;
}
if(chioce==1){
cout<<"请输入您要查询的年份:\n";
cin>>y;
cal.outyear ();
cout<<"请选择功能:\n";
}
if(chioce==2){
cout<<"请输入要查询的年月(型如“2009 3”):\n";
cin>>y>>m;
cal.outmonth(m);
cout<<"请选择功能:\n";
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询