cs1713_exam1 - It i 7 86 N I CS 1713 Exam 1 — Fall 2006...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: It i 7/ 86 N I CS 1713 Exam 1 — Fall 2006 This is a closed book exam. Answer all questions on these sheets. If you need more room, use the backs. Note that the last problem is worth 20 points so it is important that you work quickly enough to finish the exam. You should have plenty of time as long as you do not spend too much time an any one problem. 1) ( 14 points) Suppose we have: int x = 14; l 7/\ int y = 5; double 2 = 13.0; double w = 4.0; /, Evaluate each of the following expressions. Write you answer in a simplified form. a) x/y Z \/ b)x/w 2.3’ X c) (x+w+z)/y QLHLI o + lio) / { 51-0/5, J (0.1 d) (x+w*z)/y ()Lt +Ll.o’13.o)/ ‘5 |L] + 52.0 Loop/s” 213.7. J e) x%y 4 \I f) x/y+z/y 1+ Gav/S) 2+ 2J0 \/ l-Hc f)(x+z)/y (1H + [303/ 5 270/: J 5.4 2) (15 points) Since the scores on the first exam of Advanced Computer Science were so low, the instructor decided to curve the grades by adding a certain number to each score as shown in the table below. Write a code segment that sets the curved grade, curvedGrade, from the original grade, originalGrade. You can assume that each variable has been declared as an int. You can assume that originalGrade is not negative. Note: you are asked to calculate the curved grade, while the table gives the number of points added. original grade | points added 59 or below 7 in the 60’s l—' 12 in the 70’s 10 in the 80’s 8 90 or above 5 engined Cara324= 5q> CWMDC’ImDes Otia‘nal Grebe. eluittoh 'ma\ Qwabe4‘70) ” UAVVC? olijlncth’lraOL 4- \2 deal (onstmombctm CAM“; Grabt = Griswwtl (flvabt. + )0} d“ (Girl malCfiraM vae Grade, : Oflfllnalélrab 'CDHAOL 7- ) e 4-K) 2W. Cw vac-Car robe. -- 0'! lfyflo‘.‘ Quark 4 g; 3) (7 points) Write a code segment using a do — while loop that continues prompting the user to enter an integer until 3 the value entered is between 0 and 100. After reading in the desired value, print it to the screen. Start with the line: Scanner scan = new Scanner (System. in); K and use the nextInt static method in the Scanner class. 1M umLval: “_, 30$; “AF/ARK :5 560n.v’\€%l\h4(mPv/\~i Vail; Fmr’t 4) (5 points) Write a code segment that declares and initializes an array of 5 doubles with the values: 3.0, 5.1, 7.2, 11.3 and2.4. 3 acubtat] regpmaa Wflqigmzmaaflg) _a\ 5) (5 points) Write a code segment that declares and crea s a array of 100 integers and sets each element of the array 3 to have a value equal to twice its index. f ? 1MB} lest Quota? : new \n‘lhoo @ Sorta/w i=0) u leslfllwaalloma ( ‘) HAIL +€sil3wra82£ijc \ Z‘) 3 6) (14 points) Suppose we have the following declaration: String s = "abgdefg‘llsBCDEI-‘G" ; Find the value of each of the following: a) s.charAt(5); I—CI \/ 5V , J b) s . indexof ( "def ") ; c) s . indexof ( "abC") ; ' d) s . indexof ( "mac-- ) ; ‘7 M“ e) s.1ength(); fl s.substring(5); "abcbe ” X v I/ g)s.substring(2,6); C3913 X 7) (10 points) Write a method that takes an array of doubles as a parameter and returns the index of the smallest value ‘ O stored in the array. If the array has no elements, return -l. ,2 ' “ Qu\9\ \L m 3a Hm ( Emma} ti} (fisl AWOjS, [6,“wa :C) (emvn ’\ '1 yr. ,_ ‘ '13 ink min lrécx : 5‘ E ‘ I ‘ I L «h (min m; \«Aeémva35. WSW/37%; «HM /- /. lg ( 485+ AYIOJS 4 leslz Hvrc\33[ mm |nb¢xj> le‘l \néex : 3 )2 {gmrn mmMD €\< l O 8) (10 points) Write a method that takes an array of integers as a parameter and outputs the values in order on a single line separated commas. There should be one comma and one blanli‘ between entries. For example, if the array elements have they‘values: 2, 4, 6, 8, 10 and 30, the output should be: i 2, 4, 6, 8, .10, 3V0 , p / 3 w? : yo; 5' pr i v.1 r9“ my a C in“; L] +6.9 l-9+*(rc‘-s--: l ' d J 1 A 5x ML. 1/ D 4 Q; [Al/Nil ‘, 2. C) ’1 3r f' "V a ' 1M". if? . ; . V x.“ ’ l a ‘ l ,> ' A -’, ‘ ;\L\c\_+c".,w I Chi,“— ’ if; ~¢ L 113’“ i" ‘1 a H ’ “‘3 L‘] l , i y .. i - V“ , 11b :~*€‘/“W:"“:‘“<\ A 5 L 1 ‘ 3 1 N ‘51 > I, r” ) , A g 3 u l Z L, - < v " f” / \{vx‘ ; QNO double a; double b; doub1e x = double y = double 2; a = x[2]; b = YIl]; System.out.print1n(a Ylll = 7; System.out.print1n(a z = x; XI1] = b; System.out.print1n(a z[0] = 15; System.out.print1n(a x[2] = ylol; System.out.print1n(a x = Y; System.out.print1n(a a = x[0]; System.out.print1n(a (2. 3. {9. Q 0 L145 ‘130 _ 9C 4. 11, 13}; H,O 5}; x[1] x[0] x[2] x[2] x[0] + y[1] + u + YEOJ + " + + II 9) (20 points) Draw an accurate schematic of the program variables showing the execution of the program and determine the output generated. z[ll); z[0]); z[21); z[21); " + z[0]); =_»Vrn OkngXA*_ 7.0 )I o a,Q )E a 1,0 3 : |%_o Q o 0. o tic) ...
View Full Document

Page1 / 6

cs1713_exam1 - It i 7 86 N I CS 1713 Exam 1 — Fall 2006...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online