Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Must use a function to compute the day. All cin and cout statements must appear

ID: 3573286 • Letter: M

Question

Must use a function to compute the day.

All cin and cout statements must appear in main(). Has to be in c++. lab 10

Problem write a program that prints the day number of the year, given the date in the form month-day year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12 the day number is 359. The program should check for a leap year. A year is a leap year if it is divisible by 4, but not divisible by 100. For example, 1992 and 2008 are divisible by 4, but not by 100. A year that is divisible by 100 is a leap year if it is also divisible by 400. For example, 1600 and 2000 are divisible by 400. However, 1800 is not a leap year because 1800 is not divisible by 400

Explanation / Answer

#include<iostream>

usingnamespace std;

void noOfDays(int, int, int);

int main()

{

int day, month, year;

cout<<"Please enter month, day and year:"<<endl<<endl;

cin>>month>>day>>year;

noOfDays(day, month, year);

system ("pause");

return 0;

}

void noOfDays(int d, int m, int y)

{

int numDays;

if ((y % 4 == 0) || ( y % 400 == 0))

{

cout<< "The year " << y <<" is a leap year. "<<endl<<endl;

switch (m)

{

case 1:numDays = d;

break;

case 2:numDays = 31 + d;

break;

case 3:numDays = 31 + 29 + d;

break;

case 4:numDays = 31 + 29 +31 + d;

break;

case 5:numDays = 31 + 29 + 31 + 30 + d;

break;

case 6:numDays =31 + 29 + 31 + 30 + 31 + d;

break;

case 7:numDays = 31 + 29 + 31 + 30 + 31 + 30 + d;

break;

case 8:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + d;

break;

case 9:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + d;

break;

case 10:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;

break;

case 11:numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;

break;

case 12: numDays = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;

}

}

else { cout<< "The year " << y <<" is not a leap year. "<<endl<< endl;

switch (m)

{

case 1:numDays = d;

break;

case 2:numDays = 31 + d;

break;

case 3:numDays = 31 + 28 + d;

break;

case 4:numDays = 31 + 28 +31 + d;

break;

case 5:numDays = 31 + 28 + 31 + 30 + d;

break;

case 6:numDays =31 + 28 + 31 + 30 + 31 + d;

break;

case 7:numDays = 31 + 28 + 31 + 30 + 31 + 30 + d;

break;

case 8:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + d;

break;

case 9:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + d;

break;

case 10:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + d;

break;

case 11:numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + d;

break;

case 12: numDays = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + d;

}

}

cout<<"Number of days: " << numDays << endl;

}