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
|
//Day of the Year programming assignment
//by: Andrew A.
#include <iostream>
#include <string>
using namespace std;
class DayOfYear
{
public:
static const int monthdays [];
static const string monthname [];
void print (int);
};
const int DayOfYear::monthdays [] = {31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 365};
const string DayOfYear::monthname [] = {"January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
void DayOfYear::print (int Date)
{
int month = 0;
while (DayOfYear::monthdays [month] < Date)
month = (month + 1) %12;
cout << "The Date you entered reads " << DayOfYear::monthname[month] << " " << Date - DayOfYear::monthdays[month-1] << endl;
};
int main()
{
DayOfYear DatePrint;
int Date;
cout << "Enter a Date..." << endl;
cin >> Date;
if (Date <= 0 || Date > 365)
{
cout << "Please enter 1 ~ 365" << endl;
};
DatePrint.print(Date);
cin.ignore();
cin.get();
return 0;
};
|