Question

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

media%2Fec7%2Fec7b6d98-9d3b-4f2c-9401-20

help with problem number 2 would be greatly appreciated

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

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

Add a comment
Know the answer?
Add Answer to:
help with problem number 2 would be greatly appreciated Problem 1: Input data has lines organized...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++. I'm not too sure how to start this. Any help would be appreciated. 1st...

    In C++. I'm not too sure how to start this. Any help would be appreciated. 1st picture is the problem. The 2nd is the data file. Write a routine that reads enrollment data about students in seven colleges for years 2010-2016 from a data file (problem 6.dat) into a 7x7, 2-D array of integers - the file is organized with 7 whole numbers per line, separated by a single space. Your main() should declare/create the array, call the routine to...

  • CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from...

    CODE IN C++ 13.5 Alphabet Histogram Write a program that reads input character by character from the given data file "data.txt" The program should be case insensitive and count the number of occurances of each character in the alphabet. It should print a histogram of the results as follows: A : B : C : * D : * E : * F : G : H : I : J : * K : L : M : N...

  • If you can answer both the questions that would be greatly appreciated. Thank you. 2. A...

    If you can answer both the questions that would be greatly appreciated. Thank you. 2. A monopolist has a cost function given by TC 250+q+.004q2. The inverse market demand for boxes is given by p 8-.0010. The monopolist is currently able to exclude rivals from the market because of a special governmental zoning rule. (a) What is its output and what price does it charge for boxes? (b) Calculate the firm's profit at this output level. (c) Calculate the firm's...

  • Kindly help Asap....correct answers and numbering will be greatly appreciated.. thanks uestion 3 (50 In this...

    Kindly help Asap....correct answers and numbering will be greatly appreciated.. thanks uestion 3 (50 In this problem we are going to implement C modules that implement what is (hopefully) reusable functionality. Each of the modules should make use of abstraction and information hiding where appropriate and include a header file ( .h) and a source code file ( . C). As discussed in class, the header file should define the API for your module. You may model these modules from...

  • use FORTRAN functions to do the partial calculations for the sums AND read the data from...

    use FORTRAN functions to do the partial calculations for the sums AND read the data from the data le named data.dat according to the following speci cations using functions f1 and f2: (1) internal function f1 nds the correct value to sum for devices "A", "B", and "C" (2) external function f2 nds the correct value to sum for devices "D" and "E" A partial FORTRAN 90 program to accomplish the goals of this problem follows: !lab 3(b) solution by...

  • It would be greatly appreciated if you can help to do the followings. Thanks! 1. 2....

    It would be greatly appreciated if you can help to do the followings. Thanks! 1. 2. 3. 4. 5. Suppose that the liquidity effect is immediate and smaller than the other effects, and our expectations of inflation adjust quickly. Referring to the graphs on the right, choose the time path of interest rates from an increase in the growth rate of the money supply that occurs at time T." O A. GraphB O B. Graph A Interest Rate When the...

  • Assume that an imaginary supermarket sells items that are identified by a unique item number which...

    Assume that an imaginary supermarket sells items that are identified by a unique item number which is an integer in range 100 to 499 inclusive. The items are classified in four different categories based on their numbers, and each category defines a different sales tax rate. These four categories along with the range of item numbers included in them, and their specific sales tax rates has been summarized in the following table:    Category Item Numbers Sales Tax Rate A                100...

  • Program Description: A Java program is to be created to produce Morse code. The Morse code...

    Program Description: A Java program is to be created to produce Morse code. The Morse code assigns a series of dots and dashes to each letter of the alphabet, each digit, and a few special characters (such as period, comma, colon, and semicolon). In sound-oriented systems, the dot represents a short sound and the dash represents a long sound. Separation between words is indicated by a space, or, quite simply, the absence of a dot or dash. In a sound-oriented...

  • All help is greatly Appreciated. Thank you. Problem 3-16 Comprehensive Problem [LO 3-1, LO3-2, LO3-4) Gold...

    All help is greatly Appreciated. Thank you. Problem 3-16 Comprehensive Problem [LO 3-1, LO3-2, LO3-4) Gold Nest Company of Guandong, China, is a family owned enterprise that makes birdcages for the South China market. The company sells its birdcages through an extensive network of street vendors who receive commissions on their sales The company uses a job-order costing system in which overhead is applied to jobs on the basis of chrect labor cost. Its predetermined Overhead rate is based on...

  • + Run C Code IMPORTANT: • Run the following code cell to create the input file,...

    + Run C Code IMPORTANT: • Run the following code cell to create the input file, biostats.csv, which you will be using later. 74, In [ ]: N %%file biostats.csv Name, Sex, Age, Alex, M, 41, Bert, M, 42, Dave, M, 39, Elly, F, 30, Fran, F, 33, Jake, M, F, Luke, M, 34, F Myra, M, M, 38, Ruth, F, 28, 22 22 323 47 47, Height, Weight 170 200 167 70 115 143 139 280 98 75, 350...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT