Question
All I need is take date from user and display it in 4 forms: Name Format Example Explanation Default M/D/Y 10/4/1998 This will look like
All I need is take date from user and display it in 4 forms:
Name | Format | Example | Explanation |
Default | M/D/Y | 10/4/1998 | This will look like the input from the Input function. Print the month, day, and year as integer values. |
Two-Digit | mm/dd/yy | 10/04/98 | Fixed size format, in which the month, day, and year values are always 2 digits Some values may need to be padded with a leading zero, and year values always show the low 2 digits. |
Long | month D, Y | Oct 4, 1998 | This display format should show the abbreviated month name, then the day, and the full year. Month abbreviations are Jan, Feb, Mar, Apr, May, June, July, Aug, Sept, Oct, Nov, and Dec |
Julian | DDD, Y | 123, 2001 | This displays the Julian Date format. 123 in the Year 2001 is actually May 3rd, 2001. Leading edge zeros are not required. |
Can you tell me what is wrong with my code? #include#include #include using namespace std; const int DEFAULTMONTH=1; const int DEFAULTDAY=1; const int DEFAULTYEAR=2000; class Date { //private members of the class private: int month; int day; int year; char format; static string months[12]; //public members of the class public: //Default constructor Date(); Date(int m, int d, int y); void Input(int &); void Show(); bool Set(int m, int d, int y); int GetMonth(); int GetDay(); int GetYear(); bool SetFormat(char f); void Increment(int numDays = 1); int Compare(const Date &d); string monthHelper(int); }; string Date::months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Date::Date() { month = DEFAULTMONTH; day = DEFAULTDAY; year = DEFAULTYEAR; format = 'D'; } Date::Date(int m, int d, int y) { //to get a valid date if (m < 1 || m > 12 || d < 1 || d > 31 || y < 1583) { month = DEFAULTMONTH; day = DEFAULTDAY; year = DEFAULTYEAR; } else { month = m; day = d; year = y; } format = 'D'; } void Date::Input(int &Pass1) { int d, y; cout<<"Enter Month: "; cin>>Pass1; cout<<"Enter Day: "; cin>>d; cout<<"Enter Year: "; cin>>y; if (Pass1 < 1 || Pass1 > 12 || d < 1 || d > 31 || y < 1583) { cout << "Invalid date entered. Using default date: 1/1/2000"< 12 || d < 1 || d > 31 || y < 1583) { return false; } return true; } int Date::GetMonth() { return month; } int Date::GetDay() { return day; } int Date::GetYear() { return year; } void Date::Increment(int numDays) { int total_days = numDays; while (total_days > 0) { int num_days_in_month = 28; if (month == 2) { if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0)) { num_days_in_month = 29; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { num_days_in_month = 30; } else { num_days_in_month = 31; } if (day + total_days <= num_days_in_month) { day += total_days; break; } else { total_days -= (num_days_in_month - day + 1); day = 1; } if (month == 12) { month = 1; year++; } else { month++; } } } string Date::monthHelper(int Num) { string mth; switch (Num) { case 1: mth = "January"; break; case 2: mth = "February"; break; case 3: mth = "March"; break; case 4: mth = "April"; break; case 5: mth = "May"; break; case 6: mth = "June"; break; case 7: mth = "July"; break; case 8: mth = "August"; break; case 9: mth = "September"; break; case 10: mth = "October"; break; case 11: mth = "November"; break; case 12: mth = "December"; break; } return mth; } int main() { bool status=false; int comparestatus=0; int Pass1; Date date1; date1.Input( Pass1); cout<
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started