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.
OC userin Computer Science·14 Jun 2018Section 3 - Programming Questions 7. Role playing video games (RPGs) form a loosely defined genre of video games in which the player controls a small number of game characters. These characters form a group of adventurers whose purpose is to fulfill one or many quests. A common feature of RPGs is that the group of adventurers can collect various items and keep them for future me, sach items are added to the player's inventory. In this question, you will write classes which could be used to manage a player's inventory in an RPG. Part 1 Write a class called Item. An Item object represents an entire category of items carried by a group of adventurers, and each Item object has the following attributes: • The description of the items in this category (a String) The quantity of tems in this category that the group of adventurers is currently carrying can int). For example, suppose the group of adventurers is carrying 50 Heal Potions and 10 Life Potions. The SO Heal Pations would he represented by a single Item object, the value of the description attribute of this item object would be the string "Heal Potion, and the value of the quantity attribute of this Item object woukl be 50. The 10 Life Potions would also be represented by a single Item object, which is different from the Ttem object representing the Heal Potions. The value of the description attribute of this second Ttem object would he Life Potion", and the value of the quantity attribute of this second liem object would be 10. The Item class MUST provide the following INSTANCE methods, note that in the method descrip tions below, the phrase "this Item" means the item on which the method in question is called • A constructor, which takes as its only parameter a string representing the description attribute of the newly created Item. This constructor sets the quantity attribute of the newly created Item to 1. • A method called get Description(), which takes no parameters and returns a string representing the value of the description attribute of this Item • A method called getQuantity O. which takes no parameters and returns an int represent ing the value of the quantity attribute of this Item • A method called set Quantity), which takes a value of type int as its only parameter and returns nothing. This method changes the value of the quantity attribute of this Item so that its new value is equal to the int value this method accepts as parameter, this happens regardless of what the value of the int parameter is, even if it represents a sensical value Note that you MUST respect proper encapsulation practices that is, the attributes and methods of your class MUST he declared using the proper visibility modifiers. Part 2 Write a class called Inventory, which represents the inventory of a group of adventures. An Inventory object has only one attributes a collection of items, which specifies all the types of items that a group of adventurers is currently carrying along with the mumber of items of each type that the group is carrying Inventory objects MUST keep track of the items being carried by adventurers using a PLAIN ARRAY of Items, you MUST NOT se ArrayLists (or any other class which is part of the the Java Collection Framework such as Linkedin.ist) within the Inventory class under ANY circumstances. Each position in the array contains cither • The address of an Item object in memory, an Item is considered to be in the Inventory if and only if its address in memory is stored in the array . null Fach Item object in the inventory MUST appear exactly once in this array, in other words, there MUST NOT be any duplicate elements in the array under ANY circumstances, whether these dupli cates are deep copies or aliases The Inventory class MUST provide the following INSTANCE methods, note that an actual im plementation used in an RPG would provide additional methods, in particular methods to add an item to the Inventory. Also note that in the method descriptions below, the phrase "this inventory" means "the Inventory on which the method in question is called • A constructor, which takes a value of type int as its only parameter, and initializes the newly created Inventory so that the number of item types it can store is equal to the value of the parameter. The number of item types which can be stored in the Inventory is fixed during instantiation, and can never change during the lifetime of the Inventory object • A method called get.Capacity (), which takes no parameters and returns a value of type int representing the capacity of this Inventory (that is, the number of different item types which can be stored in this Inventory). • A method called getItem(), which takes a value of type int as its only parameter, and returns the Item Nered at the commenpanding position in the array holding the Items stond in this Inventory, this method returns null if the element at the position specified by the parameter value is null or if the parameter represents an invalid index in this array. • A method called consumeOne(), which takes as its only parameter a string represent ing the description of an item, and returns a value of type boolean. The method searches the inventory for an item whose description is equal to the parameter String, with the comparison being performed in a case-INSENSITIVE manner. If no such Ttem exists in the inventory, the method returns false, and the state of the Inventory does not change. On the other hand, if such an Item exist in the inventory, the method returns true and modifies the state of the Inventory as follows: -If the quantity attribute of the item is greater than or equal to 2, then its value is reduced by 1. -If the quantity attribute of the Item is equal to 1, then the item is removed from the Inventory. Note that removing an Item can be done by simply assigning null to the amay position that contains it. The state of the array before and after calling this method can consist of addresses of Item objects interspersed with null elements. For example, in an Inventory whose capacity is 20, it is possible that the array contains the addresses of Item objects al positions 3 and 17. while the other amay position contains null. This implies that the method does NOT have to "compact the array so that the addresses of all the actual tem objects appear at the beginning of the array while all the null elements appear at the end. You MAY assume that the string parameter is not null; in other words, your method does not have to handle cases in which the string parameter is indeed null Akmal notes • You MUST respect proper encapulation practices, that is the attributes and methods of your class MUST be declared using the proper visibility modifiers. • Y MUNT call the methods you were asked to write in the previous part to retrieve the descrip tion and quantity attributes of an Item object, or to change the quantity attribute of an Item object. You MAY me that the item class has been implemented correctly, even if you did not successfully complete the previous part WRITE YOUR Inventory CLASS IN THE SPACE BELOW: