开始学习C++,这是临时想到的一个程序,还不适应C++的风格
1 #include <iostream>
2 using namespace std;
3 class ruinian{
4 public:
5 int y;
6 int y_in(){
7 cin >> y;
8 return y;
9 }
10 int y_out(){
11 if (this->ck()){
12 cout << this->y << "年是闰年!" <<endl;
13 }else{
14 cout << this->y << "年不是闰年!" <<endl;
15 }
16 return 0;
17 }
18 bool ck(){
19 bool a=false;
20 if (y%2==0 && y%100 !=0){
21 a=true;
22 }
23 if (y%100==0 && y%400 ==0){
24 a=true;
25 }
26 return a;
27 }
28 };
29
30 int main()
31 {
32 ruinian year;
33 cout << "请输入年份:" ;
34 year.y_in ();
35 year.y_out();
36 }
37
|
阅读(2249) | 评论(0) | 转发(0) |