Chapter 6 (Objects and Classes) - Questions

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is the purpose of a class definition?

A class declaration describes how objects of a class will look when they are created.

A member function can always access the data a. in the object of which it is a member. b. in the class of which it is a member. c. in any object of the class of which it is a member. d. in the public part of its class.

a

Classes are useful because they a. are removed from memory when not in use. b. permit data to be hidden from other classes. c. bring together all aspects of an entity in one place. d. can closely model objects in the real world.

b, c, d

In a class definition, data or functions designated private are accessible a. to any function in the program. b. only if you know the password. c. to member functions of that class. d. only to public members of the class.

c

Sending a message to an object is the same as _________.

calling one of its member functions

Write a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry().

class leverage { private: int crowbar; public: void pry(); };

A ________ has the same relation to an ________ that a basic data type has to a variable of that type.

class, object

A constructor is executed automatically when an object is ________.

created (defined)

For the object for which it was called, a const member function a. can modify both const and non-const member data. b. can modify only const member data. c. can modify only non-const member data. d. can modify neither const nor non-const member data.

d

The dot operator (or class member access operator) connects the following two entities (reading from left to right): a. A class member and a class object b. A class object and a class c. A class and a member of that class d. A class object and a member of that class

d

True or false: Data items in a class must be private.

false; both data and functions can be private or public

True or false: There is a simple but precise methodology for dividing a real-world programming problem into classes.

false; trial and error may be necessary

Member functions defined inside a class definition are ________ by default.

inline(also private)

Write a member function called getcrow() for the leverage class. This function should return the value of the crowbar data. Assume the function is defined within the class definition.

int getcrow() { return crowbar; }

Assume that the member function getcrow() is defined outside the class definition. Write the declaration that goes inside the class definition.

int getcrow();

Write a getcrow() member function that is defined outside the leverage class definition. Return the value of crowbar.

int leverage::getcrow() { return crowbar; }

Write a statement that executes the pry() function in the lever1 object.

lever1.pry()

Write a statement that defines an object called lever1 of the leverage class.

leverage lever1;

Write a constructor that initializes to 0 the crowbar data, a member of the leverage class. Assume that the constructor is defined within the class definition.

leverage() { crowbar = 0; }

The only technical difference between structures and classes in C++ is that _________.

member functions and data are, by default, public in structures but private in classes

A constructor's name is the same as _________.

the class of which it is a member

If three objects of a class are defined, how many copies of that class's data items are stored in memory? How many copies of its member functions?

three, one

True or false: If you declare a const object, it can only be used with const member functions.

true

True or false: In a class you can have more than one constructor with the same name.

true

Write a declaration (not a definition) for a const void function called aFunc() that takes one const argument called jerry of type float.

void aFunc(const float jerry) const;


Ensembles d'études connexes

Importance of Being Earnest Lines - Algernon

View Set

Module 31: Exemplar C - Obsessive-Compulsive Disorder

View Set

FINA 4310 Final Exam Homework Review

View Set

Lesson 15.1: Mental health promotion

View Set