C++之个人银行账户管理程序(二)

博文回顾

  C++之个人银行账户管理程序(一)


基于上一篇的基础,本博文要解决总账户金额的存储和维护,以及日期的友好表示。

1.data.h

//date.h
#ifndef __DATE_H__
#define __DATE_H__

class Date {
   
   	//日期类
private:
	int year;		//年
	int month;		//月
	int 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; }
	int getMaxDay() const;		//获得当月有多少天
	bool isLeapYear() const {
   
   	//判断当年是否为闰年
		return year % 4 == 0 && year % 100 != 0 || year % 400 == 0;
	}
	void show() const;			//输出当前日期
	//计算两个日期之间差多少天	
	int distance(const Date& date) const {
   
   
		return totalDays - date.totalDays;
	}
};

#endif //__DATE_H__

2.data.cpp

//date.cpp
#include "date.h"
#include <iostream>
#include <cstdlib>
using namespace std;

namespace {
   
   	//namespace使下面的定义只在当前文件中有效
	//存储平年中某个月1日之前有多少天,为便于getMaxDay函数的实现,该数组多出一项
	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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值