史萊姆論壇

史萊姆論壇 (http://forum.slime.com.tw/)
-   程式語言討論區 (http://forum.slime.com.tw/f76.html)
-   -   [求助]老師出的顯示時間的題目 (http://forum.slime.com.tw/thread191011.html)

nichjack 2006-11-06 11:31 PM

[求助]老師出的顯示時間的題目
 
這星期四要繳交,但我都看不懂要加入那些指令才能夠讓這段程式完整的執行出來
麻煩各位大大幫忙一下小的了
題目意思是說要寫出一個顯示時間24小時制的程式來,下面的圖片有說
要能夠順利的通過進位問題,如23:59:59 進位後變成00:00:00,這個問題比較麻煩,再來就是12:01:59
進位變成12:02:00 ,在圖片中的秒(tick)缺少了指令要我們自己加入

http://i13.tinypic.com/2cf8gh4.jpg
及這段程式碼缺主要的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.                    *
 *************************************************************************/



所有時間均為台北時間。現在的時間是 07:16 PM

Powered by vBulletin® 版本 3.6.8
版權所有 ©2000 - 2025, Jelsoft Enterprises Ltd.

『服務條款』

* 有問題不知道該怎麼解決嗎?請聯絡本站的系統管理員 *


SEO by vBSEO 3.6.1