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

help with problem number 2 would be greatly appreciated Problem 1: Input data ha

ID: 3730098 • Letter: H

Question

help with problem number 2 would be greatly appreciated

Problem 1: Input data has lines organized as follows: column 1: character code (one of A, B, c, D) columns 2-3: integer (named m) columns 4-8: real value (named r) Write a FORTRAN 90 program which reads this data from the keyboard (use the Unix redirect "with the data file) A sum is found for each code: For code A sum m +r-m For code B sum (m2 + r2)0.5 For code C sum sin(mr) + cos(mr) Ignore code D if it occurs Additionally print neatly formatted output of the data read in. Provide test results for the data file: A 342.44 A-320.16 C-223.99 D 039.86 C 129.69 B-249.06 D 029.90 C 041.57 C-238.37 B-136.53

Explanation / Answer

Answer: See code for problem 2 below:

------------------------------------------

PROGRAM TEST_SUM
   CHARACTER code
   INTEGER m
   REAL r
   REAL sum_code
   INTEGER num
   CHARACTER (LEN=10) file_name
   num = 1
   file_name = "data.dat"
   open(unit=num,file=file_name)
   read(num,*)code,m,r
   CALL CALC(code,m,r,sum_code)
   CALL OUTPUT(code,sum_code)
END

SUBROUTINE CALC(code,m,r,sum_code)
   CHARACTER code
   INTEGER m
   REAL r
   REAL sum_code
   SELECT CASE(code)
       CASE('A')
           sum_code = r**m + r**(-1*m)
       CASE('B')
           sum_code = (m**2 + r**2)**0.5
       CASE('C')
           sum_code = SIN(m*r) + COS(m*r)
       CASE('D')
           sum_code = 0
   END SELECT
   RETURN
END

SUBROUTINE OUTPUT(code,sum_code)
   CHARACTER code
   REAL sum_code
   PRINT *,'Code:',code
   PRINT *,'Sum:',sum_code
   RETURN
END

-------------------------------------------