1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include<iostream>
#include<cstdlib>
using namespace std;
class DayOfYear
{
private:
int day;
static int Monthday[];
static string Month[];
public:
DayOfYear(int d)
{
if(d <= 0){
cout << "Must be a positive interger!\n";
exit(EXIT_FAILURE);
}
day = d;
}
void print();
};
/*set day for each month*/
int DayOfYear::Monthday[12] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
/*month of the year*/
string DayOfYear::Month[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December"};
void DayOfYear::print()
{
int month = 0;
while(Monthday[month] < day)
month++;
cout << "Day " << day << " would be " << Month[month] << " " << day - Monthday[month-1] << endl;
}
int main()
{
int d;
cout << "Enter the day in the year: ";
cin >> d;
DayOfYear Day(d);
Day.print();
return 0;
}
|