Comp Sci 2 C++ Test 1 Study Guide

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

This operator may be used to assign one object to another.

=

How many default constructors may a class have?

A class may have only one constructor

When a class declares an entire class as its friend, the friendship status is reciprocal. That is, each class's member functions have free access to the other's private members.

False

This is a special function that is called whenever a new object is created and initialized with another object's data.

copy constructor

When you redefine the way a standard operator works when it is used with class objects, you have ________ the operator.

overloaded

A member function that is declared ________ may not access any non-static data members in the class.

static

If a member variable is declared ________, all objects of that class have access to that variable.

static

This type of member variable may be accessed before any objects of the class have been created.

static

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

structure

Objects in an array are accessed with ________.

subscripts

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

t

A static member function does not need to be called by a specific object of the class.

t

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

t

In object-oriented programming, the object encapsulated both the data and the functions that operator on data.

t

It is possible to declare an entire class as a friend of another class

t

More than one constructor function may be defined for a class

t

The this pointer is a special built-in pointer that is automatically passed as a hidden argument to all non-static member functions.

t

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

t

While a class's member functions may be overloaded, the constructor cannot be overloaded

t

You can use the technique known as member initialization list to initialize members of a class

t

constructor functions are often used for is to allocate memory that will be needed by the object.

t

destructor functions are often used for is to free memory that was allocated by the object.

t

The constructor function always has the same name as

the class

which of the following is automatically called when an object is destroyed

the destructor function

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

#ifndef

A public data member may be declared a friend of a private function.

F

When you overload the << operator you must also overload the >> operator.

F

C++ permits you to overload the sizeof operator and the this pointer.

False

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; }

Hello!

A static member variable can be used when there are no objects of the class in existence

T

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; }

The program runs, but with no output.

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; }

The program will not compile.

Select all that apply. Given the following code fragment, which of the things shown below happen when the statement on line 8 executes? 1 int square(int a) 2 { 3 return a * a; 4 } 5 int main() 6 { 7 int x = 0; 8 x = square(5); 9 cout << x << endl; 10 return 0; 11 } The square function is called and the value 5 is passed as an argument. the square function calculates 5*5 and stores the result, 25, as a temporary value the temporary value is copied (assigned) to the variable x the temporary value is discarded by the system none of these

The square function is called and the value 5 is passed as an argument. the square function calculates 5*5 and stores the result, 25, as a temporary value the temporary value is copied (assigned) to the variable x

When you overload an operator, you can change the operator's original meaning to something entirely different.

True

The constructor function's return type is [ A ] .

[A] None

The destructor function's return type is [ A ] .

[A] Nothing. Destructors have no return type.

A [ A ] is a member function that is automatically called when a class object is [ B ] .

[A] constructor [B] created

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

[A] data [B] functions

Objects are created from abstract data types that encapsulate [ A ] and [ B ] together.

[A] data [B] functions

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

[A] data type

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

[A] default constructor

Each object of a class has its own copy of the class's ________. a.) member functions b.) member variables c.) constructor d.) all of these e.) none of these

b

When a constructor has a member initialization list, the initializations take place

before any statements in the body of the constructor execute

When a member function is defined outside of the class declaration, the function name must be qualified with the ________.

class name, followed by the scope resolution operator

Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr;

defines a Rectangle pointer variable called BoxPtr

Members of a class object are accessed with the

dot operator

A destructor function can have zero to many parameters.

f

A non-static member function may not access a static member variable.

f

Class objects can be defined prior to the class declaration.

f

In C++, if you overload the < operator, you must also overload the > operator.

f

The constructor function may not accept arguments

f

You must declare all data members of a class before you declare member functions

f

You must use the private access specification for all data members of a class.

f

more than one destructor function may be defined for a class

f

This type of function is not a member of a class, but it has access to the private members of the class.

friend

Where are class declarations usually stored?

in their own header files

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

inline

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?

myCar.accelerate();

When a class contains an instance of another class, it is known as ________.

object composition

When you overload an operator, you cannot change the number of ________ taken by the operator.

operands

To overload the + operator, you would write a function named ________.

operator +

An ________ operator can work with programmer-defined data types.

overloaded

This is used to protect important data.

private access specifier

Examples of access specifiers are the key words:

private and public

The type of member function that may be called from a statement outside the class is

public

Which type of member function may only be called from a function that is a member of the same class

public

If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used.

scope

A reason to overload the ________ is to write classes that have array-like behaviors.

square brackets [ ] operator

C++ allows you to redefine the way ________ work when used with class objects.

standard operators

This is a special built-in pointer that is available to a class's member functions.

this pointer

A good reason for overloading an operator is to enable it to ________.

work in its usual way, but with programmer-defined data types


Kaugnay na mga set ng pag-aaral

DSM Fluid & Electrolyte Imbalances

View Set

World History: England: Sparks of Preparation (Unit 7)

View Set

18.10.16. Fizika elektromágneses indukció, generátor, transzformátor

View Set

Eviro. Unit 7 Lesson 3: Surface Water and Groundwater

View Set

Farm & Agribusiness Management CDE

View Set

Maternity Chpt. 5 Sexually Transmitted Infections 5-8

View Set

Criminal Procedure Test 8 note cards

View Set

Principles of Strength and Conditioning 24 questions

View Set