![]() |
|
論壇說明 |
歡迎您來到『史萊姆論壇』 ^___^ 您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的! 請點擊這裡:『註冊成為我們的一份子!』 |
![]() ![]() |
|
主題工具 | 顯示模式 |
![]() |
#1 |
|
![]() 這星期四要繳交,但我都看不懂要加入那些指令才能夠讓這段程式完整的執行出來
麻煩各位大大幫忙一下小的了 題目意思是說要寫出一個顯示時間24小時制的程式來,下面的圖片有說 要能夠順利的通過進位問題,如23:59:59 進位後變成00:00:00,這個問題比較麻煩,再來就是12:01:59 進位變成12:02:00 ,在圖片中的秒(tick)缺少了指令要我們自己加入 ![]() 及這段程式碼缺主要的main funcion 來整合 語法:
// Fig. 6.19: time3.cpp // Member-function definitions for Time class. #include <iostream> using std::cout; #include <iomanip> using std::setfill; using std::setw; // include definition of class Time from time3.h #include "time3.h" // constructor function to initialize private data; // calls member function setTime to set variables; // 預設 values are 0 (see class definition) Time::Time( int hr, int min, int sec ) { setTime( hr, min, sec ); } // end Time constructor // set hour, minute and second values void Time::setTime( int h, int m, int s ) { setHour( h ); setMinute( m ); setSecond( s ); } // end function setTime // set hour value void Time::setHour( int h ) { hour = ( h >= 0 && h < 24 ) ? h : 0; } // end function setHour // set minute value void Time::setMinute( int m ) { minute = ( m >= 0 && m < 60 ) ? m : 0; } // end function setMinute // set second value void Time::setSecond( int s ) { second = ( s >= 0 && s < 60 ) ? s : 0; } // end function setSecond // return hour value int Time::getHour() { return hour; } // end function getHour // return minute value int Time::getMinute() { return minute; } // end function getMinute // return second value int Time::getSecond() { return second; } // end function getSecond // print Time in universal format void Time::printUniversal() { cout << setfill( '0' ) << setw( 2 ) << hour << ":" << setw( 2 ) << minute << ":" << setw( 2 ) << second; } // end function printUniversal // print Time in standard format void Time::printStandard() { cout << ( ( hour == 0 || hour == 12 ) ? 12 : hour % 12 ) << ":" << setfill( '0' ) << setw( 2 ) << minute << ":" << setw( 2 ) << second << ( hour < 12 ? " AM" : " PM" ); } // end function printStandard /************************************************************************** * (C) Copyright 1992-2002 by Deitel & Associates, Inc. and Prentice * * Hall. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/ |
送花文章: 0,
![]() |