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

Write a program that prints the day number of the year, given the date in the fo

ID: 3626595 • Letter: W

Question

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 is12-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 because1800 is not divisible by 400. (Note: This question must be solved using at least one user-defined function.)

Test your program with the following input:

i. 4-5-2008

ii. 12-30-1995

iii. 6-21-2000

iv. 1-31-1500

v. 7-19-1983

vi. 2-29-1976

MY ANSWER(please just fix my code):

#include<iostream>
#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);

return 0;

}

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

{
cout << "Enter a date: " << endl;
cin >> month;
cin>> ch;
cin>> day;
cin >> ch;
cin >> year;

}


int calculateDays(int dayNum)
{
dayNum=0;

while (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;
}


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

Explanation / Answer

please rate - thanks

I think I highlighted everything I changed

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

void calculateDays(int month , int day, int year);
bool isLeapYear(int year);

int main()
{

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

getMonthDateYear(month,day,year,ch);

calculateDays(month,day,year);

return 0;

}

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

{
cout << "Enter a date: " << endl;
cin >> month;
cin>> day;
cin >> year;

}


void calculateDays(int month , int day, int year)
{
int dayNum=0;
month--;
while (month>0)
{switch (month)
{
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;

}


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