Computer Science 0411WA 2018 Laboratory Exercise 4 Due: see myCourseLink Arrays,
ID: 3701067 • Letter: C
Question
Computer Science 0411WA 2018 Laboratory Exercise 4 Due: see myCourseLink Arrays, subroutines, modules Submit all parts in a single Word file using the template FOR LAB EXERCISE SET FOUR on myCourseLink Submission instructions are at the start of the Word template file PART I(a) Provide your selections to the following using the form provided as part of the lab submission template FOR LAB EXERCISE SET FOUR posted on myCourseLink sleet% cat e7.190 ! The following progran generates a table of ! values for points (x,y) on a line through (x1,y) and (x2,y2) ! The subroutine line returna the slope and y intercept ! for the line PROGRAM P7 IMPLICIT NONE INTEGER :1-0 REAL::x1-1.0,y1-1.0,x2-4.0,y2-9.0 REAL :: del-.5, x0-1.0,x,y REAL::a1, intercept call line(x1,y1,x2,y21 print (1x,2A10)"."xy do i-1,10 2. print "(1x,2f 10.2)", x x+del x, end do 4, line(x1 , y 1,x2,y2,a,b) real, intent (I):: x1,y1,x2,y2 real, 5 a, b m-(y2-yl)/(x2-x1) end subroutine line END PROGRAM PT sleet% f90 e7.f90Explanation / Answer
PART I(a)
ANSWER FOR BLANK NUMBER 1
(d) s1, intercept
Explanation: s1, intercept passed as parameter to get the values from subroutine
ANSWER FOR BLANK NUMBER 2
(c) s1*x+intercept
Explanation: Will calculate the value of y
ANSWER FOR BLANK NUMBER 3
(c) CONTAINS
Explanation: It separates the main program from subroutine
ANSWER FOR BLANK NUMBER 4
(e) subroutine
Explanation: use to define a subroutine
ANSWER FOR BLANK NUMBER 5
(d) intent(OUT)::
Explanation: It will allow to return the value of m,b from subroutine to s1,intercept in main program
ANSWER FOR BLANK NUMBER 6
(e) y1-m*x1
Explanation: It will calculate the value of b
PART I(b)
ANSWER FOR BLANK NUMBER 1
(a)dimension(3,4)
Explanation: Defining x,y & c array of size 3 rows and 4 columns
ANSWER FOR BLANK NUMBER 2
(a)((x(i,j),j=1,4),i=1,3)
Explanation: For reading values in array x in row order
ANSWER FOR BLANK NUMBER 3
(a)((y(i,j),i=1,3),j=1,4)
Explanation: For reading values in array y in column order
ANSWER FOR BLANK NUMBER 4
(a)maxArr(x,y,c)
Explanation: calling the subroutine maxArr and passing array x,y,c as parameter
ANSWER FOR BLANK NUMBER 5
(a)(a,b,c)
Explanation: a,b,c receiving the parameter
ANSWER FOR BLANK NUMBER 6
(c)do i=1,3
Explanation: Loop for row
Complete program for reference:-
PROGRAM P7
IMPLICIT NONE
INTEGER::i=0
REAL::x1=1.0,y1=1.0,x2=4.0,y2=9.0
REAL::del=.5,X0=1.0,x,y
REAL::s1,intercept
x=x0
call line(x1,y1,x2,y2,s1,intercept)
print "(1X,2A10)", "x","y"
do i=1,10
print "(1X,2f10.2)",x,s1*x+intercept
x=x+del
end do
CONTAINS
subroutine line(x1,y1,x2,y2,m,b)
real, intent(in)::x1,y1,x2,y2
real, intent(out)::m,b
m=(y2-y1)/(x2-x1)
b=y1-m*x1
end subroutine line
END PROGRAM P7
PROGRAM P8
IMPLICIT NONE
integer::i,j
integer,dimension(3,4)::x,y,c
read *, ((x(i,j),j=1,4),i=1,3)
read *, ((y(i,j),i=1,3),j=1,4)
call maxArr(x,y,c)
call prArr(x)
call prArr(y)
call prArr(c)
CONTAINS
subroutine maxArr(a,b,c)
integer, Dimension(3,4), intent(in)::a,b
integer, Dimension(3,4), intent(out)::c
integer ::i,j
do i=1,3
do j=1,4
c(i,j)=max(a(i,j),b(i,j))
end do
end do
end subroutine maxArr
subroutine prArr(x)
integer, Dimension(3,4), intent(in)::x
integer ::i,j
do i=1,3
print "(1X,4I10)",(x(i,j),j=1,4)
end do
end subroutine prArr
END PROGRAM P8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.