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

<p><span style=\"font-size: small;\">Write a function which calculates leap year

ID: 3639278 • Letter: #

Question

<p><span>Write a function which calculates leap years. The function prototype is as follows:</span><br /><span>bool leap_year(int year);</span><br /><span>Write the function body which returns true if the year is a leap year and false if the year is not a leap year.</span><br /><span>NOTE: A leap year is defined as any year divisible by 4 with the following exception:</span><br /><span>Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400</span><br /><span>Also note that any year prior to 1582 is not a leap year.</span><br /><span>Your submission should include a fully functional program including a main program that tests your leap_year function.</span><br /><span>Here is what I have so far:</span><br /><strong>#include </strong><br /><strong>// bool leap_year(int year)</strong><br /><strong>// function to check if the given year is a leap year or not</strong><br /><strong>// Input : year : Year which has to be checked</strong><br /><strong>// Output : true if the year is leap year false otherwise</strong><br /><br /><strong>bool leap_year(int year)</strong><br /><strong>{</strong><br /><strong>//First check if the input year is more than equal to 1582</strong><br /><strong>if(year &gt;= 1582)</strong><br /><strong>{</strong><br /><strong>// If the given year is more than equal to 1582</strong><br /><strong>//check if the number is divisible by 4</strong><br /><strong>if(year%4==0)</strong><br /><strong>{</strong><br /><strong>//if the year is divisible by 4 check if it is divisible by 100</strong><br /><strong>if(year%100==0)</strong><br /><strong>{</strong><br /><strong>//if year is divisible by 100 check if it is divisible by 400</strong><br /><strong>if(year%400==0)</strong><br /><strong>{</strong><br /><strong>// if the given year is divisible by 100 and 400 then it is a leap year</strong><br /><strong>return true;</strong><br /><strong>}</strong><br /><strong>else</strong><br /><strong>{</strong><br /><strong>// not a leap year since divisible only by 100</strong><br /><strong>return false;</strong><br /><strong>}</strong><br /><strong>}</strong><br /><strong>else</strong><br /><strong>{</strong><br /><strong>//only divisible by 4 so a leap year</strong><br /><strong>return true;</strong><br /><strong>}</strong><br /><strong>}</strong><br /><strong>}</strong><br /><strong>else</strong><br /><strong>{</strong><br /><strong>// if the given year is prior to 1582 it is not a leap year</strong><br /><strong>return false;</strong><br /><strong>}</strong><br /><strong>}</strong><br /><br /><strong>main()</strong><br /><strong>{</strong><br /><strong>int nFirstYear = 1900;</strong><br /><strong>std::cout&lt;&lt;"The year " &lt;</strong><strong> else</strong><br /><strong>std::cout&lt;&lt;" not Leap Year."&lt;</strong> <br /><strong>int nSecondYear = 2000;</strong><br /><strong>std::cout&lt;&lt;"The year " &lt;</strong><strong> else</strong><br /><strong>std::cout&lt;&lt;" not Leap Year."&lt;</strong> <br /><strong>int nThirdYear = 1504;</strong><br /><strong>std::cout&lt;&lt;"The year " &lt;</strong><strong> else</strong><br /><strong>std::cout&lt;&lt;" not Leap Year."&lt;</strong> <br /><strong>getchar();</strong><br /><strong>}</strong><br />Please tell me if I am on the right track.</p>

Explanation / Answer

please rate - thanks

hope this is good, if not message me. could read the post well

#include <iostream>
using namespace std;
bool leap_year(int year);
int main()
{int year;
cout<<"Enter year: ";
cin>>year;
if(leap_year(year))
     cout<<year<<" is a leap year ";
else
     cout<<year<<" is not a leap year ";     
system("pause");
return 0;
}
bool leap_year(int year)
{if(year%4==0)
    if(year%100==0)
       if(year%400==0)
            return true;
         else
             return false;
     else
         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