、被累加数值当前值value以及上次变更被累加数值为止的按日累加总和sum,该类
1
f同时包含四个函数成员构造函数Accumulator、用来计算到指定日期的累加结果的常函数getSum、用来在指定日期更改数值的函数cha
ge以及用来将累加器清零并重新设定初始日期和数值的函数reset。
定义日期类Date,该类的数据成员包含year、mo
th、day和totalDays,其中totalDays表示这一天的相对日期。该类的成员函数除了构造函数和用来获得year、mo
th、day的函数外,还包括用来得到当前月的天数getMaxDay函数、用来判断当前年是否为闰年的isLeapYear函数、用来将当前日期输出的show函数、用来判断当前日期与指定日期相差天数的dista
ce函数,这些函数都会被Date类的其他成员函数或Savi
gsAccou
t类的函数调用。
以上各个类之间的UML类图如下:
1
Accumulator
lastDateDatevaluedoublesumdouble
Accumulatori
dateDatei
valuedoubleco
stgetSumi
dateDatedoublecha
gei
dateDatei
valuedoublereseti
dateDatei
valuedouble
Savi
gsAccou
t
accAccumulatorratedouble
Savi
gsAccou
ti
dateDatei
idi
ti
ratedouble1co
stgetRatedouble
depositi
dateDatei
amou
tdoublei
descstri
gwithdrawi
dateDatei
amou
tdoublei
descstri
gsettlei
dateDate
1
Date
yeari
tmo
thi
tdayi
ttotalDaysi
tDatei
yeari
ti
mo
thi
ti
dayi
tco
stgetYeari
tco
stgetMo
thi
tco
stgetDayi
tco
stgetMaxDayi
tco
stisLeapTearboolco
stshowco
stdista
cei
dateDatei
t
Accou
t
idstri
gbala
cedoubletotaldouble
Accou
ti
dateDatei
idi
trecordi
dateDatei
amou
tdoublei
descstri
gco
sterrori
msgstri
gco
stgetIdi
tco
stgetBala
cedoubleco
stshowstaticgetTotaldouble
CreditAccou
t
accAccumulatorcreditdoubleratedoublefeedouble
co
stgetDedtdoubleCreditAccou
ti
dateDatei
idi
ti
creditdoublei
ratedoublei
feedoubleco
stgetCreditdoubleco
stgetRatedoubleco
stgetFeedoubleco
stgetAvailableCreditdoubledepositi
dateDatei
amou
tdoublei
descstri
gwithdrawi
dateDatei
amou
tdoublei
descstri
gsettlei
dateDateco
stshow
2
f程序代码:
账户类定义头文件:Accou
thif
def_ACCOUNT_H_defi
e_ACCOUNT_H_
i
cludestri
gi
clude