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

📄 date.cpp

📁 SSD5 中EX1的参考答案 下载后请参照注释认真分析
💻 CPP
字号:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>

#include "date.h"

using namespace std;

date::date ()
{
	day = 0;
	month = 0;
	year = 0;
}

    
date::date (int day, int month, int year)
{
	this->day = day;
	this->month = month;
	this->year = year;
}

    
int date::compareTo (date another_date)
{
	if(this->year == another_date.year)
	{
		if(this->month == another_date.month)
		{
			if(this->day == another_date.day)
			{
				return 0;
			}
			else if(this->day < another_date.day)
			{
				return -1;
			}
			else
			{
				return 1;
			}
		}
		else if(this->month < another_date.month)
		{
			return -1;
		}
		else
		{
			return 1;
		}
	}
	else if(this->year < another_date.year)
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

ostream &operator<< (ostream &stream, date d)
{
	return stream << d.month<<"/"<<d.day<<"/"<<d.year;
}

⌨️ 快捷键说明

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