Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

got stuck on a fortran problem. Need help with questions 4-9 need to know what extra needs to be added for the LHS to check

got stuck on a fortran problem. Need help with questions 4-9
image text in transcribed
image text in transcribed
need to know what extra needs to be added for the LHS to check itself
Objectives Learn about conditional statements Experiment with different data types Tasks 1. Type the following program exactly as shown (statements starting in column 7): ! This program finds the roots of equations of the 2nd degree ! with coefficients a, b and c program Equation implicit none real a, b, c, delta real rooti, root2 integer count -----Prompt and Input print", "Solves ax^2 + bx + C -0" print", "Enter the coefficients a,b,c separated by commas..." read". a, b, c -----Validate ----Find delta delta - b**2 - 4. a. c --Determine Roots if (delta .GT. 0.) then root1 - (-b + sqrt(delta)) / (2. a) root2 - (-b - sqrt (delta)) / 12. - a) count - 2 else if (delta .LT. 0.) then count=0 else rooti - -b / (2. . a) count - 1 end if ---Show Results if (count .EO. 2) then write(", 20)" Equation has two roots: ", root1, ",", root2 else if (count .EQ. 1) then write(,20) Equation has one root: ", rooti else write(", 20) Equation has no real roots!" end it 20 format (lx, A, F10.4, A, F10.4) ---Verify rooti if (count GT. 0) then print", "Verifying the first root by computing the L.H.S. end if end 2. Compile the program as you learned in Lab 1. If any compiler errors are reported, edit the program and fix them and repeat until you get a clean compilation. Experiments These experiments are intended to help you understand the problem and the solution. Take notes, but do not include them in your submission. 1. When run, the program prompts you to enter the three coefficients of an equation of the 2nd degree. To test the program, supply numbers for which you know the correct answer: The equation (x-1)(x-2)-0 obviously has two roots (1 and 2). If you multiply the left- hand-side (LHS) the coefficients to be entered are: 1.-3.2. 2. Re-run the program and test for the other two cases, i.e. when the equation has one (double) root or no (real) roots at all. 3. Test now for non-integer roots; e.g. (x-0.5)(x-1.5)-0. To do 4. We can make the program test itself by having it plug in the found root and evaluate the LHS (it should be zero). Complete the program by having it evaluate the LHS at - root1. Re-run the previous four test cases and observe the printed value of the LHS. More Experiments 5. Supply the input: I. -10, -100. The roots should be around 16 and -6. What is the printed value of the LHS? Why? 6. Repeat the last question after changing real to real. everywhere in the program. What do you observe? Can you explain this? (Hint: change the format F10.4 to, say. F20.15). Is there anything else that should be changed in the program when the data types are changed from real (i.e. single precision) to real 8 (i.e. double precision)? Hint: what about constants? 7. What if the input was: 0, -3,2 ? Explain. To do 8. Modify the program in Question 14 so as to guard against the case encountered in the Question #7. Insert some code under the "Validate" comment to insure that when a 0, the program prints an appropriate error message, e.g. "this is not an equation of the 2nd degree", and does not proceed with its computation. Note: You cannot use an END in the middle of the program, nor can you use a construct that we haven't covered yet. The preceding validation resulted in the program ending when a "bad" input was encountered. A more friendly approach involves outputting the root, if any, of the supplied Ist-degree equation. Modify your program in Question #8 so that it adopts this approach Fallo Fall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 2012 Proceedings Part 2 Lnai 7197

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284892, 978-3642284892

More Books

Students also viewed these Databases questions