#include<iostream>#include<iomanip>using namespace std;class Calendar{public:int weekday;int year;public://Calendar(){};void printmonthdays();void printtitle(int m);int monthdays(int n);int firstday(int year);};int Calendar::monthdays(int m){ switch(m) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if(((this->year%4==0&&this->year%100!=0)||this->year%400==0)) return 29; else return 28; default:return 0; }}void Calendar::printmonthdays(){ int days; for(int n=1;n<=12;n++) { printtitle(n); days=monthdays(n); for(int i=1;i<=days;i++) { cout<<setw(7)<<i; weekday=(weekday+1)%7;//星期 if(weekday==0) cout<<"\n"; } cout<<"\n"; }}void Calendar::printtitle(int m){ int i;? cout<<"\n"<<m<<"月 ?日 ? ? 一 ? ? 二 ? ? 三 ? ? 四 ? ? 五 ? ? 六 \n"; //cout<<" ";? for(i=0;i<weekday;i++) cout<<" ? ? ? ";}int Calendar::firstday(int year){ int a,b; a=year/100; b=year%100-1; return (b+(b/4)+(a/4)-2*a+(26*(13+1)/10))%7;}void main(int argc,char* argv[]){ int year; int weekday; Calendar cal; cout<<"請輸入你要查看的年份:"; cin>>year; weekday=cal.firstday(year); cout<<"\n\n"; cout<<" ? ? ? ? ? "<<year<<"年"; cal.printmonthdays(); cout<<"\n\n";}我找不到錯誤,麻煩幫我分析下,謝謝
- 1 回答
- 0 關注
- 1168 瀏覽
添加回答
舉報
0/150
提交
取消