// Design a class called Date.
// The class should store a date in three integers : month, day, and year.
// There should be member functions to print the date in the following forms :
// 12 / 25 / 2014
// December 25, 2014
// 25 December 2014
// Demonstrate the class by writing a C++ complete program implementing it.
// Input Validation :
// Do not accept values for the day greater than 31 or less than 1.
// Do not accept values for the month greater than 12 or less than 1.
// a) Use program example Pr13-2.cpp as a template to create your own program.
// b) Use program example 3: Pr13-3.cpp as a template to create your own program.
//
#include <iostream>
#include <string>
using namespace std;
class Date {
private:
int month; int day; int year;
public:
void setDate(int, int, int);
int getMonth() const;
int getDay() const;
int getYear() const;
void print1() const;
void print2() const;
void print3() const;
};
void Date::setDate(int m, int d, int y) { month = m; day = d; year = y; }
int Date::getMonth() const { return month; }
int Date::getDay() const { return day; }
int Date::getYear() const { return year; }
void Date::print1() const { cout << month << "/" << day << "/" << year << endl;}
void Date::print2() const {
string monthNames[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
cout << monthNames[month] << " " << day << ", " << year << endl;
}
void Date::print3() const {
string monthNames[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
cout << day << " " << monthNames[month] << " " << year << endl;
}
int main() {
int mm, dd, yy;
Date myDate;
do { cout << "Enter month (1-12): "; cin >> mm; } while (mm < 1 or mm>12);
do { cout << "Enter day (1-31): "; cin >> dd; } while (dd < 1 or dd>31);
cout << "Enter year: "; cin >> yy;
myDate.setDate(mm,dd,yy);
cout << "Printing in format 1: ";
myDate.print1();
cout << "Printing in format 2: ";
myDate.print2();
cout << "Printing in format 3: ";
myDate.print3();
return 0;
}