Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include "date.h"
- using namespace std;
- string Months[] = { "January", "February ", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
- class Date // Default Class
- {
- private:
- int month;
- int day;
- int year;
- int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- public:
- Date(int m, int d, int y)
- {
- if (m < 1 || m > 12)
- month = 1;
- else
- month = m;
- if (d < 1 || d > DaysPerMonth[month - 1])
- day = 1;
- else
- day = d;
- if (y < 2001)
- year = 2001;
- else
- year = y;
- }
- Date(){
- }
- void printDate1() // Print the Date in 1st style
- {
- cout << this->month << "/" << this->day << "/" << this->year << "\n"; // Display the date in m/d/y
- }
- void printDate2() // Print the Date in 2nd style
- {
- cout << Months[month - 1] << " " << day << ", " << year << endl; // Display the Date in m d, y
- }
- void printDate3() // Print the Date in 3rd style
- {
- cout << day << " " << Months[month - 1] << " " << year << endl; // Display the Date in d m y
- }
- };
- int main()
- {
- int tempMonth = 0;
- int tempDay = 0;
- int tempYear = 0;
- int DaysPerMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- cout << "Hello! This Program will Give You a Certain Date in 3 Different Formats\n\n";
- while (tempMonth < 1 || tempMonth > 12)
- {
- cout << "Month: \n\n";
- cin >> tempMonth;
- cout << endl;
- }
- while (tempDay > DaysPerMonth[tempMonth - 1] || tempDay < 1)
- {
- cout << "Day: \n\n";
- cin >> tempDay;
- cout << endl;
- }
- while (tempYear < 1)
- {
- cout << "Year: \n\n";
- cin >> tempYear;
- cout << endl;
- }
- Date *d = new Date(tempMonth, tempDay, tempYear);
- d->printDate1();
- d->printDate2();
- d->printDate3();
- system("Pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment