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

Write a C++ program that prints the day number of the year, given the date in th

ID: 3581672 • Letter: W

Question

Write a C++ 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-25-2006, 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.

Chapter 6: Functions 1. 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-25-2006, 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 EACHINGU15C. ProgrammingwBook Mar EACHINGW116C. Programming Book Material Enter date in the form: north day-year: 1-1-2016 nter date in the forn month-day-year a7-22-1979 is is day number 1 of the year 2 his is day number 2e3 of the year 1979 rocess returned e (exe) execution tine 11.335 s Process returned e (exe) execution time 5.393 s Press any key to continue. ress any key to continue.

Explanation / Answer

#include<iostream>
#include <climits>
#include<iomanip>
using namespace std;
void getMonthDateYear(int &month , int &day, int &year, char &ch);

int calculateDays(int dayNum);
bool isLeapYear(int year);

int main()
{

int day, month, year, dayNum;
char ch;

getMonthDateYear(month,day,year,ch);

calculateDays(dayNum);

system("PAUSE")

return 0;

}

void getMonthDateYear(int &month , int &day, int &year, char &ch)

{
cout << "Enter a date(mm-dd-yyyy): " << endl;
cin >> month;
cin>> ch;
cin>> day;
cin >> ch;
cin >> year;

}


int calculateDays(int dayNum)
{
dayNum=0;

while (month>1)
{
switch(month-1)
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
dayNum += 31;
break;

case 4:
case 6:
case 9:
case 11:
dayNum +=30;
break;
case 2:
dayNum +=28;

if (isLeapYear(year))

dayNum++
break;
{
month--;
}
dayNum += day;
cout << " The day Number is : " << dayNum << endl;
return 0;
}


bool isLeapYear(int year)
{
if (((year%4 == 0) && (year%100 != 0)) || ((year%100==0)&& (year%400==0)))
return true;
else
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote