Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef DATE_H // Date.h is the Date class specification file
- #define DATE_H
- #include <iostream>
- #include <string.h>
- #include <iomanip>
- #include <string>
- #include <cstdlib>
- using namespace std;
- //string Months[] = { "January", "February ", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
- // Class Date Declaration
- class Date
- {
- public:
- Date(int m, int d, int y);
- void printDate1();
- void printDate2();
- void printDate3();
- int month;
- int day;
- int year;
- static int DaysPerMonth[12];
- static string Months[12];
- };
- #endif
- // Date.cpp is the Date class function implemetation file.
- #include "Date.h"
- using namespace std;
- int Date::DaysPerMonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- string Date::Months[12] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
- Date::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 < 0)
- year = 2001;
- else
- year = y;
- }
- void Date::printDate1()
- {
- cout << this->month << "/" << this->day << "/" << this->year << "\n";
- }
- void Date::printDate2()
- {
- cout << Months[month - 1] << " " << day << ", " << year << endl;
- }
- void Date::printDate3() //
- {
- cout << day << " " << Months[month - 1] << " " << year << endl;
- }
- #include "Date.h"
- #include <stdio.h>
- using namespace std;
- 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