Question: Write a program that accepts a date in the format MM-DD-YYYY from the user and determines and displays the day number 1-366 for the day

Write a program that accepts a date in the format MM-DD-YYYY from the user and determines and displays the day number 1-366 for the day of the year corresponding to the entered date. For an entered date of 05-31-1999, the program should display the message May 31, 1999, is day number 151. Your program should account for leap years. In leap years February has 29 days. In non-leap years February has 28 days. A year is a leap year if it divisible by 4, but not by 100 or if it is divisible by 400. Your program must include a function named isLeapYear that takes an integer corresponding to a year as its only argument and returns the Boolean value true if the year is a leap year and false if the year is not a leap year. i.e. The function must implement the following prototype: bool isLeapYear (int year); In addition, your program must include at least two other meaningful called functions (in addition to main and isLeapYear. It can contain more than two. Remember every function definition must be preceded by a comment that tells what the function does, the arguments it takes, and the values it returns (if any). Your program must use at least one switch statement in a meaningful way

Enter a date [MM-DD-YYYY]: 01-03-1985 January 3, 1985, is day number 3.

. Sample Output 2: Enter a date [MM-DD-YYYY]: 06-03-1992 June 3, 1992, is day number 155.

Sample Output 3: Enter a date [MM-DD-YYYY]: 09-31-2017. Error, invalid day 31 entered. Please run the program again with a valid date.

********************************************************* This is my program, I'm just having difficulty understanding how to fit in the function for the invalid date*****************************

#include

using namespace std;

bool isLeapYear(int year) //bOOL VARIABLE where calculations to determine whether its a leap year or not are done {

// (!(year % 100 && year % 4 || year % 400)); if ((year % 4 == 0) && (year % 100 != 0)) //calculations on every 4 years since its leap year with module to get remainder, if remiander then it is not { //leap year

return 1; } else //if else statement to get true or false based on the year given { return 0; } }

//************************************** //Days of year function determines the days in a year depending if leap year or not based on subtracting the days in a year from the days in a month //Also the month names are here connected to the month number for example, if 1 then we will get january and so on.

int daysOfYear(int month, int years, int days) { string monthName; int dayYear;

if(isLeapYear(years)) //to determine whether febraury has 28 or 29 days based on calling bool function from earlier { dayYear = 366;

} else { dayYear = 365; //bool leapDay = isLeapYear(years); }//if (isLeapYear

switch(month) //switch stament gives us the amount of days in a year based on input given { //case number is based on month, and days based on the days inputed to get 'dayYear' which is amount of days in a year case 1: //Month January monthName = "January";

if(isLeapYear(years)) //to determine whether febraury has 28 or 29 days based on calling bool function from earlier { dayYear -= (366 - days);

} else { dayYear -= (365 - days); } break;

case 2: //Month February monthName = "February";

if(isLeapYear(years)) //to determine whether febraury has 28 or 29 days based on calling bool function from earlier { dayYear -= (335 - days);

} else { dayYear -= (334 - days); //bool leapDay = isLeapYear(years); }//if (isLeapYear break;

case 3: //Month March monthName = "March"; dayYear -= (306 - days); break;

case 4: //Month April monthName = "April"; dayYear -= (275- days); break;

case 5: //month May monthName = "May"; dayYear -= (245 - days); break; case 6: monthName = "June"; dayYear -= (214 - days); //month june break; case 7: monthName = "July"; dayYear -= (184 - days); break;

case 8: //Month August monthName = "August"; dayYear -= (153 - days); break;

case 9: //September monthName = "September"; dayYear -= (122 - days); break; case 10: //Month of october monthName = "October"; dayYear -= (92 - days); break; case 11: //Month of November monthName = "November"; dayYear -= (61 - days); break; case 12: //Month of December monthName = "December"; dayYear -= (31 - days); break;

return dayYear;

}

void invalidDate(int month, int days, int years)

if (month > 12) { cout << "Error, invalid month " << month << " entered. "; cout << "Please run the program again with a valid date. ";

} if (days < 1 || days > 31) { cout << "Error, invalid day " << days << " entered. "; cout << "Please run the program again with a valid date. "; } if (years > 9999 || years < -0) { cout << "Error, invalid year " << years << " entered. "; cout << "Please run the program again with a valid date. ";

}

//*************************************Function #3 **************************************************************************** //This function determines whether months, days, years is invalid and outputs it, whatever is given that is invalid

int main()

{ int month, days, years; cin >> month >> days >> years; cout << "Enter a date [MM-DD-YYYY]: " << month << "-" << days << "-" << years << endl;

if (month > 12) { cout << "Error, invalid month " << month << " entered. "; cout << "Please run the program again with a valid date. ";

} if (days < 1 || days > 31) { cout << "Error, invalid day " << days << " entered. "; cout << "Please run the program again with a valid date. "; } if (years > 9999 || years < -0) { cout << "Error, invalid year " << years << " entered. "; cout << "Please run the program again with a valid date. ";

} else {

isLeapYear(years); daysOfYear(month, years, days); }

cout << monthName << " " << days << ", " << years << " is day number " << dayYear << endl; //output if date inputed in valid to the compiler. Of course dayYear is the days in a year

// daysOfYear( month, years, days);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!