设计Weekday类 代码参考

0
11
 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 class Weekday
 6 {
 7     private:
 8         int num;
 9     public:
10         void SetDay(){cin>>num;return;}
11         void IncDay(){num+=1;if(num>6) num-=7;return;}
12         void NowDay()
13         {
14             switch(num)
15             {
16                 case 0:cout<<"星期日"<<endl;break;
17                 case 1:cout<<"星期一"<<endl;break;
18                 case 2:cout<<"星期二"<<endl;break;
19                 case 3:cout<<"星期三"<<endl;break;
20                 case 4:cout<<"星期四"<<endl;break;
21                 case 5:cout<<"星期五"<<endl;break;
22                 case 6:cout<<"星期六"<<endl;break;
23                 default:break;
24             }
25         }
26 };
27 
28 int main()
29 {
30     Weekday one;
31     one.SetDay();
32     one.NowDay();
33     one.IncDay();
34     one.NowDay();
35     one.IncDay();
36     one.NowDay();
37     return 0;
38 }

<

发布回复

请输入评论!
请输入你的名字