⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usedate.cpp

📁 大于小于等于 操作符重载 对于日期的使用
💻 CPP
字号:
#include <iostream>
#include "myDate.h"
using namespace std;

int main()
{
	//自定义四个不同日期(日期 A 为默认构造日期)
    Date A;
    Date B(1980, 1, 1);
    Date C(2007, 5, 20);
	Date D(1980, 1, 1);
	//打印四个日期,以作比较
	cout << "Show all the years will be compared:" << endl;
    cout << "The default constructor --> "<<"A = ";
    A.Show();
    cout << "B = ";
    B.Show();
    cout << "C = ";
    C.Show();
	cout << "D = ";
	D.Show();
	
	//使用重载后的‘ 〉’比较日期 B 和 C,显示其中较大的年份 
	cout<< "Compare the year of B and C with '>'" << endl;
	if( B>C == true)
	{
		cout<< "The bigger year is: ";
		B.Show();
	}
	else
	{
		cout<< "The bigger year is: ";
		C.Show();
	}

	//使用重载后的‘〈 ’ 比较日期 B 和 C,显示其中较小的年份
	cout<< "Compare the year of B and C with '<'" << endl;
	if( B<C == true)
	{
		cout<< "The smaller year is: ";
		B.Show();
	}
	else
	{
		cout<< "The smaller year is: ";
		C.Show();
	}

	//使用重载后的‘ = ’比较日期 B 和 D,判断他们是否相等
	cout<< "Compare the year of B and D with '='" << endl;
	if( (B = D) == true)
	{
		cout<< "They are the same year, they are equal." << endl;
	}
	else
	{
		cout<< "They are not the same year, they are not equal." << endl;
	}
	

	return 0;

  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -