资源简介
C程序设计教程第二版答案钱能.zip
代码片段和文件信息
// Fig. 11.13: Date.cpp
// Date class member function definitions.
#include
#include “Date.h“
// initialize static member at file scope; one classwide copy
const int Date::days[] =
{ 0 31 28 31 30 31 30 31 31 30 31 30 31 };
// Date constructor
Date::Date(int m int d int y)
{
setDate( m d y );
} // end Date constuctor
// set month day and year
void Date::setDate( int mm int dd int yy )
{
month = ( mm >= 1 && mm <= 12 ) ? mm : 1;
year = ( yy >= 1900 && yy <= 2100 ) ? yy : 1900;
// test for a leap year
if ( month == 2 && leapYear( year ) )
day = ( dd >= 1 && dd <= 29 ) ? dd : 1;
else
day = ( dd >= 1 && dd <= days[ month ] ) ? dd : 1;
} // end function setDate
// overloaded prefix increment operator
Date &Date::operator++()
{
helpIncrement(); // increment date
return *this; // reference return to create an lvalue
} // end function operator++
// overloaded postfix increment operator; note that the
// dumy integer parameter does not have a parameter name
Date Date::operator++( int )
{
Date temp = *this; // hold current state of object
helpIncrement();
// return unincremented saved temporary object
return temp; // value return; not a reference return
} // end function operator++
// add specified number of days to date
const Date &Date::operator +=( int additionalDays )
{
for ( int i = 0; i < additionalDays; i++ )
helpIncrement();
return *this; // enables cascading
} // end function operator+=
// if the year is a leap year return true; otherwise return false
bool Date::leapYear( int testYear ) const
{
if ( testYear % 400 == 0 ||
( testYear % 100 != 0 && testYear % 4 == 0) )
return true; // a leap year
else
return false; // not a leap year
} // end function leapYear
// determine whether the day is the last day of the month
bool Date::endOfMonth( int testDay ) const
{
if ( month == 2 && leapYear( year ) )
return testDay == 29; // last day of Feb. in leap year
else
return testDay == days[ month ];
} // end function endOfMonth
// function to help increment the date
void Date::helpIncrement()
{
// day is not end of month
if ( !endOfMonth( day ) )
day++; // increment day
else // last day of year
{
year++; // increment year
month = 1; // first month of new year
day = 1; // first day of new month
} // end else
} // end function helpIncrement
// overload output operator
ostream& operator<<(ostream& output const Date &d)
{
static char *monthName[ 13 ] = { ““ “January“ “Februray“
“March“ “April“ “May“ “June“ “July“ “August“
“September“ “Oectober“ “November“ “December“ };
output << monthName[ d.month ] << ‘ ‘ << d.day << “ “ << d.year;
return output; // enables cascading
} // end function operator<<
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 505 2008-05-05 20:31 ex0601.cpp
文件 614 2008-05-07 06:09 prime.cpp
文件 271 2008-05-07 06:09 prime.h
文件 16 2008-04-27 16:08 prime.txt
----------- --------- ---------- ----- ----
1406 4
- 上一篇:软件项目管理进度表excel
- 下一篇:fpga峰值采样verilog程序
相关资源
- genPwd.bat
- 打包解包整理vs2013.zip
- was打包器.exe
- VJ1604E-蒙泰新曲线.rar
- lic_standalone.rar
- sh-demand-forecast-alg.zip
- vmware_keygen_20180725.zip
- 中国省份和城市对照表及城市分级.
- cudnn8.0.txt
- IWO.rar.zip
- meituan_spider.rar
- pb做监控系统.zip
- 盗号木马源码.rar
- text.hex
- Intouch2014R2-2099.rar
- 老虎机程序v1.1.rar
- ITSS通用标准.pdf
- MUI全套视频教程地址.txt
- ccnbie.doc
- supplyair_2755453.zip
- 中国菜刀.txt
- TCP_Socket.zip
- QQctangyunxiangc.rar
- 东华-表结构资料.zip
- 敏感词词库.txt
- sunnyman2008_10945697.ap14
- Alamouti.zip
- sRGBColorCheckerBoundary.jpg
- 深入性能测试:LoadRunner性能测试、流
- Zookeeper学习.txt
评论
共有 条评论