한국어< 中文 فارسی English ไทย All Copyright Reserved 2010-2011 SDUSTOJ TEAM GPL2.0 2003-2011 HUSTOJ Project TEAM Anything about the Problems, Please Contact Admin:admin
#include <iostream> #include <iomanip> using namespace std; class Time { private: int h,m,s; static int num; public: Time():h(0),m(0),s(0){num++;} Time(int hh,int mm,int ss) : h(hh),m(mm),s(ss){num++;} Time(const Time &t) { h = t.h;m = t.m;s = t.s;num++; cout << "There was a call to the copy constructor : " << h << "," << m << "," << s << endl; } public: void hour(int hh){ h = hh;} void minute(int mm){ m = mm;} void second(int ss ){ s = ss;} public: int hour()const{return h;} int minute()const{return m;} int second()const{return s;} public: Time &setTime(int hh ,int mm ,int ss) { h = hh;m = mm;s = ss; return* this; } Time &setTime(const Time & t) { h = t.hour(); m = t.minute(); s = t.second(); return *this; } const Time &getTime()const { return *this;//passing 'const Time' as 'this' argument of 'const Time& Time::getTime()' discards qualifiers [-fpermissive]| } public: void showTime() const { if(h >= 0&& h<24 && m >=0 && m < 60 && s >= 0 && s < 60){ cout << setw(2) << setfill('0'); cout << setw(2) << h << ":"; cout << setw(2) << m << ":"; cout << setw(2) << s << endl; } else cout << "Time error" << endl; } public: static int getNumber() { return num;} static void displayNumber() { cout << "Now, There is " << num << " object of Time." <<endl;} }; int Time::num = 0; int main() { cout<<"Static member test output :"<<endl; Time::displayNumber(); Time t; t.displayNumber(); Time tt(t); tt.displayNumber(); Time ttt(1, 2, 3); ttt.displayNumber(); Time tttt(ttt.getTime()); tttt.displayNumber(); int non_cases = Time::getNumber(); cout<<"\nTest data output :"<<endl; int hour, minute, second; while(cin>>hour>>minute>>second) { Time t; t.setTime(hour, minute, second).showTime(); } cout<<t.getNumber() - non_cases<<endl; }