Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 5 0 / 1 point When designing a class, what is one of the first tasks th

ID: 3828442 • Letter: Q

Question

Question 5

0 / 1 point

When designing a class, what is one of the first tasks that need to be done?

Question options:

Defining the instance variables

Writing the method headers

Specifying the public interface

Adding comments to your program

Question 6

0 / 1 point

Consider the following code segment:

What is the name of the class variable?

Question options:

color

_color

self

_type

Question 7

0 / 1 point

Where is an object's data stored?

Question options:

Global variables

Instance variables

Local variables

Parameter variables

Question 10

0 / 1 point

Which of the following is NOT a pattern used to help design the data representation of a class?

Question options:

An instance variable for thte total is updated in methods that increase or decrease the total amount

An object reference specifies the location of an object

An object can collect other objects in a list

To model a moving object, you need to store and update its position

Question 12

0 / 1 point

What method name is used for a constructor?

Question options:

__begin__

__construct__

__create__

__init__

Question 13

0 / 1 point

Which name would be best for a private instance variable?

Question options:

_confidential

HIDDEN

private

Secret

Question 18

0 / 1 point

How do you access instance variables in a method?

Question options:

Using the constructor

Using the public interface

Using a default value

Using the self reference

Question 19

0 / 1 point

Which of the following patterns can be used for designing your class for a train object that drives along a track and keeps track of the distance from the terminus?

Question options:

Describing the Position of an Object

Modeling Objects with Distinct States

Managing Properties of an Object

Collecting Values

Consider the following class:

Which method creates a new instance variable?

Question options:

click

getValue

reset

unClick

Question 7

0 / 1 point

Consider the following class:

Which line(s) are part of the public interface for the class?

Question options:

Only line 1

Only line 2

Only lines 2 and 3

Only lines 3 and 4

Question 9

0 / 1 point

Consider the following class:

Which method is an accessor?

Question options:

getValue

click

unClick

reset

Question 11

0 / 1 point

Consider the following class:

Which method(s) are mutators?

Question options:

Only reset

Only click and unClick

Only click, unClick and reset

All four methods are mutators

Question 14

0 / 1 point

Consider the following class:

What is output by the following code segment?

Question options:

Bob

Joe

555-000-0000

555-123-4567

Question 16

0 / 1 point

Which method below would be considered an accessor method?

Question options:

Question 17

0 / 1 point

Which statement determines if the middleInit variable is empty or does not refer to any object?

Question options:

Question 18

0 / 1 point

Which of the following statements determines if x currently refers to an object containing an integer?

Question options:

if int(x) :

if x == int :

if x is int :

if isinstance(x, int) :

Suppose you have a class ShoppingList, with instance variables _quantity, _cost, and _itemName. How should you access these variables when writing code that is not contained within the ShoppingList class?

Question options:

Directly access the instance variables by using the object and the instance variables' names.

Use methods provided by the ShoppingList class.

It is not possible to access the instance variables outside of the ShoppingList class.

Use the self parameter followed by the instance variables' names.

Question 7

0 / 1 point

What is the purpose of the self parameter?

Question options:

Enables changes in the implementation without affecting users of a class

To create variables with public visibility

Store the data for all objects created by the same class

Refers to the object on which the method was invoked

Question 11

0 / 1 point

When using the process of tracing objects for problem solving, which types of methods update the values of the instance variables?

Question options:

Accessor methods

Mutator methods

Constructors

Both B and C

Question 12

0 / 1 point

Before invoking a method on an object, what must be done first?

Question options:

Initialize all instance variables

Invoke the accessor and mutator methods

Create a public interface

Construct the object

Question 14

0 / 1 point

Which of the following method headers represent a constructor for an Employee class?

Question options:

Question 15

0 / 1 point

Which of the following statements is not legal?

Question options:

["Hello", "World"].lower()

"Hello, World".lower()

["Hello", "World"].pop()

["Hello, World"].pop()

Question 16

0 / 1 point

Consider the following class:

What line of code should be placed in the blank to complete the getName accessor method that is supposed to return the pet's name?

Question options:

return

return _name

return self

return self._name

Question 19

0 / 1 point

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 20

0 / 1 point

Which method below would be considered a mutator method?

Question options:

A subclass object can always be used when a superclass object is expected. This fact is referred to as:

generalized interoperability

method overriding

the replacement policy

the substitution principle

Question 4

0 / 1 point

Assume that a Programmer class inherits from an Employee class, and that both classes have an implementation of an increaseSalary method with the same set of parameters. Which class's increaseSalary method is to be executed is determined by:

checking whether or not the super function is called in the method body.

the number of instance variables in the class.

the order in which the programmer declared the classes.

the type of the object on which the method is invoked.

Question 6

0 / 1 point

Which method is being overridden in the following code segment?

getMake

getModel

getColor

No method is being overridden in this code segment

Question 7

0 / 1 point

Consider the following code snippet:

If the Programmer class inherits from the Employee class, and both classes have an implementation of the increaseSalary method with the same set of parameters, which statement is correct?

An additional line of code must be added to the snippet shown previously to specify which method will execute.

It is not possible to determine which class's method will be executed without seeing the complete class definitions.

The increaseSalary method of the Employee class will be executed.

The increaseSalary method of the Programmer class will be executed.

Question 8

0 / 1 point

You are creating a class inheritance hierarchy about motor vehicles that will contain classes named Vehicle, Auto, and Motorcycle. Which of the following statements is correct?

Vehicle should be the subclass, while Auto, and Motorcycle should be the default classes

Vehicle should be the subclass, while Auto, and Motorcycle should be the superclasses

Vehicle should be the default class, while Auto, and Motorcycle should be the subclasses

Vehicle should be the superclass, while Auto, and Motorcycle should be the subclasses

Question 10

0 / 1 point

What is the purpose of using an inheritance hierarchy?

To share common code among the classes

To create objects from concrete classes

To create objects from abstract classes

To create objects using constructors

Assuming the Rectangle class is already designed with a constructor __init__(self, x, y, width, height), which code snippet creates a square in the middle of a frame with FRAME_WIDTH = 400, FRAME_HEIGHT = 600?

Question 7

0 / 1 point

Consider the following class hierarchy:

Complete the code in the Auto class constructor to store the type data.

This cannot be done unless the Auto class declares an instance variable named type.

Question 8

0 / 1 point

Which of the following statements indicates that ClassA is a superclass of ClassB?

class ClassB(ClassA) :

class ClassA(ClassB) :

class ClassB extends ClassA :

class ClassA extends ClassB :

Question 10

0 / 1 point

Which of the following statements is true?

A method that is overridden in a subclass can perform a task that is totally different from the task performed by the same method in the superclass.

A method that is overridden in a subclass cannot invoke the method in the superclass with the same name.

A method that is overridden in a subclass must extend the functionality of the superclass by invoking the superclass method.

Every method in a subclass must override a superclass method.

You cannot inherit from this class.

You cannot construct an object from this class.

You can construct an object from this class.

All non-abstract subclasses of this class must implement this method.

Question 6

0 / 1 point

Which of the following statements about abstract methods is true?

An abstract method has a name and parameters, but its implementation is not specified.

An abstract method has parameters and is fully implemented, but it has no defined name.

An abstract method has a name and is fully implemented, but it has no parameters.

An abstract method has only a name, but it implementation is not specified and it has no parameters.

Question 9

0 / 1 point

Which of the following is true regarding subclasses?

A subclass that inherits methods from its superclass may not override the methods.

A subclass that inherits instance variables from its superclass may not declare additional instance variables.

A subclass may inherit methods or instance variables from its superclass but not both.

A subclass may inherit methods and instance variables from its superclass, and may also implement its own methods and declare its own instance variables.

Question 2

0 / 1 point

Consider the following recursive code snippet:

What value is returned from a call to mystery(3,6)

Question 3

0 / 1 point

A palindrome is a word or phrase that reads the same forward and backward. Consider the functions palindrome and isPal shown below:

The function isPal as shown here would be considered to be a ____ function.

iterative

method

helper

static

Question 4

0 / 1 point

Consider the following recursive function:

What is printed for the call myPrint(821)?

10

12

128

821

Question 6

0 / 1 point

Which of the following options could be used as a terminating condition for a recursive function that finds the middle character of a String with any number of characters?

I. the length of the String is 1

II. first and last String characters match

III. the String is not empty

I

II

I, II, and III

I and III

Question 7

0 / 1 point

Why does the best recursive function usually run slightly slower than its iterative counterpart?

Testing the terminating condition takes longer.

Each recursive function call takes processor time.

Multiple recursive cases must be considered.

Checking multiple terminating conditions take more processor time.

Question 8

0 / 1 point

A palindrome is a word or phrase spelled which reads the same forward or backward. Consider the following code snippet:

What does the function palindrome return?

True

False

a palindrome not found exception

the Boolean value returned from the isPalfunction

Question 9

0 / 1 point

Consider the following function:

What will happen if lines #2 and #3 were swapped with lines #4 and #5?

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 10

0 / 1 point

Recursion will take place if any of the following happen:

I. function A calls function B, which calls function C

II. function A calls function B, which calls function A

III. function A calls function A

I

I and II

II

II and III

6 / 10 - D

8 / 10 - B

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.

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)

Question 2

0 / 1 point

Which statement finds all of the links in a webpage?

Question options:

elements = doc.find_all("a")

elements = doc.find_all("li")

elements = doc.find_all(links)

elements = doc.find_links()

Question 3

0 / 1 point

Complete the code for the myFactorial recursive function shown below, which is intended to compute the factorial of the value passed to the function:

Question options:

Question 4

0 / 1 point

Consider the code for the recursive function myPrint shown in this code snippet:

To avoid infinite recursion, which of the following lines of code should replace the current terminating case?

Question options:

The terminating case as shown will avoid infinite recursion

Question 5

0 / 1 point

Consider the function powerOfTwo shown below:

How many recursive calls are made from the original call powerOfTwo(64) (not including the original call)?

Question options:

8

6

4

2

Question 7

0 / 1 point

Consider the following code segment:

This code segment would be classified as:

Question options:

backtracking

mutually recursive

non-recursive

object oriented

Question 10

0 / 1 point

Consider the following code segment:

When this code is run, it will display:

Question options:

0

1

3

7

Question 2

0 / 1 point

Which problem is well suited to being solved with mutually recursive functions?

Question options:

Computing the factorial of a number

Determining if a string is a palindrome

Computing Fibonacci numbers

Evaluating a numeric expression

Question 3

0 / 1 point

A unique permutation is one that is different from any other generated permutation. How many unique permutations does the string "bee" have?

Question options:

2

3

4

5

Question 4

0 / 1 point

Recall the permutations function from Section 11.5 in the textbook.

How permutations will be generated by calling permutations("code")?

Question options:

1

4

10

24

Question 5

0 / 1 point

How many recursive calls to the fib function shown below would be made from an original call to fib(4)? (Do not count the original call)

Question options:

1

2

4

8

Question 7

0 / 1 point

Consider the triangleArea function from the textbook shown below:

What will happen if line #6 is changed to:

Question options:

Infinite recursion will occur when sideLength is equal to 0.

Infinite recursion will occur when sideLength is equal to 1.

Infinite recursion will occur when sideLength is greater than or equal to 2.

Infinite recursion will occur for any value of sideLength.

Question 10

0 / 1 point

Recall the backtracking strategy outlined in the textbook. A similar strategy can be used to solve Sudoku puzzles.

What code should be placed in the blank to complete the solution to this problem?

Question options:

print(status)

print(gameBoard)

solve(gameBoard)

gameBoard = extend(gameBoard)

A particular algorithm visits n3 + nlog(n) + n! elements in order to perform its task on a list of n elements. Which big-Oh expression best describes the growth rate of this algorithm?

Question options:

O(n)

O(n3)

O(n!)

O(nlog(n))

Question 9

0 / 1 point

Which sort algorithm starts with an initial sequence of size 1, which is assumed to be sorted, and increases the size of the sorted sequence in the list in each iteration?

Question options:

insertion sort

selection sort

merge sort

quicksort

Question 10

0 / 1 point

Consider the code for mergeSort shown below, which works correctly:

What would happen if the line mid = len(values) // 2 was replaced with the line mid = len(values) // 4

Question options:

Merge sort would continue to work at the same speed as the original version

Merge sort would continue to work, but it would be slower than the original version

Merge sort would continue to work, and it would be faster than the original

The modified version would not sort the list successfully

Question 5

0 / 1 point

Explanation / Answer

5- First thing to be done while defining a class is defining the instance variables.

6-Name of class variable is _color

7-object data is stored in instance variable

10-An object reference specifies the location of an object, this can not be used as data representation of a class.

18- Private

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote