CS2 chapter 13

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

structure

A C++ class is similar to one of these.

constructor, created

A ________ is a member function that is automatically called when a class object is ________.

data type

A class is a(n) ________ that is defined by the programmer.

only one

A class may have this many default constructor(s).

myCar.accelerate();

Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?

private and public

Examples of access specifiers are the key words:

z is available to code that is written outside the class.

For the following code, which statement is not true? class Point { private: double y; double z; public: double x; };

private

If you do not declare an access specification, the default for members of a class is ________.

attributes, methods

In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________.

data, functions

In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data.

dot operator

Members of a class object are accessed with the ________.

data, functions

Objects are created from abstract data types that encapsulate ________ and ________ together.

subscripts

Objects in an array are accessed with ________, just like any other data type in an array.

the class

The constructor function always has the same name as ________.

None of these

The constructor function's return type is ________. int float char structure pointer

Nothing. Destructors have no return type.

The destructor function's return type is ________.

Identify objects, then define objects' attributes, behaviors, and relationships

The process of object-oriented analysis can be viewed as the following steps:

#ifndef

This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.

private access specifier

This is used to protect important data.

False

True/False: A destructor function can have zero to many parameters.

True

True/False: A private member function is useful for tasks that are internal to the class, but is not directly called by statements outside the class.

False

True/False: Class objects can be defined prior to the class declaration.

True

True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

True

True/False: More than one constructor function may be defined for a class.

False

True/False: More than one destructor function may be defined for a class.

True

True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.

True

True/False: One purpose that constructor functions are often used for is to allocate memory that will be needed by the object.

True

True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.

False

True/False: The constructor function may not accept arguments.

True

True/False: When an object is defined without an argument list for its constructor, the compiler automatically calls the object's default constructor.

True

True/False: When using smart pointers to dynamically allocate objects in C++ 11, it is unnecessary to delete the dynamically allocated objects because the smart pointer will automatically delete them.

True

True/False: Whereas object-oriented programming centers on the object, procedural programming centers on functions.

False

True/False: You must declare all data members of a class before you declare member functions.

False

True/False: You must use the private access specification for all data members of a class.

The program will not compile.

What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() { cout << val << endl; } public: TestClass(int x) {val = x;} }; int main() { TestClass test(77); test.showVal(); return 0; }

77

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) {cout << x << endl;} TestClass() {cout << "Hello!" << endl; } }; int main() { TestClass test(77); return 0; }

Hello!

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) {cout << x << endl;} TestClass() {cout << "Hello!" << endl; } }; int main() { TestClass test; return 0; }

default constructor

When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________.

inline

When the body of a member function is defined inside a class declaration, it is said to be ________.

-> operator

When you dereference an object pointer, use the ________.


Ensembles d'études connexes

rest of the ap chem ms buck questions

View Set

anatomy: heart 2 homework questions

View Set

BIOL 1040: Masteringbiology: Exam 3

View Set

A+ Chapt 00 - Assessment Examine - Intro

View Set

Chapter 16 - Regulating Competition (Antitrust Laws)

View Set

Ophthalmic Optics Boards Review - Dr. Mckee's Notes

View Set

Ch. 12 CNS Depressants and Muscle Relaxants

View Set

5.07 UNIT TEST: Counting and Probability - Part 1

View Set