c++银行账户管理程序2

在 C++个人银行账户管理1的基础上进行以下改进:
(1)在类SavingsAccount中增加一个静态数据成员total,用来记录各个账户的总金额,并为其增加相应的静态成员函数getTotal用来对其进行访问。
(2)将类SavingsAccount中不需要改变对象状态的成员函数声明为常成员函数,比如getBalance等。
(3)增加日期类Date
整个程序分为5个文件:date.h account.h是类定义头文件,date.cpp account.cpp是类实现文件,main.cpp是主函数文件。

main.cpp

#include<iostream>
#include"date.h"
#include"account.h"
using namespace std;
double SavingsAccount::total = 0;
int main()
{SavingsAccount s0(1001,0.015,2008,11,1);SavingsAccount s1(1002,0.015,2008,11,1);Date d01(2008,11,5),d02(2008,12,5),d11(2008,11,25),d12(2008,12,20),d2(2009,1,1);s0.deposit(d01,5000);s1.deposit(d11,10000);s0.deposit(d02,5500);s1.withdraw(d12,4000);s0.settle(d2);s1.settle(d2);cout<<"-----------------------------------------------------------------------"<<endl;s0.show();s1.show();cout<<"各账户总额:"<<s0.getTotal()<<endl;
}

account.h

#ifndef ACCOUNT_H_
#define ACCOUNT_H_
#include"date.h"
class  SavingsAccount
{int  Id;  //帐号double  balance;  //余额double  Rate;   //年利率Date  lastDate; //上次变更余额的日期double  accumulation=0; //余额按日累加之和double static total;double  accumulate(Date date);   //获得到指定日期为止的存款金额按日累积值
public:SavingsAccount(int id, double rate,int year,int month,int day);  //构造函数void  deposit(Date date, double amount);  //存入现金,date为日期,amount为金额void  withdraw(Date date, double amount);  //取出现金void  settle(Date date); //结算利息,每年1月1日调用一次该函数void  show();   //输出账户信息int getId() {return Id;}double  getBalance () { return balance;}double  getRate() {return Rate;}double static getTotal();
};
#endif // ACCOUNT_H_INCLUDED
#endif // ACCOUNT_H_INCLUDED

account.cpp

#include<iostream>
#include "account.h"
using namespace std;
double SavingsAccount::accumulate(Date date)
{return balance*lastDate.distance(date);
}
SavingsAccount::SavingsAccount(int id,double rate,int year,int month,int day) :lastDate(year,month,day)
{Id=id;Rate=rate;balance=0;cout<<year<<"/"<<month<<"/"<<day<<"\t";cout<<"账户"<<Id<<"创建完成!"<<endl;
}
void  SavingsAccount::deposit(Date date, double amount)  存入现金,date为日期,amount为金额
{accumulation += accumulate(date);balance+=amount;lastDate = date;total += amount;cout<<Id<<"存入:"<<amount<<"!\t"<<Id<<" 余额:"<<balance<<endl;
}
void  SavingsAccount::withdraw(Date date, double amount) 取出现金
{accumulation += accumulate(date);if(balance>=amount)balance-=amount;elsecout<<"余额不足"<<endl;lastDate=date;total -= amount;cout<<Id<<"取出:"<<amount<<"!\t"<<Id<<" 余额:"<<balance<<endl;
}
void  SavingsAccount::settle(Date date)   //结算利息,每年1月1日调用一次该函数
{accumulation += accumulate(date);double settle = (accumulation/356)*Rate;cout<<Id<<"结算利息:"<<settle<<endl;deposit(date,settle);
}
void  SavingsAccount::show()    //输出账户信息
{cout<<"帐号:"<<Id<<endl<<"余额:"<<balance<<endl;
}
double SavingsAccount::getTotal()
{return total;
}

date.h

#ifndef DATE_H_INCLUDED
#define DATE_H_INCLUDED
class  Date
{int  year, month, day;int  totalDays;   //该日期是从公元元年1月1日开始的第几天
public:Date(int year, int month, int day);int  getYear() const { return year; }int  getMonth() const { return month; }int  getDay() const { return day; }void  show() const;   //输出当前日期bool  isLeapYear(int year) const; //判断当年是否为闰年int  distance(const Date& date) const;//计算当前日期与指定日期之间相差天数
};
#endif // DATE_H_INCLUDED

date.cpp

#include<iostream>
#include "date.h"
using namespace std;
Date::Date(int Year, int Month, int Day)
{year=Year;month=Month;day=Day;int Days=0;for(int i=0;i<year;i++){if(isLeapYear(i)==true)Days=Days+366;elseDays=Days+365;}switch(month){case 1:Days+=0;break;case 2:Days+=31;break;case 3:Days+=59;break;case 4:Days+=90;break;case 5:Days+=120;break;case 6:Days+=151;break;case 7:Days+=181;break;case 8:Days+=212;break;case 9:Days+=243;break;case 10:Days+=273;break;case 11:Days+=304;break;case 12:Days+=334;break;default:cout<<"month error!"<<endl;}totalDays=Days+day;
}
void  Date::show() const
{cout<<getYear()<<"/"<<getMonth()<<"/"<<getDay()<<endl;
} //输出当前日期
bool  Date::isLeapYear(int year) const
{if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)return true;elsereturn false;
} //判断当年是否为闰年
int  Date::distance(const Date& date) const
{cout<<date.year<<"/"<<date.month<<"/"<<date.day<<"\t";return date.totalDays-totalDays;
}    //计算当前日期与指定日期之间相差天数

代码运行截图

更多见:

C++银行账户管理1
C++银行账户管理3
C++银行账户管理4

C++银行账户管理程序2相关推荐

  1. 【C++ 第七章 个人银行账户管理程序案例】

    [第七章] 个人银行账户管理程序  案例实现 //account.cpp #include"account.h" #include<cmath> #include< ...

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

    这个程序是一个银行账户管理的程序,是用C++来实现程序功能的,该程序包含六个文件,其中有date.h头文件 是日期类的头文件,date.cpp是日期类的实现文件,accumulator.h是按日将数值 ...

  3. shell银行账户管理程序_如何在德国设立银行账户?德国银行卡比较和解析

    什么是Current Account? 通过Expatrio在线办理的自保金账户是一个特殊的,有限制条款的冻结账户,不能作为储蓄和消费账户使用.因此您需要设立一个欧元往来账户(current acco ...

  4. shell银行账户管理程序_德国邮政 Postbank 银行 开户 中文 参考教程

    精 选 众家 » 生活点滴 » 德国邮政 Postbank 银行 开户 中文 参考教程 德国邮政 Postbank 银行 开户 中文 参考教程 2014-07-29 2518 次阅读 德国邮政银行Po ...

  5. C++转Java个人银行账户管理程序

    4.9 1.private,public等在Java里面需要单独写在每一个成员前面 java private int id; private void record(int date, double ...

  6. 个人银行账户管理程序(C++语言程序设计第4版)

    银行作业分享,欢迎批评指正.到第12章. 文章目录 Array.h accumulator.h date.h account.h account.cpp date.cpp main.cpp comma ...

  7. java转账_使用Java模拟银行账户存、取款、转账功能

    半枯 package bank;import java.util.Scanner;/** * 1.建立一个银行账户类(Acount),具有建立新帐号.查询余额.存款.取款.转账 * 即从本账户把钱转给 ...

  8. python银行系统-Python实现银行账户资金交易管理系统

    用类和对象实现一个银行账户的资金交易管理, 包括存款.取款和打印交易详情, 交易详情中包含每次交易的时间.存款或者取款的金额.每次交易后的余额. 如: 下面按照要求定义一个账户 Account 类.账 ...

  9. C#实验报告 类与对象的访问性:银行账户存取款、新建账户、查询余额

    实验4 C#程序的流程控制 一.实验目的 (1)理解面向对象的概念,掌握C#定义类和创建对象的方法 (2)区分类的不同数据成员,包括常量.字段和属性的定义方法,并学会控制其访问性 (3)掌握类的方法成 ...

  10. C++编程练习:设计一个银行账户类,包含户名、帐号以及当前余额属性,并且能完成开户、存款、取款和查询余额等行为。

    文章目录 例题 分析 代码 测试 结语 例题 设计一个银行账户(Account)类,包含户名.帐号以及当前余额属性,可完成开户.存款.取款和查询余额等行为.银行账户类的定义要求如下: class Ac ...

最新文章

  1. 什么是体系化?为什么要体系化架构
  2. [置顶] 细说Cache
  3. 应聘腾讯,面试官和我聊了一个小时的人生
  4. centos 6.5 32bit qemu 环境搭建
  5. 湖北师范大学c语言考试题目,湖北师范学院2010期末C语言试卷.doc
  6. 安装android到u盘安装程序,在u盘内安装android教程
  7. Learn X in Y minutes
  8. GitHub 上最受欢迎的 5 大 Java 项目
  9. android仿大众点评,仿大众点评android源码
  10. php读取/写入mssql乱码!(续...重要)
  11. Flask入门 表单Flask-wtf form原生 Bootstrap渲染(七)
  12. virtuebox 安装VBoxGuestAdditions,ubuntu下设置文件共享
  13. c专家编程(C专家编程pdf)
  14. python学习实验报告(第五周)
  15. 素食崇尚的是养身和修心的生活方式,鼎沐素食让你身心共融
  16. android ota功能,支持 OTA 更新  |  Android 开源项目  |  Android Open Source Project
  17. QTREE系列1,4,5,6,7 LCT
  18. java.util工具类之Currency类
  19. linux环境中设定开机自启动与定时任务
  20. 事件委托、事件冒泡与事件捕获

热门文章

  1. 神经网络的数学原理(二):神经元与神经网络
  2. python入门教程陈孟林_如何入门Python?
  3. Centos任务栏不见了
  4. 主流流媒体服务器介绍
  5. 【tensorrt】——error: #error The version of CUB in your include path is not compatible with this releas
  6. ESXi主机从6.7升级到ESXi 7.0.3后无法识别Emulex LPe12000 HBA卡
  7. Python系列之-ins图片保存应用微信机器人开发
  8. EINT、DINT、ERTM、DRTM和INTM、DBGM解析
  9. 爬虫实战 ——百度翻译
  10. c语言round函数作用,if条件函数怎样和round一起用?!,C++中round函数怎么用