📄 pex3_9.cpp
字号:
#include <iostream.h>
#include <stdlib.h>
#pragma hdrstop
#include "wex3_6.h"
// computes number of days from mm1/dd1 to mm2/dd2 in the year
// determined by the Calendar object c
int DayInterval(Calendar c, int mm1, int dd1, int mm2, int dd2)
{
return c.NumDays(mm2,dd2) - c.NumDays(mm1,dd1);
}
void main(void)
{
int currentyear, currentmonth, currentday, numberOfDays;
char separator;
cout << "Enter a current year: ";
cin >> currentyear;
Calendar cal(currentyear);
cout << currentyear << (cal.Leapyear() ? " is " : " is not ")
<< " a leap year" << endl;
// computer the number of days from Jan. 1 to Christmas in currentyear
numberOfDays = cal.NumDays(12,25);
cal.PrintDate(numberOfDays);
cout << "What is the current date in the format mm/dd? ";
cin >> currentmonth >> separator >> currentday;
// compute number of days from today to Christmas of currentyear
cout << "There are " << DayInterval(cal,currentmonth,currentday,12,25)
<< " days to Christmas." << endl;
// compute number of days from 2/1 to 3/1 in currentyear
cout << "There are " << DayInterval(cal,2,1,3,1)
<< " days from Feb 1 to Mar 1. " << endl;
}
/*
<Run>
Enter a current year: 1995
1995 is not a leap year
Date is 12/25
What is the current date in the format mm/dd? 5/19
There are 220 days to Christmas.
There are 28 days from Feb 1 to Mar 1.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -