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

Create in programming language of your choice a function called isLeapYear(intYe

ID: 3531844 • Letter: C

Question

Create in programming language of your choice a function called isLeapYear(intYear) that determines if the input year is a leap year or not. Write the main program to calculate the total days passed in a year for a given date. Prompt the user for the (integer) inputs: year, month, and day. The output is the total days passed since Jan 1st of that year excluding the input date (e.g., if the user gives 2012, 01, 23, then the output is 22). Call the function isLeapYear(intYear) to determine if the year is leap or not, if necessary.

Assumption: The user is intelligent enough to enter valid dates only. Example of invalid dates (yyyy/mm/dd): 2001/01/32, 2002/02/29 (2002 is non-leap), 2005/04/31 (April has only 30 days), etc. Tackling invalid dates is for Project #1. However, if you insist to deal with invalid dates in this HW, it will worth maximum 10 extra pts, by creating another function to check the validity of the input date before calculating the total days passed. Name the function isValidDate(intYear, intMonth, intDay).
For checking: Use built-in function DateDiff in VB to check your work. Note that the function DateDiff must be used for checking ONLY.

Expected I/O:
Enter year: 2012
Enter month: 3
Enter day: 15
Total days passed in 2012 before 3/15 = 74 days.

Explanation / Answer

function [ status ] = isLeapYear( year )

if mod(year, 4) == 0

status = true;

if mod(year, 100) == 0

status=false;

if mod(year,400)==0

status = true;

end

end

else

status=false;

end





clear

year = input('Enter year: ' );

month = input('Enter month: ');

day = input('Enter day: ');


if isLeapYear(year) = True

numdays = [31,29,31,30,31,30,31,31,30,31,30,31];

else

numdays = [31,28,31,30,31,30,31,31,30,31,30,31];

end


n = month - 1;

m = day - 1;

sum = 0;

for i=1:n

sum = sum + numdays(i);

end


totaldays = sum + m;

X = ['Total days passed in ', year, ' before ', month , '/', day, ' = ', totaldays];

Disp (X);

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