📄 time.cpp
字号:
// time.cpp
// member function definitions for time.cpp
#include <iostream>
using std::cout;
#include <ctime>
#include "time.h"
// constructor
Time::Time()
{
long int totalTime; // time in seconds since 1970
double currentYear = 2002 - 1970; // current year
double totalYear; // current time in years
double totalDay; // days since beginning of year
double divisor; // conversion divisor
int timeShift = 4; // time returned by time() is
// given as the number of seconds
// elapsed since 1/1/70 GMT.
// Depending on the time zone
// you are in, you must shift
// the time by a certain
// number of hours. For this
// problem, 4 hours is the
// current shift for EST.
double tempHour;
double tempMinute; // Used in conversion to seconds.
double tempSecond; // Used to set seconds.
totalTime = time( NULL );
divisor = 60 * 60 * 24 * 365;
totalYear = totalTime / divisor - currentYear;
totalDay = 365 * totalYear; // leap year unimportant
// for hour/minute/seconds
// calculation
tempHour =
(totalDay - static_cast< int >( totalDay ) ) * 24;
tempMinute =
( tempHour - static_cast< int >( tempHour ) ) * 60;
tempSecond =
( tempMinute - static_cast< int >( tempMinute ) ) * 60;
setHour( static_cast< int >( tempHour ) - timeShift );
setMinute( static_cast< int >( tempMinute ) );
setSecond( static_cast< int >( tempSecond ) );
} // end class Time constructor
// function printStandard definition
void Time::printStandard()
{
cout << ( ( hour % 12 == 0 ) ? 12 : hour % 12 ) << ':'
<< ( minute < 10 ? "0" : "" ) << minute << ':'
<< ( second < 10 ? "0" : "" ) << second << '\n';
} // end function printStandard
/**************************************************************************
* (C) Copyright 1992-2003 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. *
*************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -