Code:
#include <iostream> #include <string> #include <vector>using namespace std;int hashmapping (int mouth) {vector<int> days{31,28,31,30,31,30,31,31,30,31,30,31}; return days[mouth-1];} int isleapyear (int year, int mouth) {if ((year%4 = = 0 && year%100! = 0) | | (year%400 = = 0)) && mouth = = 2) {return hashmapping (mouth) + 1; } return hashmapping (mouth);} int calculatedays (int start_year, int end_year, int start_mouth, int end_mouth) {int days = 0; if (End_mouth >= start_mouth) {if (Start_year < end_year) {for (int i = start_year; I < End_year; i++) {for (int j = Start_mouth, J <=, J + +) days + = Isleapyear (i, j); for (int j = 1; J <= End_mouth; j + +) days + = Isleapyear (i, j); }} else {for (int j = Start_mouth; J <= End_mouth; j + +) days + =Isleapyear (Start_year, J); }} else {for (int i = start_year; i < end_year; i++) {for (int j = Start_mouth; j <= 12; J + +) days + = Isleapyear (i, j); for (int j = 1; J <= End_mouth; j + +) days + = Isleapyear (i, j); }} return days;} string Hashfunc (int days, int week) {vector<string> str{"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}; Return str[(week-1 + days%7)%7];} void PrintWeek (int start_year, int start_mouth, int start_day, int week, int end_year, int end_mouth, int end_day) {str ing we; int days; Switch (week) {Case 1:days = calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_da Y + isleapyear (end_year, End_mouth)-end_day); we = Hashfunc (days, week); Break Case 2:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + isleapyear (end_year, End_mouth)-End_dAY); we = Hashfunc (days, week); Break Case 3:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + isleapyear (end_year, End_mouth)-End_day); we = Hashfunc (days, week); Break Case 4:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + isleapyear (end_year, End_mouth)-End_day); we = Hashfunc (days, week); Break Case 5:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + isleapyear (end_year, End_mouth)-End_day); we = Hashfunc (days, week); Break Case 6:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + isleapyear (end_year, End_mouth)-End_day); we = Hashfunc (days, week); Break Case 7:days = Calculatedays (Start_year, End_year, Start_mouth, End_mouth)-(Start_day + Isleapyear (End_year, End_mouth)-end_day); we = Hashfunc (days, week); Break } cout << start_year << '/' << start_mouth << '/' << start_day << ' ~ ' <&L T End_year << ' << end_mouth << '/' << end_day << ' total: ' << days << ' Day ' << Endl; cout << end_year << "year" << End_mouth << "month" << end_day << "Day is" << we << en DL;} int main () {int start_year, start_mouth, Start_day; int end_year, End_mouth, End_day; Int week; cout << "Please enter the starting year/month/day and Days of the week:" << Endl; Cin >> Start_year; Cin >> Start_mouth; Cin >> Start_day; CIN >> Week; cout << "Please enter end of year/month/day:" << Endl; Cin >> End_year; Cin >> End_mouth; Cin >> End_day; PrintWeek (Start_year, Start_mouth, Start_day, week, End_year, End_mouth, End_day); return 0;}
Operation Result:
C + +-implementation calculation today is xx xx month xx day week x xx years xx month xx days is the day of the week?