Question 1 Which statement successfully creates a new Apple object? Question opt
ID: 3829468 • Letter: Q
Question
Question 1
Which statement successfully creates a new Apple object?
Question options:
x = Fruit()
x = Fruit("Apple")
x = Apple()
x = Apple("McIntosh")
Question 2
Given the code snippet below, what methods does an object of the Rectangle class have? class GeometricShape :
def __init__(self, x, y) : self._x = x
self._y = yself._fill = None self._outline = "blue" ...
def getX(self) : return self._x
def getY(self) : return self._y
class Rectangle(GeometricShape) :def __init__(self, x, y, width, height) :
super().__init__(x, y) self._width = width self._height = height
def getWidth(self) : return self._width
def getHeight(self) : return self._height
Question options:
getWidth(), getHeight()
getX(), getY(), getWidth(), getHeight()
getX(), getY(), setColor()
getX(), getY(), getWidth(), getHeight()
Question 3
What object oriented programming concept can often be used to eliminate explicit type tests?
Question options:
Class variables
Encapsulation
Functions
Polymorphism
Question 4
Consider the following class which is used to represent a polygon consisting of an arbitrary number of (x, y) points:class Polygon :
def __init__(self) :
self._x_points = []
self._y_points = []
Which of the following code segments is the correct implementation for the addPoint method that adds another point to the polygon?
def addPoint(self, x, y) :
self._points.append(x, y)
def addPoint(self, x, y) :
self._x_points.append(x)
self._y_points.append(y)
def addPoint(self, x, y) :
self._x_points = x
self._y_points = y
def addPoint(self, x, y) :
self._x_points = [x]
self._y_points = [y]
Question 5
In the following example, which data is considered instance data?
You are assigned the task of writing a program that calculates payroll for a small company. To get started the program should do the following:
Add new employees including their first and last name and hourly wage
Ask for the number of hours worked
Calculate payroll (applying 1.5 for any hours greater than 40)
Print a report of all employees' salary for the week, total of all hours and total of all salaries
Question options:
Question 6
Consider the following function:
1.2.3.4.5.6.What will happen if lines #2 and #3 were swapped with lines #4 and #5?
def mystery(n, if n == 0 : return 0 if n == 1 : return m
m) :# special case 1
# special case 2 return m + mystery(n - 1), m)
What will happen if lines #2 and #3 were swapped with lines #4 and #5?
Question options:
The original function and the modified function will return the same result for all integer values of n and m.
The original function and the modified function will return different results for all integer value of n and m.
The original function and the modified function will return the same result when n is greater than m, and different results when m is greater than n.
The original function and the modified function will return the same result when n is less than m, and different results when m is less than n.
Question 6
Consider the following code segment:
def f1(n) :
if n < 0 :
return 0
if n % 2 == 1 :
return n
return f2(n + 1)
def f2(n) :
if n < 0 :
return 0
if n % 2 == 0 :
return n
return f1(n // 2)
print(f2(7))
When this code is run, it will display:
Question options:
0
1
3
7
The following function is supposed to use recursion to compute the area of a square from the length of its sides. For example, squareArea(3) should return 9.def squareArea(sideLength) :
if sideLength == 1 :
return 1
else :
____________________
What line of code should be placed in the blank to achieve this goal?
Question options:
return squareArea(sideLength - 1)
return 2 * squareArea(sideLength - 1)
return 2 * sideLength + squareArea(sideLength - 1)
return 2 * (sideLength – 1 squareArea(sideLength - 1)
firstName, lastName, hoursWorked, hourlyWage
firstName, lastName, hoursWorked, hourlyWage, payrollAmount
firstName, lastName, hoursWorked, hourlyWage, totalHours, totalSalary
firstName, lastName, hoursWorked, hourlyWage, payrollAmount, totalHours, totalSalary
Explanation / Answer
Solution1:x = Apple("McIntosh").
Reason: apple obect is created with a name to it.
Solution2: getX(), getY(), getWidth(), getHeight().
Reason: as class Rectangle is child class and class GeometricShape is parent class. So child class object can access the functions belongs to its class and the parent class from which it is being inherited.
Solution3: Polymorphism. As in polymorphism the compiler itself does typec checking and call the respective function for a call.
Solution 4:
def addPoint(self, x, y) :
self._x_points.append(x)
self._y_points.append(y)
Reason: As x and y are two lists in the class. So a new point's coordinate will be inserted in the respective lists using function append.
Solution 5:
Reason:Instance variables are those variables a which are assigned when an object is created. So they are different for every object. So these variables are different for every employee.
Solution 6: the answer is 3.
Solution 6: return 2 * (sideLength – 1 squareArea(sideLength - 1)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.