0% found this document useful (0 votes)
115 views

CSC280 Preperatory Questions & Answers

Uploaded by

darrielabua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
115 views

CSC280 Preperatory Questions & Answers

Uploaded by

darrielabua
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Preparatory Questions And Answers for CSC280.1 By EmmaRoyal UNIVERSITY OF PORT HARCOURT DEPARTMENT OF COMPUTER SCIENCE FIRST SEMSTERS EXAMS CSC 280.1: COMPUTER PROGRAMMING Use the program segment to answer question 1-4 Interger xy Integer, Dimension (3) 2 Data x.y.2(1),2(3)/2.4,5,2°6/ 1) The value assignedto array element 2(1) is (a)2_ (by (5 (d)6 (a) 12 2). The value assigned to y is ()2 “bya ()5 (dG (2) 12 3) The value assigned to 2(2) is (a2 (ba ()5.*(a) 6 (0) 12 4) The value assigned to 2(2) is (a2 (ea (5 *{a) 6 (0) 12 5) The of an array is an ordered list of its extents (a)Extent *(b) Shape (c)size (d) Dimension (e) Rank 6) Inznarray, the___ of the dimension is the number of element of the specified type in that dimension *(a}Extent (b) Shape (c)Size (d) Matrix (e) Rank 2) The symbol used to implement continuation in Fortran is (2) + (b)!(c) 1! a) & (e) 8) Which of the followingiis not a program debugging technique (a)Brute force (b) backtracking (c) Cause elimination (d) program slicing *(e) None of a,b,c or d 9) An Array with rank2 could be called__*{a)Matrix (b) List c) Subscribt (4) Vector (e) None of ab.cord 10) What contains the data and program during execution of the program by CPU? (a) ALU *(b) Primary Memory (cFlash drive (d) secondary memory (e) UPS For questions 11-14 classify each of the following as either integer constant, real constant, character constant, logical constant or Not Valid 11) RADIUS {a)integer (b) Real *(c) Character (d) Logical (e) Not Valid 12) “3.14159” _(alInteger *{b) Real (c} Character (d) Logical (e} Not Valid 13) False, {a)integer (b) Real (c) Character *(d) Logical (e) Not Vali¢ 14) "485" {alinteger (b) Real (c) Character (d) Logical *{e) Not Valid 15) Which of the following is a primary Fortran programming feature which supports parallel computing (a)Parallel array {b) Syne Array *(c) Coarrays (4) Jpint array (e) None of a,b,c ord 16) In activating a function in an expression, the function name is usually followed by list of Inputs called (a) arrays *(b) arguments (c) constructors (d}comments (e) None of a,b,c or d 17) **is an operator used to implement. in Fortran (a) Addition (bj Subtraction (c) Double Multiplication *(d) Exponentiation (e) None of a,b,c or d 18) Which of the following is NOT a loop construct in Fortran *(a) IF construct (b) Do While construct (c) Case Construct (d) Do Construct (e) None of a,b,c or d Use the following array declaration to answer questions 19-21 INTEGER, DIMENSION (2,3) :: CROSS 19) Array named CROSS has how many dimensions (a]1 *{b)2 (c) 3 (d) 4 (e) 6 20) The size of array CROSSis (a)1 (b)2 (c)3 (d) 4 *{e)6 24) The extent of array CROSS along dimension 2is (a)1 (b) 2 *(c)3 (d) 4 (e) 6 Use the following program segment to answer question 22-24 Integer, Dimension (3,3) :intmatrix Preparatory Questions And Answers for CSC280.1 By EmmaRoyal Doj-3 Intmatrix (hj) =2 End Do 22) By inspection, itis observed that the array named intmatrix is @ (2) 1-dimension array *(b) 2- dimension array (c) 3-dimension array (4) 4-dimension array (e) None of a,b,c or d 23) The Do loops are used to set the values of all the calls to *(a)2 (b) 3 (c) 4 (d) 6 (e)9 24) The size of Intmatrix is (a)2 (b) 3(c) 4 (d) 6 *e) 9 25) Determine the correct array declaration (a) integer, dimension (2,3) : john *(b) integer, dimension (2,3) :: john (0) dimension, integer(2,3) :john (d) dimension, integer(3,4): john (e) None of a,b,c or d 26) Which of the following statement is used to specify the size of an array _(a)array (b) integer *{c) dimension (a) write(e) range 27) Which of these Fortran keywords can be used to cause additional branching within @ Do-Loop (a)EXIT and JUMP (b) EXIT and BRANCH *(c) EXIT and CYCLE (4) JUMB and CYCLE (e) JUMP and BRANCH 28) Which ofthe following flow chart symbols isused to = data processing taf b. « a) wm £7 29) Which is the correct order in which operations are — in an expression, 2 bo © Ty 4 e| ” “ + " + ‘ 4 “ 7 30)__is an example of a input statement. *(a) READ (*,*) “SAM,PIE” (b) WRITE (*,") “SAM, PIE” (c) PRINT. (5) “SAM.PIE” (d) SEND (*,*) “SAM,PIE” (e) INPUT (*,*) “SAM, PIE" B1)A statement indicates exactly how data is laid out ina READ and WRITE statement. (a) FORTRAN (b) variable (c) expression (d) transform *(e) format 32) Which of the following is not a method for assignment values or populating an array? (a) Using Do Loop (b) Using Array Constructors (c) Assignment values to individual members of the array (4) Using array subscripts. *{e) None of ab,cord 33) An array with rank 2 could be called a___*(a)Matrix (b) Ust(c) Subscripts (d} Vectors (e] None of a,b,c or d 34) Which of the following is net a method for assigning values or populating an array (a) Using Do Loop (b) Using Array Constructors (c) Assignment values to individual members of the array (a) Using array subscripts . *(e) None of a,b,c or d For the following segments of FORTRAN code in questions 35-37, determine what values will be stored. 35) CHARACTER (Len=4) : SUB) SUBI= '0C3030° (a}0¢3030 *()0C30——_(c) 3030 (@) Error nothing will be stored (€) None of a,b,cor d 36) INTEGER: 1), KL 123, 128, Ke5; L=k41/3*42 40 (a1 (b)49 ()2_—(d)2.9__—_*Le) Error nothing will be stored 37) REAL:: CDF (C24; D=2 F=¢**2*1 1.06+03/2,0°D (a) 4000 _(b) -4000 (c) 1600 (4) -1600 *(e) Error nothing will be stored 38) The general format for array declaration in Fortran is *(a) Datatype, DIMENSION (a,b,c) :: arrayname (b) DIMENSION, datatype (a,b,c) :: arrayname (c) arrayname, DIMENSION (2,b,¢) :! Datatype (d) Datatype, arrayname:: DIMENSION (2,b,¢) (e) None of a,b,c or d Preparatory Questions And Answers for CSC280.1 By EmmaRoyal 39)_ statement is used to output data in Fortran, (a)FORMAT —(b)SEND-—*{c) WRITE (d) READ —_(e] Noneof a,b,c ord 40) What is the size of an array with DIMENSION (-4:2, 0:2)? (ay20 *(b) 21 (24 (a) 30 (e) None of a,b,c ord 41) an ordely arrangement of similar objects in rows and cclumns, in the form of a matrix, whose objects are of the same size and data type although the objects can have different values. (vector (b)Index—*{e)Array_—(d) Function __(e) None of a,b,cor d 42) In FORTRAN a numeric quantity in an expression that has a fixed value throughout the program is known as (a) Variable (b) Real *(q)Constant (d) Integer (e) String Use the program fragment below to answer question 43-45 Integer I Integer, Dimension (3) :(Maths DATA 1J Maths(2), Maths(2), Maths(3}, /5,3,6,2, 7/ 43) The Value assigned to array element Maths(3) fs (a2 (b)3 (c)5_-*(d)7_—_(e) None of a,b,cor d 44) The Value assigned to lis (a2 (b)3. * (eS (d)7_(e) None of ab,cord 43) The value assigned to Maths(2) is *fa)2_(b)3._(c)5_ (d)7_(@) None of a,b,c ord Use the following program fragment to answer questions 46-50 INTEGER =: TRACKER=4, FACTORIAL= 1 FACTORIAL = FACTORIAL *TRACKER; TRACKER = TRACKER-1. DO WHILE (TRACKER>0) FACTORIAL =FACTORIAL* TRACKER ; TRACKER = TRACKER ~ 1 END DO PRINT *, FACTORIAL 46) How many times will the DO WHILE loop be executed? *{a)3__(b) 4 (c)5_(d)6_(e) None of a,b,c ord 47) What value of TRACKER will terminate the loop? *{a)O_(b) 1 (c)2_(d) 73_(e) None of a,b,c ord 48) What is the final output value for FACTORIAL? (a) 120 (b) 240 (c) 360 (d) 720 *(e) None of a,b,cord 49) The variable TRACKER is declared as (a) integer constant *{b) integer variable (c) real constant _(d) real variable (e) None of a,b,c or d 50) The variable FACTORIAL is declared as *(a) integer constant _(b) integer variable (c) real constant (4) real variable — (e) None of a,b,cord SECTION B: Answer the two questions in the space provided. 1. Write a simple Fortran program to read 10 values into an array and then output the sum of the values. Make generous use of the comment statements to explain your program. 2. Write'a program using functions to calculate either the area OR the volume of a sphere using appropriate control constructs (Hints: Area of a Sphere = 4, Volume of a Sphere =4/3 ANSWER TO SECTION B 1. Program Sum_Array IThis program computes the sum of 10 values using arrays in Fortran Implicit None Real, Dimension (10) Real :: sum | declaration of variables Integer :i sum x dimension of the array Preparatory Questions And Answers for CSC280.1 By EmmaRoyal 10 !Beginning of the loop statement, Read (*,*) (i) linput statement to receive array elements ‘Sum= sum + x(i) !addition of array elements EndDo The end of the loop statement Write (*,*) The End of the loop statement End Program Sum_array Program Areafuncvol This program computes the area and volume of a sphere Using functions and control structures in Fortran Implicit None declaration of variables Integer ::selection Reels: Radius a,b ‘a= Areasphere(radius) b= Volumesphere(radius) ‘write (*,*) “please enter either 1 or 2” I1is to select Area of @ Sphere |2is to select Volume of a Sphere IF (selection ==1) Then ‘Write (*,*) “The Area of the sphere is”, a Else if (selection ==2) Then ‘write (*,*) “The Volume of the Sphere is” b Else Write (*,*) “invalid selection” End if Beginning of the Sub program part CONTAINS Function statement for Area of a Sphere REAL FUNCTION Areasphere (r) Implicit None {Declaration of variables Real:: Areasphere Real, intent (in) =r Real, parameter :: pi=3.142 Areasphere =4*pitr?*2 END FUNCTION Areasphere Ifunction statement for voume of a sphere REAL FUNCTION Volumesphere(r) IMPLICTT NONE !Declaration of variables Reels: Voumnesphere Rea,intent(in) :r Reel,parameter:: pi=3.142 Volumesphere =(4"pi*r?*3)/3 END FUNCTIONALVolumesphere End Program Areafuncvol

You might also like