收藏 分销(赏)

个人银行账户管理程序.doc

上传人:丰**** 文档编号:3043192 上传时间:2024-06-13 格式:DOC 页数:11 大小:334KB
下载 相关 举报
个人银行账户管理程序.doc_第1页
第1页 / 共11页
个人银行账户管理程序.doc_第2页
第2页 / 共11页
个人银行账户管理程序.doc_第3页
第3页 / 共11页
个人银行账户管理程序.doc_第4页
第4页 / 共11页
个人银行账户管理程序.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、个人银行账户管理程序实验内容:设计一个程序,实现对个人银行账户的管理。银行账户有储蓄账户和信用账户两类。储蓄账户不可以透支,利息每年结算一次;信用账户允许在一定额度内透支,透支则需支付利息,并在每月1日进行一次结算。实验要求:1. 程序要实现的功能:a) 用户创建新账户需要提供基本的账号以及金额,如果是储蓄账户,还需定义年利率,如果是信用账户,则还需定义信用额度,日利率,年费b) 储蓄账户:在每年的1月1日结算利息,利息的计算: 将一年中每天的余额累积起来再除以一年总天数,得到日均余额,再乘以年利率c) 信用账户:在每年的1月1日扣取年费,信用账户没有利息,但透支则需要支付利息,从透支那天开始

2、计算利息(日均欠费金额利率),并在每月的1日进行一次结算d) 用户能查看账户信息以及账户余额的变动情况e) 用户存取款需要提供日期和金额,取款失败应提示输出失败原因2. 设计类并写出每个类的详细描述(包括构造函数,成员变量,成员函数的含义)和画出UML类图(体现类之间的关系和类内成员的访问权限)3. 程序中使用的类应该做到类定义和实现分离(使用多文件结构)4. 设计测试用例对程序功能进行充分测试,并对运行结果进行截图实验分析:定义账户基类Account描述所有账户的共性,包含私有成员:账号id、余额balance、账户总金额静态数据成员total;保护成员:构造函数Account()、记账函数

3、record()、错误信息报告常函数error();公有成员:获取账号常函数getId()、获取余额常函数getBalance()、获取总金额静态函数getTotal()、显示账户信息show()。再从账户基类中公有派生出储蓄账户类SavingsAccount和信用账户类CreditAccount,储蓄类账户中定义了私有成员:辅助计算利息的累加器acc、存款的年利率rate,公有成员:构造函数SavingsAccount()、用于访问年利率的常函数getRate()、存现金函数deposit()、取现金函数withdraw()、利息结算函数settle()。信用类账户中定义了私有成员:辅助计算

4、利息的累加器acc、信用额度credit、欠款的日利率rate、信用卡年费fee、获得欠款项函数getDebt();公有成员:构造函数CreditAccount()、获取信用额度常函数getCredit()、获取日利率常函数getRate()、获取年费常函数getFee()、获得可用信用额度常函数getAvailableCredit()、存现金函数deposit()、取现金函数withdraw()、利息和年费结算函数settle()。定义类Accumulator,用于计算一项数值的按日累加之和的接口,通过该类计算利息,包含三个数据成员表示被累加数值上次变更日期的lastDate、被累加数值当前

5、值value以及上次变更被累加数值为止的按日累加总和sum,该类同时包含四个函数成员构造函数Accumulator()、用来计算到指定日期的累加结果的常函数getSum()、用来在指定日期更改数值的函数change()以及用来将累加器清零并重新设定初始日期和数值的函数reset()。定义日期类Date,该类的数据成员包含year、month、day和totalDays,其中totalDays表示这一天的相对日期。该类的成员函数除了构造函数和用来获得year、month、day的函数外,还包括用来得到当前月的天数getMaxDay()函数、用来判断当前年是否为闰年的isLeapYear()函数、

6、用来将当前日期输出的show()函数、用来判断当前日期与指定日期相差天数的distance()函数,这些函数都会被Date类的其他成员函数或SavingsAccount类的函数调用。以上各个类之间的UML类图如下:程序代码:账户类定义头文件:/Account.h#ifndef _ACCOUNT_H_ #define _ACCOUNT_H_ #include #include Date.h #include Accumulator.h class Account private: std:string id; double balance; static double total; protec

7、ted: Account(const Date &date, const std:string &id); void record(const Date &date, double amount, const std:string &desc); void error(const Date &date, double amount, const std:string &msg) const;public: const std:string &getId() constreturn id; double getBalance() constreturn balance; static doubl

8、e getTotal()return total; void show() const; ; class SavingsAccount:public Account private: Accumulator acc; double rate; public: SavingsAccount(const Date &date, const std:string &id, double rate);double getRate() const return rate; void deposit(const Date &date, double amount, const std:string &de

9、sc); void withdraw(const Date &date, double amount, const std:string &desc); void settle(const Date &date); ; class CreditAccount:public Account private: Accumulator acc; double credit; double rate; double fee; double getDebt() const double balance = getBalance(); return (balance0 ? balance : 0); pu

10、blic: CreditAccount(const Date &date, const std:string &id, double credit, double rate, double fee); double getCredit() const return credit; double getRate() constreturn rate; double getFee()return fee; double getAvailableCredit() const if(getBalance() 0) return credit + getBalance(); elsereturn cre

11、dit; void deposit(const Date &date, double amount, const std:string &desc); void withdraw(const Date &date, double amount, const std:string &desc); void settle(const Date &date); void show() const; ; #endif账户类实现文件:/Account.cpp#include #include #include #include Account.h using namespace std; double

12、Account:total = 0; Account:Account(const Date &date, const std:string &id):id(id), balance(0) date.show(); cout t# id is created endl; void Account:record(const Date &date, double amount, const std:string &desc) amount = floor(amount * 100 + 0.5) / 100; balance += amount; total += amount; date.show(

13、); cout t# id t setw(6) amount t setw(10) balance t desc endl; void Account:show() constcout # id tBalance: balance; void Account:error(const Date &date, double amount, const string &msg) const date.show();cout t# id t setw(6) amount t setw(10) balance t Error:+msg getBalance() error(date, amount, y

14、ou not enough money); else record(date,-amount,desc); acc.change(date,getBalance(); void SavingsAccount:settle(const Date &date) double interest = acc.getSum(date) * rate / date.distance( Date(date.getYear()-1,1,1) ); if(interest!=0) record(date,interest,interest); acc.reset(date,getBalance(); Credi

15、tAccount:CreditAccount(const Date &date,const string& id,double credit,double rate,double fee):Account(date,id),credit(credit),rate(rate),fee(fee),acc(date,0) void CreditAccount:deposit(const Date &date,double amount,const string &desc) record(date,amount,desc); acc.change(date,getDebt(); void Credi

16、tAccount:withdraw(const Date &date,double amount,const string &desc) if(amount-getBalance()credit) error(date, amount, you not enough credit); else record(date,-amount,desc); acc.change(date,getDebt(); void CreditAccount:settle(const Date &date) double interest=acc.getSum(date)*rate; if(interest!=0)

17、 record(date,interest,interest); if(date.getMonth()=1)record(date,-fee,annual fee); acc.reset(date,getDebt(); void CreditAccount:show() const Account:show(); cout ttAvailable credit: getAvailableCredit(); 日期类头文件:/Date.h#ifndef _DATE_H_ #define _DATE_H_ class Date private: int year; int month; int da

18、y; int totalDays; public: Date(int year, int month, int day); int getYear() const return year; int getMonth() const return month; int getDay() const return day; int getMaxDay() const; bool isLeapYear() const return year%4=0 & year%100!=0 | year%400=0; int distance(const Date& date) const return tota

19、lDays - date.totalDays; void show() const; #endif 日期类实现文件:/Date.cpp#include #include #include Date.h using namespace std; namespace const int DAYS_BEFORE_MONTH=0,31,59,90,120,151,181,212,243,273,304,334,365; Date:Date(int year,int month,int day):year(year),month(month),day(day) if(day getMaxDay() co

20、ut Invalid date: ; show(); cout 2) totalDays+; int Date:getMaxDay() const if(isLeapYear() & month = 2) return 29;else return DAYS_BEFORE_MONTHmonth - DAYS_BEFORE_MONTHmonth-1; void Date:show() const cout getYear() - getMonth() - value = value; void reset(const Date &date, double value) lastDate = da

21、te; this-value = value; sum=0; ; #endif 测试用例及截图:/main.cpp#include #include #include Account.h using namespace std;int main() Date date(2016, 12, 22);cout建立账户endl;SavingsAccount sa1(date, SA_2016, 0.015);SavingsAccount sa2(date, SA_2017, 0.015);CreditAccount ca(date, CA_2018, 10000, 0.0005, 100);cout

22、所有账户的交易记录(存款、取款、结算)endl;coutTimettAccount_idtsetw(6)Amounttsetw(11)BalancetNotesendl;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, buy a cell);sa2.deposit(Date(2017, 1, 25), 10000, s

23、ell stock 0323);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, repay the credit);ca.settle(Date(2017, 5, 1);sa1.deposit(Date(2017, 5, 5), 5500, salary);ca.settle(Date(2017, 6, 1);ca.settle(Date(2017, 7, 1);ca.withdraw(Date(2017, 7,

24、 10), 10000, donation);sa2.withdraw(Date(2017, 7, 20), 15000, buy a cell phone);ca.settle(Date(2017, 8, 1);ca.deposit(Date(2017, 8, 26), 1000, repay the credit);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);cout所有账户信息endl;sa1.show();coutendl;sa2.show();coutendl;ca.show();coutendl;cout所有账户总金额Total: Account:getTotal() endl;return 0;运行结果:

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 管理财经 > 金融保险

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服