史萊姆論壇

返回   史萊姆論壇 > 專業主討論區 > 程式語言討論區
忘記密碼?
論壇說明

歡迎您來到『史萊姆論壇』 ^___^

您目前正以訪客的身份瀏覽本論壇,訪客所擁有的權限將受到限制,您可以瀏覽本論壇大部份的版區與文章,但您將無法參與任何討論或是使用私人訊息與其他會員交流。若您希望擁有完整的使用權限,請註冊成為我們的一份子,註冊的程序十分簡單、快速,而且最重要的是--註冊是完全免費的!

請點擊這裡:『註冊成為我們的一份子!』

Google 提供的廣告


發文 回覆
 
主題工具 顯示模式
舊 2006-11-06, 11:31 PM   #1
nichjack
榮譽勳章

勳章總數
UID -
在線等級:
文章: n/a
精華:
預設 疑問 - [求助]老師出的顯示時間的題目

這星期四要繳交,但我都看不懂要加入那些指令才能夠讓這段程式完整的執行出來
麻煩各位大大幫忙一下小的了
題目意思是說要寫出一個顯示時間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.                     *
 *************************************************************************/
 
送花文章: 0, 收花文章: 0 篇, 收花: 0 次
回覆時引用此帖
發文 回覆



發表規則
不可以發文
不可以回覆主題
不可以上傳附加檔案
不可以編輯您的文章

論壇啟用 BB 語法
論壇啟用 表情符號
論壇啟用 [IMG] 語法
論壇禁用 HTML 語法
Trackbacks are 禁用
Pingbacks are 禁用
Refbacks are 禁用


所有時間均為台北時間。現在的時間是 02:48 AM


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


SEO by vBSEO 3.6.1