I have to Add to the Time class the conversion function for converting from a long (seconds 77777) to a Time object....I have no idea what to do...this is the code I have so far....
Code:class Time { private: int hrs; //1 to 23 int mins; //0 to 59 int secs; //0 to 59 public: //no-arg constructor Time() : hrs(0), mins(0), secs(0) { } //3-arg constructor Time(int h, int m, int s) : hrs(h), mins(m), secs(s) { } void display() const //format: 11:59 p.m. { cout << hrs << ':' << mins << ':' << secs; } Time operator ++ () // increment prefix { return Time (++hrs, ++ mins, ++ secs);} Time operator ++ (int) // increment postfix { return Time (hrs++, mins++, secs++);} Time operator -- () //prefix {return Time (--hrs, --mins, --secs);} Time operator -- (int) //postfix {return Time (hrs--, mins--, secs--);} }; //////////////////////////////////////////////////////////////// void main(void) { int h, m, s; long time; cout << "Enter 24-hour time: \n"; cout << " Hours (0 to 23): "; cin >> h; cout << " Minutes: "; cin >> m; cout << " Seconds: "; cin >> s; Time t(h, m, s); //make a time object t cout << "You entered: "; //display the t t.display(); } I think i need a conversion operator ... but not to sure how to go about it....plz help.....thx



LinkBack URL
About LinkBacks



