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

Fortran Date Format: It should include this functions: the program should check

ID: 672460 • Letter: F

Question

Fortran Date Format: It should include this functions:

the program should check for appropriate values for month (between 1 and 12), check for appropriate values for the date (between 1 and 31), including checking for a valid date for each specific month, and ensure that the value for year is between 1970 and 3000 (inclusive). For example, April 31 is not a valid date. Additionally, the program should check for a leap year to see if February has 28 or 29 days for that year

PROGRAM DATE

IMPLICIT NONE

INTEGER :: dateinfo(8), day
CHARACTER(9) :: month, dayname

CALL DATE_AND_TIME(VALUES=dateinfo)
SELECT CASE(dateinfo(2))
CASE(1)
month = "January"
CASE(2)
month = "February"
CASE(3)
month = "March"
CASE(4)
month = "April"
CASE(5)
month = "May"
CASE(6)
month = "June"
CASE(7)
month = "July"
CASE(8)
month = "August"
CASE(9)
month = "September"
CASE(10)
month = "October"
CASE(11)
month = "November"
CASE(12)
month = "December"
END SELECT

day = Day_of_week(dateinfo(3), dateinfo(2), dateinfo(1))

SELECT CASE(day)
CASE(0)
dayname = "Saturday"
CASE(1)
dayname = "Sunday"
CASE(2)
dayname = "Monday"
CASE(3)
dayname = "Tuesday"
CASE(4)
dayname = "Wednesday"
CASE(5)
dayname = "Thursday"
CASE(6)
dayname = "Friday"
END SELECT

WRITE(*,"(I0,A,I0,A,I0)") dateinfo(1),"-", dateinfo(2),"-", dateinfo(3)
WRITE(*,"(4(A),I0,A,I0)") trim(dayname), ", ", trim(month), " ", dateinfo(3), ", ", dateinfo(1)

CONTAINS

FUNCTION Day_of_week(d, m, y)
INTEGER :: Day_of_week, j, k
INTEGER, INTENT(IN) :: d, m, y

j = y / 100
k = MOD(y, 100)
Day_of_week = MOD(d + (m+1)*26/10 + k + k/4 + j/4 + 5*j, 7)
END FUNCTION Day_of_week

END PROGRAM DATE

Explanation / Answer

SELECT CASE (Month) !!Find number of days in a Month
CASE (:0, 13:)
Days_in_month = 0
PRINT *, "Invalid month!!"
CASE (1, 3, 5, 7:8, 10, 12)
Days_in_month = 31
CASE (2) !!February
Days_in_month = 28
IF (MOD(Year,4) == 0) Days_in_month = 29 !!Leap year
CASE DEFAULT !!September, April, June & November
Days_in_month = 30 !! Thirty days hath ...^
END SELECT

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