Defines a struct variable (including year, month, and day) that requires the input of the year, month, and day, which is the day ordinal of the year.
/** Copyright (c) 2014, Yantai University School of Computer * All right reserved.* Shao * file: demo.cpp* finish: December 16, 2014 * version number: v1.0*/#include <iostream >using namespace std;struct date{int year; int month; int day;}; int main () {date date; cout<< "input year,month,day:"; cin>>date.year>>date.month>>date.day; int days; Calculate days switch (date.month) {case 1:days = Date.day; Break Case 2:days = Date.day + 31; Break Case 3:days = Date.day + 59; Break Case 4:days = Date.day + 90; Break Case 5:days = Date.day + 120; Break Case 6:days = date.day + 151; Break Case 7:days = date.day + 181; Break Case 8:days = date.day + 212; Break Case 9:days = date.day + 243; Break Case 10:days = date.day + 273; Break Case 11:days = date.day + 304; Break Case 12:Days = Date.day + 334; Break } if ((date.year% 4 = = 0 && date.year% 100! = 0) | | (date.year% = = = 0 && date.year 100 = = 0)) {if (date.month>2) days--; } cout<<date.month<< "Month" <<date.day<< "Day is" <<date.year<< "year" <<days< < "day." <<endl; return 0;}
Operation Result:
@ Mayuko
17th Week Item 4-date structure (the day ordinal of the year)