Example #1
0
int main(){
//Remember, 1901 was a Tuesday year, so i=2;
i=2;
j=0;

while(done==0){
  if(j==1) {//February has 28 days, and 29 every four years 
  //Check if year is a leap year only if the month is February:
  //We don't need to check 12 times!
    if(year%4==0){
      leap   =1;
      //  Uncomment to print leap years
      //printf("%d \n",year);
    }
    else leap=0;
    while(day<=28+leap){
      if (day==28+leap){
        nextMonth(j);
        break;
      }
      else nextDay(i);
    }
  }
  else if((j==3)||(j==5)||(j==8)||(j==10)){ //April,June,Sept and Nov have 30 days
    while(day<=30){
      if (day==30){
        nextMonth(j);
        break;
      }
      else nextDay(i);
    }
  }
  else { //if it's any other month, 31 days
    while(day<=31){
      if (day==31){
        nextMonth(j);
        break;
    }
      else nextDay(i);
    }
  }
  }//end of while loop
printf("\n%d\n\n",score);
return 0;
}
Example #2
0
int main(void){
   int count = 0;
   struct day* day = malloc(sizeof(struct day));
   day->day = 6;
   day->month = 1;
   day->year = 1901;
   
   do{
      for (int i = 0; i < 7; i++){
         day = nextDay(day);
      }
      if (day->day == 1 && day->year < 2001){
         count++;
      }
   } while (day->year < 2001);
   
   free(day);
   printf("%d\n",count);
}
Example #3
0
int nextMonth(int n){
  if (year<f){
    day=0;
    if (j<11){
      j++;
    }
    else if (j==11) {  //Happy new year!
      j=0;            //Start on January
      year++;         //increment year
      //And if it increments to the final year, stop!
      if(year==f) (done=1);
    }
    nextDay(i);
    //check to see if the week starts on a Sunday:
    if (i==0){
      score++;
    }
  }
  return j;
}
Example #4
0
int main(void){
	int dayMonth = 1;
	int dayWeek = 1;
	int month = 1;
	int year = 1901;
	
	int counter = 0;
	
	while(year < 2001){
		if(dayMonth == 1 && dayWeek == 7){
			counter++;
		}
		nextDayWeek(&dayWeek);
		nextDay(&dayMonth, &month, &year);
		// printDay(dayWeek, dayMonth, month, year);
	}
	
	printf("Result: %d\n", counter);
	
	return 0;
}
Example #5
0
InterstellarClock& InterstellarClock::nextMonth() {
    for (Date i = 0; i < DAYS_IN_MONTH; i++)
        nextDay();
    return *this;
}
Example #6
0
Tools::Tools(bool thisIsABackup, QWidget *parent) : QToolBar(parent) {

	// This variable holds whether the toolbar is used for a backup or not (add and edit buttons disabled for backups)
	this->thisIsABackup = thisIsABackup;

	this->setFloatable(false);
	this->setMovable(false);
	this->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	this->setIconSize(QSize(20,20));

	addBooking = new QToolButton;
	addBooking->setIcon(QIcon(":/images/add.png"));
	addBooking->setText("Add &New");
	addBooking->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	addBooking->setStyleSheet("font-size: 11pt; font-weight: bold");
	addBooking->setFixedHeight(40);
	addBooking->setStatusTip("Add a new booking");
	if(thisIsABackup) addBooking->setEnabled(false);

	editBooking = new QToolButton;
	editBooking->setIcon(QIcon(":/images/edit.png"));
	editBooking->setText("&Edit");
	editBooking->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	editBooking->setStyleSheet("font-size: 11pt; font-weight: bold");
	editBooking->setFixedHeight(40);
	editBooking->setStatusTip("Edit Booking");
	if(thisIsABackup) editBooking->setEnabled(false);

	gotoToday_but = new QToolButton;
	gotoToday_but->setIcon(QIcon(":/images/calendar.png"));
	gotoToday_but->setText("Go to &Today");
	gotoToday_but->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	gotoToday_but->setStyleSheet("font-size: 11pt; font-weight: bold");
	gotoToday_but->setFixedHeight(40);
	gotoToday_but->setStatusTip("Go to Today");

	currentDate = QDate::currentDate();
	gotoPrev = new QToolButton;
	gotoPrev->setIcon(QIcon(":/images/left.png"));
	gotoPrev->setStatusTip("Go to previous day");
	gotoPrev->setFixedSize(50,40);
	gotoPrev->setShortcut(QKeySequence("Alt+Left"));
	gotoNext = new QToolButton;
	gotoNext->setIcon(QIcon(":/images/right.png"));
	gotoNext->setStatusTip("Go to next day");
	gotoNext->setFixedSize(50,40);
	gotoNext->setShortcut(QKeySequence("Alt+Right"));
	curDate = new QToolButton;
	curDate->setStatusTip("Select date from calendar");
	curDate->setText(QDate::currentDate().toString("dddd, dd MMM yyyy"));
	curDate->setStyleSheet("font-size: 11pt; font-weight: bold");
	curDate->setFixedSize(220,40);
	curDate->setPopupMode(QToolButton::InstantPopup);
	curDate->setShortcut(QKeySequence("Alt+C"));

	cal = new QCalendarWidget;
	cal->setMinimumDate(QDate(QDate::currentDate().year()-100,1,1));
	cal->setMaximumDate(QDate(QDate::currentDate().year()+100,12,31));
	cal->setFixedWidth(400);
	cal->setFixedHeight(300);
	cal->setGridVisible(true);
	cal->setStyleSheet("font-size: 12pt; font-weight: bold");
	QTextCharFormat format;
	format.setFontWeight(QFont::Bold);
	format.setBackground(QBrush(QColor(220,220,220)));
	cal->setHeaderTextFormat(format);
	m = new QMenu;
	QWidgetAction *a = new QWidgetAction(m);
	a->setDefaultWidget(cal);
	m->addAction(a);
	curDate->setMenu(m);
	m->installEventFilter(this);

	connect(m, SIGNAL(aboutToShow()), this, SLOT(clickForCalendar()));

	showCancelled = new QCheckBox("Also show cancelled bookings");

	filterAdv = new QToolButton;
	filterAdv->setCheckable(true);
	filterAdv->setText("&Search");
	filterAdv->setIcon(QIcon(":/images/search.png"));
	filterAdv->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
	filterAdv->setStyleSheet("font-size: 11pt; font-weight: bold");
	filterAdv->setFixedHeight(40);
	filter = new CustomLineEdit;
	filter->setStyleSheet("font-size: 11pt");

	this->addWidget(addBooking);
	this->addSeparator();
	this->addWidget(editBooking);
	this->addSeparator();
	this->addWidget(gotoToday_but);
	this->addWidget(gotoPrev);
	this->addWidget(curDate);
	this->addWidget(gotoNext);

	QWidget *separator1 = new QWidget;
	separator1->setSizePolicy(QSizePolicy::Expanding,
				 QSizePolicy::Expanding);
	QWidget *separator2 = new QWidget;
	separator2->setFixedWidth(10);
	QWidget *separator3 = new QWidget;
	separator3->setFixedWidth(10);

	this->addWidget(separator1);
	this->addWidget(filterAdv);
	this->addWidget(filter);
	this->addWidget(separator2);
	this->addSeparator();
	this->addWidget(separator3);


	connect(gotoToday_but, SIGNAL(clicked()), this, SLOT(gotoToday()));
	connect(gotoNext, SIGNAL(clicked()), this, SLOT(nextDay()));
	connect(gotoPrev, SIGNAL(clicked()), this, SLOT(prevDay()));
	connect(cal, SIGNAL(clicked(QDate)), this, SLOT(dateSelected()));

	connect(filter, SIGNAL(textChanged(QString)), this, SIGNAL(setFilter(QString)));

}