Leap year. Write a function bool leap_year(int year); that tests whether a year
ID: 3614087 • Letter: L
Question
Leap year. Write a functionbool leap_year(int year);
that tests whether a year is a leap year: that is, a year with 366days. Leap years are necessary to keep the calendar synchronizedwith the sun because the earth revolves around the sun once every365.25 days. Actually, the figure is not entirely precise, and forall dates after 1580 the Gregorian correction applies. Usuallyyears that are divisible by 4 but is not a century year are leapyears, century years that are not divisible by 400 are not leapyears, century years that are divisible by 400 are leap years.
Write a program to test your leap_year() function with at least oneinput year from each of the following four year types.
1. Non-century non-leap years (e.g., 1995, 1997)
2. Non-century leap years (e.g, 1980, 1984)
3. Century non-leap years (e.g., 1700, 1800)
4. Century leap years (e.g., 2000, 2400)
Explanation / Answer
Can't give you the C++ code but I can give you the algorithm. " If year%400 == 0 leapyear = True elif year%100 == 0 leapyear = False elif year%4 == 0 leapyear = True else leapyear = False " where % means the remainder of the division (i.e 7%3 = 1)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.