📄 date_.cpp
字号:
#include "date.h"
//类实现部分
//**********************************************************************************
//Date类的构造函数
Date::Date()
{
strcpy(tmpbuf,"\0");
}
//**********************************************************************************
//返回到当前为止,图书已入库多少天
int Date::getDates()
{
int date1,date2;
int month1,month2;
int year1,year2;
int dates;
char newDate[9];
char temp[3];
_strdate(newDate);
temp[0]=tmpbuf[0];
temp[1]=tmpbuf[1];
temp[2]=tmpbuf[2];
month1 = (int)atof(temp);
temp[0]=tmpbuf[4];
temp[1]=tmpbuf[5];
temp[2]=tmpbuf[6];
date1 = (int)atof(temp);
temp[0]=tmpbuf[7];
temp[1]=tmpbuf[8];
temp[2]=tmpbuf[9];
year1 = (int)atof(temp);
temp[0]=newDate[0];
temp[1]=newDate[1];
temp[2]=newDate[2];
month2 = (int)atof(temp);
temp[0]=newDate[4];
temp[1]=newDate[5];
temp[2]=newDate[6];
date2 = (int)atof(temp);
temp[0]=newDate[7];
temp[1]=newDate[8];
temp[2]=newDate[9];
year2 = (int)atof(temp);
dates= (year2-year1)*365+(month2-month1)*30+(date2-date1);
return dates;
}
//**********************************************************************************
//Date类的设置函数 得到系统时间
void Date::set()
{
_strdate(tmpbuf);
}
//**********************************************************************************
//有需要时手工设置进书日期
void Date::set(char s[])
{
strcpy(tmpbuf,s);
}
//**********************************************************************************
//返回日期串
char * Date::getDate()
{
return tmpbuf;
}
//**********************************************************************************
// 重载"="
Date Date::operator =(const Date &goal)
{
strcpy(tmpbuf,goal.tmpbuf);
return *this;
}
//**********************************************************************************
//重载输入流"<<"
ostream & operator <<(ostream &out,Date &goal)
{
cout<<goal.tmpbuf<<" ";
return out;
}
//**********************************************************************************
//重载文件流"<<"
fstream& operator<< ( fstream & file, Date & goal )
{
file<<goal.tmpbuf;
return file;
}
//**********************************************************************************
//重载文件流">>"
Date operator>> ( fstream & file, Date & goal )
{
file>>goal.tmpbuf;
return goal;
}
//**********************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -