2-31
声明一-个表示时间的结构体,可以精确表示年、月、日﹑小时、分、秒;提示用户输人年、月、日、小时、分、秒的值,然后完整地显示出来。
1 #include<iostream> 2 using namespace std; 3 4 struct Time{ 5 int y,mon,day,h,min,s; 6 void timeshow(){ 7 cout<<y<<"年"<<mon<<"月"<<day<<"日"<<h<<":"<<min<<":"<<s<<endl; 8 } 9 }; 10 int main(){ 11 Time t; 12 cout<<"请输入年、月、日、小时、分、秒"<<endl; 13 cin>>t.y>>t.mon>>t.day>>t.h>>t.min>>t.s; 14 t.timeshow(); 15 return 0; 16 }

浙公网安备 33010602011771号