亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

急!關于c++編日歷的問題,大佬幫忙看看

急!關于c++編日歷的問題,大佬幫忙看看

C++
逝月兮 2017-06-22 19:09:21
#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 回答

已采納
?
MR帽子先生

TA貢獻245條經驗 獲得超106個贊

switch(m)錯了,括號里面內容應該轉為int類型不然是str類型的。

希望對你有幫助,祝您學習愉快,有幫助的話請采納我的答案。

查看完整回答
反對 回復 2017-06-24
  • 逝月兮
    逝月兮
    請問具體怎么改呢
  • MR帽子先生
    MR帽子先生
    switch(int m) 直接轉換為int類型就可以了。祝你學習順利。
  • 逝月兮
    逝月兮
    抱歉,這幾天考試,沒來得及回復你。這樣改不對哦,需要在firstday(int year)函數這里,改為int Calendar::firstday(int year_input) { year=year_input; …… 但我不知道這是什么意思,in_put是啥啊
點擊展開后面2
  • 1 回答
  • 0 關注
  • 1168 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號