100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > 个人银行账户管理程序【简化】

个人银行账户管理程序【简化】

时间:2020-01-06 12:30:07

相关推荐

个人银行账户管理程序【简化】

//自学,对于“获得到指定日期为止的存款金额按日累加值”这句话理解不能T_T。因此修改类部分内容,忽略部分逻辑=_=……

#include <iostream> #include <cmath> using namespace std;class SavingsAccount { //储蓄账户类private:int id; //账号double balance;//余额double rate; //存款的年利率double interest=0.0;//利息 //记录一笔账,date为日期,amout为金额,desc为说明void record(int date, double amout);public:SavingsAccount(int date, int id, double rate);int getID() { return id; }double getBalance() { return balance; }double getRate() { return rate; }void deposit(int date, double amount);void withdraw(int dadte, double amount);//结算利息double lixi(int date, double amount);//显示账户信息void show();};//SavingsAccount相关成员函数的实现SavingsAccount::SavingsAccount(int date, int id, double rate):id(id), balance(0), rate(rate) {cout << date << "\t#" << id << " is created" << endl;}void SavingsAccount::record(int date, double amount) {amount = floor(amount * 100+0.5)/100; //floor函数的目的:保留小数点后两位balance += amount;cout << date << "\t#" << id << "\t" << amount <<"\t"<< balance << endl;}void SavingsAccount::deposit(int date, double amount) {record(date, amount);lixi(date, amount);}void SavingsAccount::withdraw(int date, double amount) {if (amount > getBalance()) //如果要取的钱大于存款余额cout << "Error:not enough money" << endl;elserecord(date, -amount);lixi(date, -amount);}void SavingsAccount::show() {cout << "#" << id << "\tBalance:" << (balance+interest)<<endl;cout << "#" << id << "\tlixi:" << interest;}double SavingsAccount::lixi(int date, double amount) { //计算不同操作下的存款利息,并累加interest += ((amount*rate) / 365)*(90 - date);interest = floor(interest * 100 + 0.5) / 100;return interest;}int main(){//建立两个账户SavingsAccount sa0(1, 21325302, 0.015);SavingsAccount sa1(1, 5832, 0.015);//几笔账目(操作)sa0.deposit(5, 5000);sa1.deposit(25, 10000);sa0.deposit(45, 5500);sa1.withdraw(60, 4000);//输出各个账户信息sa0.show(); cout << endl;sa1.show(); cout << endl;return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。