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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <string>
using namespace std;
#include "Date.h"
Date::Date()
{
//Initialize variables.
int month = 0, day = 0, year = 0;
}
Date::Date(int Month, int Day, int Year)
{
month = Month;
day = Day;
year = Year;
}
void Date::setDay(int d)
{
if (d < 1 && d > 31)
cout << "The day is invalid" << endl;
else
day = d;
}
void Date::setMonth(int m)
{
if (m < 1 && m > 12)
cout << "The month is invalid" << endl;
else
month = m;
}
void Date::setYear(int y)
{
if (y < 1950 && y > 2020)
cout << "The year is invalid" << endl;
else
year = y;
}
void Date::showDate1()
{
cout << month << " /" << day << " /" << year << endl;
}
void Date::showDate2()
{
string monthName[] = { "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December" };
cout << monthName[month - 1] << " " << day << " " << year << endl;
}
void Date::showDate3()
{
string monthName[] = { "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December" };
cout << day << " " << monthName[month - 1] << " " << year << endl;
}
int main()
{
int Month, Day, Year;
string monthName[] = { "January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December" };
cout << "Please enter a month (between 1 - 12) " << endl;
cin >> Month;
cout << "Please enter a day (between 1 - 31) " << endl;
cin >> Day;
cout << "Please enter a year (between 1950 - 2020) " << endl;
cin >> Year;
Date newDate(Month, Day, Year);
newDate.showDate1();
newDate.showDate2();
newDate.showDate3();
cin.get();
cin.get();
system("pause");
return 0;
}
|