OC userin Computer Science·10 Jul 2018Part (b) [2 MARKS] Here is the header, type contract, and description for method log_trip in class Airplane. Add an example that creates an Airplane object, logs a trip of 1000.0 miles, and shows that those miles have been logged. Also write the body of the method. def log_trip(self, num_miles): (Airplane, float) -> None Type Precondition: num_miles > 0.0 Record that the airplane travelled num_miles additional miles.
OC userin Computer Science·10 Jul 20185. Enter the best choice from the list of choices A-W above for what this program displays for (int row = 0; row < height; row+=20) { rect(0, 0, width-row, height-row);
OC userin Computer Science·6 Jul 2018Question 11. [5 MARKS] Each code fragment in the table below operates on list L, which has length k where k is very large - at least in the tens of thousands. For each fragment, give an expression in terms of k for how many times happy! is printed, and circle whether the behaviour is constant, linear, quadratic or something else. Code How many times is happy! printed? Complexity (circle one) for i in range (len (L)): print('happy!') for item in L: print('happy!') constant linear quadratic something else for i in range (len(L)) for item in L[:i]: print('happy!' constant linear quadratic something else # Precondition: len(L) % 10 == 0 i = 0 while i < len(L): print("happy!') i = i + len(L) // 10 constant linear quadratic something else for item in L[1000:2000] : print('happy!' constant linear quadratic something else for item in L[10:] : print('happy!' constant linear quadratic something else
OC userin Computer Science·5 Jul 2018gate/gates to construct an a half 9. It takes adder. a one b. two c three d. four
OC userin Computer Science·6 Jul 20184. 18 marks] Consider the following Scheme code: idefine (eval vi v2) (cora (and (> vl 0) (> V2 C)) (+ vl v2) 2)1 [(or 1> v! 0) (> v2 O)) (max v: v2) [else 'regative-valcos:)) a) [2 marks Write the contract for eval. b) [2 marks) Write a purpose for eval. c) 14 marks Write 4 separate, distinct tests for eval. (check-expect (check-expect (check-expect (check-expoco
OC userin Computer Science·2 Jul 201830. Line 5 (A) temp = fib1+fib2; fib1 = fib2; fib2 = temp; (B) return temp; (C) temp = temp+fib1; fib2=fibi; fib1 = temp; (D) counter ++; (E) return fibi + fib2;
OC userin Computer Science·2 Jul 201810. What is printed at the end of this piece of code? int num; for (num = 1; num <= 10; num++) System.out.println(num); (A) 9 (B) "" (C) 11 (D) This gives a compiler error (E) 10
OC userin Computer Science·29 Jun 20181. In Excel 2010 cell Al contains the formula =MID("12345678", 4, 2). What is displayed in cell A1? a) 56 b) 55 c) 34 d) 45 x e) None of the above
OC userin Computer Science·26 Jun 2018(d) Which variables are in scope at the point given by the comment /* Point 4 */? For each variable you list, indicate whether it is an instance variable, a formal parameter, or a local vari- able.
OC userin Computer Science·25 Jun 201811. Which part of the CPU performs arithmetical, logical, and bit manipulation operations? a) Registers b) ALU X c) Program Counter d) Cache memory e) All of the above
OC userin Computer Science·23 Jun 20185. Add the missing line to the code below so it produces the image shown. int pos = 0; void draw() { rect(pos, pos, 10, 10); translate (10,10); pos = pos + 10; either A or B neither Anor B
OC userin Computer Science·18 Jun 20182. 15 marks Given the following definitions. (defire k 4) (define (gx) (+ xk)) Trace the Scheme expression below. Show all steps, and put one step on each line. You may not need all the lines. (+ (1K2) (- (g 2) (9 k) ) )
OC userin Computer Science·18 Jun 20182. In one or two sentences, explain the differences between the concepts in each of the following pairs. BE BRIEF; overly long answers will be grounds for mark deductions. (a) An if statement and a while statement
OC userin Computer Science·18 Jun 201833. (2 points) Write a static sketch (no draw() or setup() that creates this image. Hint, use rectMode(CENTER), translate, rotoate, and the fact that if w is the width of one square, then the next one nested within it has width sqrt((w/2)*(w/2)*2). You should be able to see how that is derived by remembering the Pythagorean equation and looking at one of the triangles. The sketch is 500x500. One more hint, 45 degrees is the same as PI/4 radians. Although you may have trouble seeing them due to shrinking the image to fit on the page, there are a total of 20 squares in this image.