程序代写代做代考 python Starting Out with Python 4e (Gaddis)

Starting Out with Python 4e (Gaddis)
Chapter 10 Classes and Object-Oriented Programming

TRUE/FALSE

1. A mutator method has no control over the way that a class’s data attributes are modified.

ANS: F

2. In a UML diagram the first section holds the list of the class’s methods.

ANS: F

3. Object-oriented programming allows us to hide the object’s data attributes from code that is outside the object.

ANS: T

4. Procedures operate on data items that are separate from the procedures.

ANS: T

5. All instances of a class share the same values of the data attributes in the class.

ANS: F

6. All class definitions are stored in the library so that they can be imported into any program.

ANS: F

7. The self parameter is required in every method of a class.

ANS: T

8. A class can be thought of as a blueprint that can be used to create an object.

ANS: T

9. An object is a stand-alone program but is used by programs that need its service.

ANS: F

10. The self parameter need not be named self but it is strongly recommended to do so, to conform with standard practice.

ANS: T

MULTIPLE CHOICE

1. What does the acronym UML stand for?
a.
Unified Modeling Language

b.
United Modeling Language

c.
Unified Model Language

d.
Union of Modeling Languages

ANS: A

2. Which section in the UML holds the list of the class’s data attributes?
a.
first section

b.
second section

c.
third section

d.
fourth section

ANS: B

3. Which section in the UML holds the list of the class’s methods?
a.
first section

b.
second section

c.
third section

d.
fourth section

ANS: C

4. What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method?
a.
accessor

b.
mutator

c.
setter

d.
class

ANS: A

5. The procedures that an object performs are called
a.
methods

b.
actions

c.
modules

d.
instances

ANS: A

6. Which attributes belong to a specific instance of a class?
a.
instance

b.
self

c.
object

d.
data

ANS: A

7. What is the special name given to the method that returns a string containing an object’s state?
a.
__state__

b.
__obj__

c.
__str__

d.
__init__

ANS: C

8. Which method is automatically executed when an instance of a class is created in memory?
a.
__state__

b.
__obj__

c.
__str__

d.
__init__

ANS: D

9. Which method is automatically called when you pass an object as an argument to the print function?
a.
__state__

b.
__obj__

c.
__str__

d.
__init__

ANS: C

10. What type of programming contains class definitions?
a.
procedural

b.
top-down

c.
object-oriented

d.
modular

ANS: C

11. Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes?
a.
a class

b.
an object

c.
an instance

d.
a module

ANS: B

12. Combining data and code in a single object is known as
a.
modularity

b.
instantiation

c.
encapsulation

d.
objectification

ANS: C

13. Mutator methods are also known as
a.
setters

b.
getters

c.
instances

d.
attributes

ANS: A

14. Accessor methods are also known as
a.
setters

b.
getters

c.
instances

d.
attributes

ANS: B

15. When an object is passed as an argument, __________ is passed into the parameter variable.
a.
a copy of the object

b.
a reference to the object’s state

c.
a reference to the object

d.
Objects cannot be passed as arguments.

ANS: C

16. In object-oriented programming, one of first tasks of the programmer is to
a.
list the nouns in the problem

b.
list the methods that are needed

c.
identify the classes needed

d.
identify the objects needed

ANS: C

17. Which is the first line needed when creating a class named Worker?
a.
def__init__(self):

b.
class Worker:

c.
import random

d.
def worker_pay(self):

ANS: B

18. Which of the following will create an object, worker_joey, of the Worker class?
a.
def__init__(worker_joey):

b.
class worker_joey:

c.
worker_joey = Worker()

d.
worker_joey.Worker

ANS: C

COMPLETION

1. A(n) __________ is code that specifies the data attributes and methods for a particular type of object.

ANS: class

2. Each object that is created from a class is called a(n) __________ of the class.

ANS: instance

3. A class __________ is a set of statements that defines a class’s methods and data attributes.

ANS: definition

4. A(n) __________ method in a class initializes an object’s data attributes.

ANS: initializer

5. An object’s __________ contains the values of the object’s attributes at a given moment.

ANS: state

6. A method that returns a value from a class’s attribute but does not change it is known as a(n) __________ method.

ANS: accessor

7. In ___________ programming, the programming is centered on objects that are created from abstract data types that encapsulate data and functions together.

ANS: object-oriented

8. ___________ programming is a method of writing software that centers on the actions that take place in a program.

ANS: Procedural

9. ___________ provides a set of standard diagrams for graphically depicting object-oriented systems.

ANS: UML

10. The instance attributes are created by the __________ parameter and they belong to a specific instance of the class.

ANS: self

Leave a Reply

Your email address will not be published. Required fields are marked *