个人银行账户管理程序Word下载.docx

上传人:b****3 文档编号:7169937 上传时间:2023-05-08 格式:DOCX 页数:16 大小:110.57KB
下载 相关 举报
个人银行账户管理程序Word下载.docx_第1页
第1页 / 共16页
个人银行账户管理程序Word下载.docx_第2页
第2页 / 共16页
个人银行账户管理程序Word下载.docx_第3页
第3页 / 共16页
个人银行账户管理程序Word下载.docx_第4页
第4页 / 共16页
个人银行账户管理程序Word下载.docx_第5页
第5页 / 共16页
个人银行账户管理程序Word下载.docx_第6页
第6页 / 共16页
个人银行账户管理程序Word下载.docx_第7页
第7页 / 共16页
个人银行账户管理程序Word下载.docx_第8页
第8页 / 共16页
个人银行账户管理程序Word下载.docx_第9页
第9页 / 共16页
个人银行账户管理程序Word下载.docx_第10页
第10页 / 共16页
个人银行账户管理程序Word下载.docx_第11页
第11页 / 共16页
个人银行账户管理程序Word下载.docx_第12页
第12页 / 共16页
个人银行账户管理程序Word下载.docx_第13页
第13页 / 共16页
个人银行账户管理程序Word下载.docx_第14页
第14页 / 共16页
个人银行账户管理程序Word下载.docx_第15页
第15页 / 共16页
个人银行账户管理程序Word下载.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

个人银行账户管理程序Word下载.docx

《个人银行账户管理程序Word下载.docx》由会员分享,可在线阅读,更多相关《个人银行账户管理程序Word下载.docx(16页珍藏版)》请在冰点文库上搜索。

个人银行账户管理程序Word下载.docx

该类的成员函数除了构造函数和用来获得year、month、day的函数外,还包括用来得到当前月的天数getMaxDay()函数、用来判断当前年是否为闰年的isLeapYear()函数、用来将当前日期输出的show()函数、用来判断当前日期与指定日期相差天数的distance()函数,这些函数都会被Date类的其他成员函数或SavingsAccount类的函数调用。

以上各个类之间的UML类图如下:

程序代码:

账户类定义头文件:

//Account.h

#ifndef_ACCOUNT_H_

#define_ACCOUNT_H_

#include<

string>

#include"

Date.h"

Accumulator.h"

classAccount{

private:

std:

:

stringid;

doublebalance;

staticdoubletotal;

protected:

Account(constDate&

date,conststd:

string&

id);

voidrecord(constDate&

date,doubleamount,conststd:

desc);

voiderror(constDate&

msg)const;

public:

conststd:

getId()const{

returnid;

}

doublegetBalance()const{

returnbalance;

staticdoublegetTotal(){

returntotal;

voidshow()const;

};

classSavingsAccount:

publicAccount{

Accumulatoracc;

doublerate;

SavingsAccount(constDate&

id,doublerate);

doublegetRate()const{

returnrate;

voiddeposit(constDate&

voidwithdraw(constDate&

voidsettle(constDate&

date);

classCreditAccount:

publicAccount{

doublecredit;

doublefee;

doublegetDebt()const{

doublebalance=getBalance();

return(balance<

0?

balance:

0);

CreditAccount(constDate&

id,doublecredit,doublerate,doublefee);

doublegetCredit()const{

returncredit;

doublegetRate()const{

doublegetFee(){

returnfee;

doublegetAvailableCredit()const{

if(getBalance()<

0)

returncredit+getBalance();

else

returncredit;

#endif

账户类实现文件:

//Account.cpp

iostream>

cmath>

iomanip>

Account.h"

usingnamespacestd;

doubleAccount:

total=0;

Account:

Account(constDate&

id):

id(id),balance(0){

date.show();

cout<

<

"

\t#"

<

id<

iscreated"

endl;

}

voidAccount:

record(constDate&

desc){

amount=floor(amount*100+0.5)/100;

balance+=amount;

total+=amount;

\t"

setw(6)<

amount<

setw(10)<

balance<

desc<

}

show()const{

#"

\tBalance:

"

balance;

error(constDate&

date,doubleamount,conststring&

msg)const{

cout<

Error:

+msg<

endl;

SavingsAccount:

SavingsAccount(constDate&

id,double

rate):

Account(date,id),rate(rate),acc(date,0){}

voidSavingsAccount:

deposit(constDate&

desc){

record(date,amount,desc);

acc.change(date,getBalance());

withdraw(constDate&

if(amount>

getBalance()){

error(date,amount,"

younotenoughmoney"

);

}else{

record(date,-amount,desc);

acc.change(date,getBalance());

settle(constDate&

date){

doubleinterest=acc.getSum(date)*rate/date.distance(Date(date.getYear()-1,1,1));

if(interest!

=0){

record(date,interest,"

interest"

}

acc.reset(date,getBalance());

CreditAccount:

CreditAccount(constDate&

date,conststring&

id,doublecredit,doublerate,doublefee):

Account(date,id),credit(credit),rate(rate),fee(fee),acc(date,0){}

voidCreditAccount:

date,doubleamount,conststring&

acc.change(date,getDebt());

if(amount-getBalance()>

credit){

younotenoughcredit"

}else{

acc.change(date,getDebt());

doubleinterest=acc.getSum(date)*rate;

if(date.getMonth()==1){

record(date,-fee,"

annualfee"

acc.reset(date,getDebt());

voidCreditAccount:

show()const{

Account:

show();

\t\tAvailablecredit:

getAvailableCredit();

日期类头文件:

//Date.h

#ifndef_DATE_H_

#define_DATE_H_

classDate{

intyear;

intmonth;

intday;

inttotalDays;

Date(intyear,intmonth,intday);

intgetYear()const{

returnyear;

intgetMonth()const{

returnmonth;

intgetDay()const{

returnday;

intgetMaxDay()const;

boolisLeapYear()const{

returnyear%4==0&

&

year%100!

=0||year%400==0;

intdistance(constDate&

date)const{

returntotalDays-date.totalDays;

#endif

 

日期类实现文件:

//Date.cpp

cstdlib>

namespace{

constintDAYS_BEFORE_MONTH[]={0,31,59,90,120,151,181,212,243,273,304,334,365};

Date:

Date(intyear,intmonth,intday):

year(year),month(month),day(day){

if(day<

=0||day>

getMaxDay()){

cout<

Invaliddate:

;

show();

exit

(1);

intyears=year-1;

totalDays=years*365+years/4-years/100+years/400+DAYS_BEFORE_MONTH[month-1]+day;

if(isLeapYear()&

month>

2)

totalDays++;

intDate:

getMaxDay()const{

month==2)

return29;

else

returnDAYS_BEFORE_MONTH[month]-DAYS_BEFORE_MONTH[month-1];

voidDate:

show()const{

getYear()<

-"

getMonth()<

getDay();

Accumulator类头文件:

//Accumulator.h

#ifndef_ACCUMULATOR_H_

#define_ACCUMULATOR_H_

classAccumulator{

DatelastDate;

doublevalue;

doublesum;

Accumulator(constDate&

date,doublevalue):

lastDate(date),value(value),sum(0){}

doublegetSum(constDate&

date)const{

returnsum+value*date.distance(lastDate);

voidchange(constDate&

date,doublevalue){

sum=getSum(date);

lastDate=date;

this->

value=value;

voidreset(constDate&

sum=0;

测试用例及截图:

//main.cpp

intmain(){

Datedate(2016,12,22);

建立账户"

SavingsAccountsa1(date,"

SA_2016"

0.015);

SavingsAccountsa2(date,"

SA_2017"

CreditAccountca(date,"

CA_2018"

10000,0.0005,100);

所有账户的交易记录(存款、取款、结算)"

Time\t\t"

Account_id\t"

setw(6)<

Amount\t"

setw(11)<

Balance\t"

Notes"

sa1.settle(Date(2017,1,1));

sa2.settle(Date(2017,1,1));

ca.settle(Date(2017,1,1));

sa1.deposit(Date(2017,1,5),5000,"

salary"

ca.withdraw(Date(2017,1,15),3000,"

buyacell"

sa2.deposit(Date(2017,1,25),10000,"

sellstock0323"

ca.settle(Date(2017,2,1));

ca.settle(Date(2017,3,1));

ca.settle(Date(2017,4,1));

ca.deposit(Date(2017,4,1),2018,"

repaythecredit"

ca.settle(Date(2017,5,1));

sa1.deposit(Date(2017,5,5),5500,"

ca.settle(Date(2017,6,1));

ca.settle(Date(2017,7,1));

ca.withdraw(Date(2017,7,10),10000,"

donation"

sa2.withdraw(Date(2017,7,20),15000,"

buyacellphone"

ca.settle(Date(2017,8,1));

ca.deposit(Date(2017,8,26),1000,"

ca.settle(Date(2017,9,1));

ca.settle(Date(2017,10,1));

ca.settle(Date(2017,11,1));

ca.settle(Date(2017,12,1));

sa1.settle(Date(2018,1,1));

sa2.settle(Date(2018,1,1));

ca.settle(Date(2018,1,1));

所有账户信息"

sa1.show();

cout<

sa2.show();

ca.show();

所有账户总金额Total:

getTotal()<

return0;

运行结果:

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 农林牧渔 > 林学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2