版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
//Date,h
#ifndefDATEH_
^define_DATE_H_
classDate{
private:
intyear;
intmonth;
intday;
inttotalDays;
public:
Date(intyear,intmonth,intday);
intgetYear()const(
returnyear;
}
intgetMonth0const{
returnmonth;
}
intgetDay()const(
returnday;
}
intgetMaxDay()const;
boolisLeapYearOconst(
returnyeai'%4==C&&year%100!=0year%400==0;
}
voidshow()const;
〃计算两个日期之间差多少天
intdistance(constDatc&date)const{
returntotalDays-date.totalDays;
}
};
#endif
“Accumulator,h
iiifndef_ACCUMULATOR」]
^define_ACCUMULATOR_H
^include"Date,h”
classAccumulator!
private:
DatelastDate;
doublevalue;
doublesum;
public:
〃构造函数,date开始累加的日期,value为初始值
Accumulator(constDaleSdate,doublevalue):lastDalc(date),value(value),sum(O){:
〃获得U期date的累加结果
doublegctSum(constDate&datc)const{
returnsum+valu€*date.distance(lastDate);
}
〃在date将数值变更为value
voidchange(constDate&date,doublevalue){
sum=getSum(date);
lastDate=date;this->va1ue=va1ue;
}
voidreset(constDate&date,doublevalue){
lastDate=date;
this->va1ue=va1ue;
sum=0;
)
);
#endif
//Accout.h
#ifndef_ACC0UNT_H_
切efine_ACCOUNT_H_
#include"Date,h”
#include"Accumulator,h”
#include<string>
classAccount{
private:
std::stringid;
doublebalance;
staticdoubletotal;
protected:
〃供派生类调用的构造函数,id为账户
Account(constDate&date,conststd::string&id);
〃记录一笔括账,date为日期,amount为金额,desc为说明
voidrecord(constDate&date,doubleamount,conststd::string&desc);
〃报告错误信息
voiderror(conststd::string&msg)const;
public:
conststd::string&getld()const{returnid;}
doubIegetBalanceOconst{returnbalance:)
staticdoublegetTotal(){returntotal:)
〃显示账户信息
voidshow()const:
};
classSavingsAccount:pub]icAccount{
private:
Accumulatoracc;
//doublecredit;
doublerate;
public:
〃构造函数
SavingsAccount(constDate&date,conststd::string&id,doublerate);
doublegetRateOconst(returnrate;}
〃存入现金
voiddeposit(constDate&date,doubleamount,conststd::string&desc);
〃取出现金
voidwithdraw(constDate&date,doubleamount,conststd::string&desc);
voidsettle(constDace&date);
};
classCreditAccount:publicAccount{
private:
Accumulatoracc;
doublecredit;
doublerate;
doublefee;
doublegetDebt()const{
doublebalance=getBalance();
return(balance<O?balance:O);
}
public:
〃构造函数
CreditAccount(constDate&date,conststd::string&id,doublecredit,doublerate,double
fee);
doublegetCredit()const{returncredit;}
doublegetRateOconst{returnrate;}
doublegetFeeO(returnfee;}
doublegetAvai1ableCredit()const{
if(getBalance()<0)
returncredit+getBalance();
else
returncredit;
}
〃存入现金
voiddeposit(constDate&datc,doubleamount,conststd::string&desc):
〃取出现金
voidwithdraw(constDate&datc,doubleamount,conststd::string&desc);
voidsettle(constDate&date);
voidshow()const;
}:
#endif
//Date.epp
#include"Date,h”
Sinclude<iostream>
^include<csidlib>
usingnamespacestd;
namespace{//namespace使卜面的定义只在当前文件中有效
〃存储半年中的某3个月1日之前有多少天,为便于getMaxDay函数的实现,该数组多出一项
constintDAYS_BEF0R3_M0NTH[]=(0,31,59,90,120,15L181,212,243,273,304,334,365};
}
Date::Date(intyear,intnonth,intday):year(year),month(month),day(day){
if(day<=0day>geLMaxDay()){
cout«z,Invaliddate:";
show();
cout«endl;
exit(1);
}
intyears=year-l;
totalDays=ycars*365+ycars/4-ycars/l00+years/400+DAYS_BEFORE_MONTH[month-1]+day;
if(isLeapYeai'()&&month>2)
totalDays++;
}
intDate::getMaxDay()const{
if(isLeapYear()&&month==2)
return29;
else
returnDAYS_BEFORE_MONTH[month]-DAYS_BEFORE_MONTH[month-1];
}
voidDate::show()const{
cout«getYear()«z/*«getMonth0«*-z/«getDay0;
}
//Account.cpp
#include“Accout.h"
#include<cmalh>
#include<iostream>
usingnamespacestd;
doubleAccount::total=0;
〃Accounl类的实现
Account::Account(constDate&date,conststd:zstring&id):id(id),balance(0){
date,show();
cout"created”〈〈end1;
)
voidAccount::record(constDate&date,doubleamount,conststd::string&desc){
amount=floor(amount*100+0.5)/100;
balance+=amount;
total+=amount;
date.show();
cout«zz\t#/,«id«,,\t"«amount«,z\tz«balance<<"\tv«desc«endl;
)
voidAccount::show()const{cout«id<<~\tBalance:“〈〈balance;}
void?\ccount::error(conststring&msg)const{
cout<<MError(#",<<id<(//):*«msg«endl;
}
〃SavingsAccount类相关成员函数的实现
SavingsAccount::SavingsAccount(constDate&date,conststd:zstring&id,double
rate):Account(date,id),rate(rate),acc(date,0)(}
voidSavingsAccount::deposit(constDateftdate,doubleunount,conststring&dcsc){
record(date,amount,desc);
acc.change(date,gctBalanceO);
}
voidSavingsAccount::withdraw(constDate&date,doubleamount,conststring&desc)(
if(amount>getBalance()){
error(zznotenoughmoney");
}
else(
record(date,-ameunt,desc);
acc.change(date,getBalance());
}
voidSavingsAccount::settle(constDate&date){
doubleinterest=acc.getSum(dale)*rate/dalc.distance(Date(date.getYcar()-1,1,l)j;
if(interest!=0)
record(date,interest,"interest");
acc.reset(date,getBalanceO);
)
//CreditAccount类相关成员函数的实现
CreditAccount::CreditAccount(constDate&date,conststring&id,doublecredit,double
rate,doublefee):Account(date,id),credit(crcdit),rate(rate),fee(fec),acc(date,0){}
voidCreditAccount::deposit(constDatedelate,doubleamount,conststring&desc){
record(date,amount,desc);
acc.change(date,getDebt());
)
voidCreditAccount::withdraw(constDate&date,double£mount,conststring&desc){
if(amount-getBalanceO>credit)(
error(^notenoughcredit");
}
else{
record(date,-ameunt,desc);
acc.change(date,getDebt()):
}
)
voidCreditAccount::settle(constDate&date){
doubIeinterest=acc.getSum(date)*rate;
if(interest!=0)
record(date,interest,“interest");
if(date.getMonth()==l)
record(date,-fee,“annualfee");
acc.reset(date,getDebt()):
}
voidCreditAccount::show()const{
Account::show();
cout«w\tAvailablecredit:*«getAvailableCredit();
)
//Lab7_10
#include“Accout.h"
#include<iostream>
usingnamespacestd;
intmain(){
Datedate(2008,11,1);
〃建立几个账户
SavingsAccountsal(date,*53755217",0.015):
SavingsAccountsa2
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生物标志物指导EGJ腺癌免疫联合治疗策略
- 生物标志物在药物临床试验中的多学科协作
- 生物材料导管与再生修复的协同策略
- 生物打印技术在心脏组织工程中的挑战
- 生物化学虚拟实验与科研方法培养
- 生物制品稳定性试验生物传感器应用
- 生物制剂失应答的炎症性肠病精准医疗实践
- 游戏体验与娱乐项目管理要点及面试题目参考
- 工业制造领域的数据分析师招聘题目
- 深度解析(2026)《GBT 19529-2004技术信息与文件的构成》
- 《J监狱突发事件应急管理现状及完善对策研究》24000字(论文)
- 中药山药课件
- 国开电大操作系统实验2:进程管理实验报告
- 建筑材料采购投标方案(技术标)
- 小步舞详解(教师版)
- 光伏支架安装技术交底
- 节能基本情况表(打印)
- 创新思维与创业实验-东南大学中国大学mooc课后章节答案期末考试题库2023年
- 电动车转让合同协议书电子版
- YS/T 1019-2015氯化铷
- GB/T 39081-2020电阻点焊及凸焊接头的十字拉伸试验方法
评论
0/150
提交评论