看板 PCCU-CS 關於我們 聯絡資訊
#include <iostream> using std::cout; #include "time6.h" // Constructor function to initialize private data. // Calls member function setTime to set variables. // Default values are 0 (see class definition). Time::Time( int hr, int min, int sec ) { setTime( hr, min, sec ); } // Set the values of hour, minute, and second. Time &Time::setTime( int h, int m, int s ) { setHour( h ); setMinute( m ); setSecond( s ); return *this; // enables cascading } // end function setTime // Set the hour value Time &Time::setHour( int h ) { second = (( h >= 0 && h < 24 ) ? h : 0)*3600; return *this; // enables cascading } // end function setHour // Set the minute value Time &Time::setMinute( int m ) { second += (( m >= 0 && m < 60 ) ? m : 0)*60; return *this; // enables cascading } // end function setMinute // Set the second value Time &Time::setSecond( int s ) { second += ( s >= 0 && s < 60 ) ? s : 0; return *this; // enables cascading } // end function setSecond // Get the hour value int Time::getHour() const { return (second/3600); } // Get the minute value int Time::getMinute() const { return (second%3600/60); } // Get the second value int Time::getSecond() const { return (second%60); } // Display military format time: HH:MM void Time::printMilitary() const { cout << ( getHour() < 10 ? "0" : "" ) << getHour() << ":" << ( getMinute() < 10 ? "0" : "" ) << getMinute(); } // end function printMilitary // Display standard format time: HH:MM:SS AM (or PM) void Time::printStandard() const { cout << ( ( getHour() == 0 || getHour() == 12 ) ? 12 : getHour() % 12 ) << ":" << ( getMinute() < 10 ? "0" : "" ) << getMinute() << ":" << ( getSecond() < 10 ? "0" : "" ) << getSecond() << ( getHour() < 12 ? " AM" : " PM" ); } // end function printStandard -- 謝謝你!!                  使一個人感動很容易 我好感動~~ 哈 這哪算得了什麼         使一個人心動卻只能看天意 /     >   因為 我喜歡妳..  ▲     ■    ●但..我們還是當好朋友吧^^  ∥      ∥           ■     http://www.wretch.cc/blog/lightpink1 ∥    ∥ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.224.251.208