Example #1
0
void PrintDate(const Date &cDate)
{
    // although cDate is const, we can call const member functions
    std::cout << cDate.GetMonth() << "/" <<
        cDate.GetDay() << "/" <<
        cDate.GetYear() << std::endl;
}
Example #2
0
void PrintDate(const Date &cDate)
// void PrintDate(Date &cDate)
{
    std::cout << cDate.GetDay() << "/" <<
                 cDate.GetMonth() << "/" <<
                 cDate.GetYear() << std::endl;                
}
Example #3
0
bool Date::operator < ( Date d ) const
{
	if ( m_Year < d.GetYear() )
		return true;

	else if ( m_Year == d.GetYear() )
	{
		if ( m_Month < d.GetMonth() )
			return true;

		else if ( m_Month == d.GetMonth() )
			return m_Day < d.GetDay();
	}

	return false;
}
Example #4
0
std::string Date::GetNowString()
{
    Date d = Date();
    
    char date[60] = {0};
    sprintf(date, "%d-%02d-%02d %02d:%02d:%02d",
            d.GetYear(),d.GetMonth(),d.GetDay(),
            d.GetHour(),d.GetMinute(),d.GetSecond());
    return std::string(date);
}
// Checks if the given date is a valid date in Gregorian calendar
bool ModelValidator::isValid(const Date& date, bool allowDefaults /*= false*/)
{
	if (date == Date() && !allowDefaults)
		RETURN_WITH_ERROR("Date is empty");

	// Check month
	RETURN_IF_RANGE_NOT_VALID(date.GetMonth(), 1, 12, "Month");

	// Check year
	if (date.GetYear() == 0)
		RETURN_WITH_ERROR("There is no 0 year in Gregorian calendar");

	// Check day
	int day = date.GetDay();

	// 1582 - Gregorian calendar switch.
	// No dates exist between october 4 and October 15
	if (date.GetYear() == 1582 && date.GetMonth() == 10 && day > 4 && day < 15)
		RETURN_WITH_ERROR("The year 1582 does not have dates between October 4 and October 15");

	int maxDay = 31;
	switch (date.GetMonth())
	{
		case 4:
		case 6:
		case 9:
		case 11:
			maxDay = 30;
			break;
		case 2:
			maxDay = AIMUtil::isLeapYear(date.GetYear()) ? 29 : 28;
			break;
	}
	RETURN_IF_RANGE_NOT_VALID(day, 0, maxDay, "Day");

	return true;
}
Example #6
0
int main()
{
	int arr[GetConst()] = { 0 };//无法使用运行时常量来初始化数组
	enum{ e1 = GetConst(), e2 };//也无法使用运行时常量作为枚举值

	int arr2[GetConstexpr()] = { 0 };//ok

	constexpr ConstexprClass mc(0); //必须使用常量表达式赋值
	//constexpr ConstexprClass mc = { 0 };等价上一条
	//constexpr ConstexprClass mc{ 0 }; 等价上一条

	//gcc-5.1报错:"error: passing 'const Date' as 'this' argument discards qualifiers [-fpermissive]"
	constexpr Date d(1990, 11, 28);
	constexpr int year = d.GetYear();
	constexpr int month = d.GetMonth();
	constexpr int day = d.GetDay();
	std::cout << "year:" << year << std::endl
		<< "month" << month << std::endl
		<< "day" << day << std::endl;


	//结构体NotLiteral不是定义了常量表达式构造函数的类型,因此不能够声明为常量表达式值
	//而模版函数一旦以NotLiteral作为参数,那么其constexpr关键字就会被忽略
	NotLiteral nl;
	NotLiteral nl1 = ConstExprFun(nl);
	constexpr NotLiteral nl2 = ConstExprFun(nl);//编译失败
	constexpr int a = ConstExprFun(1);

	constexpr Literal l1;
	Literal l2 = ConstExprFun(l1);//ok
	constexpr Literal l3 = ConstExprFun(l1);//ok

	//constexpr函数递归
	int fibs[] = { Fib(11), Fib(12), Fib(13), Fib(14), Fib(15) };
	std::copy(std::begin(fibs), std::end(fibs),
		std::ostream_iterator<int>(std::cout, " "));//89 144 233 377 610 
	
	std::cout << std::endl;
	//使用模板元实现递归编程
	int fibs2[] = { Fibo<11>::result, Fibo<12>::result, Fibo<13>::result, Fibo<14>::result, Fibo<15>::result };
	std::copy(std::begin(fibs2), std::end(fibs2),
		std::ostream_iterator<int>(std::cout, " "));//89 144 233 377 610 

	return 0;
}
Example #7
0
		void DisplayInfo()
		{
			cout<<"借阅信息------------------------------"<<endl;
			cout<<"图书信息----------------"<<endl;
			cout<<"书名:\t\t"<<inBook.GetName()<<endl;
			cout<<"作者:\t\t"<<inBook.GetAuthor()<<endl;
			cout<<"ISBN号:\t"<<inBook.GetISBNNum()<<endl;
			cout<<"出版日期:\t"<<inBook.GetDat()<<endl;

			cout<<"读者信息-----------------"<<endl;
			cout<<"姓名:\t\t"<<inPatron.GetName()<<endl;
			cout<<"图书卡号:\t"<<inPatron.GetCardNum()<<endl;
			cout<<"借书日期:\t"<<inDate.GetYear()<<"-"<<inDate.GetMonth()<<"-"<<inDate.GetDay()<<endl;
			if(inPatron.IsOwed())
				cout<<"欠费信息:\t欠费"<<inPatron.GetOweCount()<<"元"<<endl;
			else
				cout<<"欠费信息:\t无欠费记录"<<endl;

			cout<<endl;
		}
Example #8
0
void ZebulonWindow::genererQTimeSlot(TimeSlot* t){
    QString nameCP, color;
    ClassPeriod *cp = t->GetClassPeriod();
    if(dynamic_cast<TutorialClass*>(cp) != NULL) {
            nameCP = "Tutorial "+QString::number(cp->GetId());
            color = "navy";
            if(!widget.checkBoxTutorial->isChecked()) return;
    }
    else if(dynamic_cast<PracticalClass*>(cp) != NULL) {
            nameCP = "Practical "+QString::number(cp->GetId());
            color = "green";
            if(!widget.checkBoxPractical->isChecked()) return;
    }
    else if(dynamic_cast<MagistralClass*>(cp) != NULL) {
            nameCP = "Magistral "+QString::number(cp->GetId());
            color = "maroon";
            if(!widget.checkBoxMagistral->isChecked()) return;
    }
    
    Date *dit = t->GetStartDate();
    QDate qdts = QDate(dit->GetYear(), dit->GetMonth(), dit->GetDay());

    QString stringGroups = "";
    list<Group*>* l = t->GetClassPeriod()->GetGroupList();
    list<Group*>::iterator it = l->begin();
    list<Group*>::const_iterator MaxList = l->end();
    for(;it != MaxList; it++){
        stringGroups.append(QString::fromStdString((*it)->GetId()));
        stringGroups.append(";");
    }
    
    
    QTimeSlot* time = new QTimeSlot(t->GetId(), qdts, dit->GetHour(), dit->GetMin(), cp->GetDuration(),
            nameCP, QString::fromStdString(t->GetClassroom()->GetId()), QString::fromStdString((cp->GetMomo()->GetId()+" : "+cp->GetMomo()->GetName())), QString::fromStdString(cp->GetTeacher()), stringGroups, NULL);
    time->setBackgroundColor(color);
    this->widget.edt->addTimeSlot(time);
    emit signal_addTimeSlot(time);
}
Example #9
0
bool Date::operator == ( Date d ) const
{
	return m_Year == d.GetYear()   && 
           m_Month == d.GetMonth() &&
 		   m_Day == d.GetDay();
}