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

📄 date.cpp

📁 This assessment requires the creation of three of the core classes of the auction project. Class Dat
💻 CPP
字号:
#include <iostream>
#include <string>
#include "Date.h"

using namespace std;

Date::Date(void):month(0),day(0),year(0),hour(0),minute(0),second(0)
{

}

Date::Date (int month, int day, int year, int hour, int minute, int second):month(month),day(day),year(year),hour(hour),minute(minute),second(second)
{

}

void Date::setMonth(int& mo)
{
	month = mo;
}
	    
void Date::setDay(int& da)
{
	day = da;
}

void Date::setYear(int& ye)
{
	year = ye;
}

void Date::setHour(int& ho)
{
	hour = ho;
}

void Date::setMinute(int& mi)
{
	minute = mi;
}

void Date::setSecond(int& se)
{
	second = se;
}


int Date::getMonth(void) const
{
	return month;
}
	    
int Date::getDay(void) const
{
	return day;
}
	    
int Date::getYear(void) const
{
	return year;
}
	    
int Date::getHour(void) const
{
	return hour;
}

int Date::getMinute(void) const
{
	return minute;
}
	    
int Date::getSecond(void) const
{
	return second;
}


bool Date::operator== (const Date &rhs)
{
	if((year == rhs.year)&&(month == rhs.month)&&(day == rhs.day)&&(hour ==rhs.hour)&&(minute == rhs.minute)&&(second == rhs.second))
		return true;
	else 
		return false;
}

bool Date::operator< (const Date &rhs)
{
	if(year < rhs.year)
		return true;
	else if(year > rhs.year)
		return false;
	else
	{
		if(month < rhs.month)
			return true;
		else if(month > rhs.month)
			return false;
		else
		{
			if(day < rhs.day)
				return true;
			else if(day > rhs.day)
				return false;
			else
			{
				if(hour < rhs.hour)
					return true;
				else if(hour > rhs.hour)
					return false;
				else
				{
					if(minute < rhs.minute)
						return true;
					else if(minute > rhs.minute)
						return false;
					else
					{
						if(second < rhs.second)
							return true;
						else if(second > rhs.second)
							return false;
						else
						{
							return false;
						}
					}
				}
			}
		}
	}
}


ostream &operator<<(ostream& stream, const Date& d)
{
	return stream << d.getMonth() << "/" << d.getDay() << "/" << d.getYear() << " " << d.getHour() << ":" << d.getMinute() << ":" << d.getSecond();
}

istream &operator>>(istream& stream, Date& d)
{
	string str;
	stream >> str;

	int month,day,year,hour,minute,second;
	string::size_type pos1,pos2;
	pos1 = str.find_first_of ("/");
    month = atoi(str.substr(0, pos1).c_str());

	pos2 = str.find_last_of("/");
	day = atoi(str.substr(pos1+1,pos2).c_str());
     
	year = atoi(str.substr(pos2+1,pos2+5).c_str());
	stream >> str;
	
	pos1 = str.find_first_of(":");
	hour = atoi(str.substr(0,pos1).c_str());

	pos2 = str.find_last_of(":");
	minute = atoi(str.substr(pos1+1,pos2).c_str());

	second = atoi(str.substr(pos2+1).c_str());

	d.setMonth(month);
	d.setDay(day);
	d.setYear(year);
	d.setHour(hour);
	d.setMinute(minute);
	d.setSecond(second);
	return stream;
}

   

⌨️ 快捷键说明

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