C++模拟打印日历

这篇博客主要介绍了如何使用C++编程语言来模拟打印日历。内容包括类和函数的声明部分,特别提醒在测试时要注意日期范围,避免超出1949年9月。此外,文中还提到了利用system()函数改变输出颜色的技巧。
摘要由CSDN通过智能技术生成

    类和函数的声明部分:

#include<iostream>
using namespace std;

class Date
{
	friend  void print_date(int year,int month);//打印日历
	friend ostream& operator<<(ostream& _cout, const Date& d);
	friend istream& operator>>(istream& _cin, Date& d);
public:
	Date(int year,int month,int day);//构造函数
	Date(const Date& d);//拷贝构造函数
	Date& operator=(const Date& d);
	Date operator+(int day);
	Date& operator++();
	Date operator++(int);
	Date operator-(int day);
	int operator-(/*const*/ Date& d);
	Date& operator--();
	Date operator--(int);
	bool operator>(const Date& d);
	bool operator<(const Date& d);
	bool operator==(const Date& d);
	bool operator!=(const Date& d);
	bool operator>=(const Date& d);
	bool operator<=(const Date& d);
	int days_everymonth(int year,int month);//所求月的天数
	Date& display(const Date& d);//打印某天日期
private:
	int _year;
	int _month;
	int _day;
};

	bool judge_leap(int year);//判断是否闰年
	void print_date(int year,int month);//打印日期
	int week_firstday(int year,int day);//计算要求月数的第一天是星期几

函数实现:

ostream& operator<<(ostream& _cout, const Date& d)
 {
	 _cout<<d._year<<"--"<<d._month<<"--"<<d._day;
	 return _cout;
 }
 istream& operator>>(istream& _cin, Date& d)
 {
	 _cin>>d._year>>d._month>>d._day;
	 return _cin;
 }
 Date::Date(int year = 2016,int month = 1,int day = 1)
	 :_year(year)
	 ,_month(month)
	 ,_day(day)
{
	if(day
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值