Final Flashcards

1
Q

Which of the following statements is true regarding classes and objects?

A

Member data of a class is in scope inside its member function definitions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For a class called Monster, which of the following is a conversion constructor, enabling automatic type conversions from type Human to type Monster?

A

Monster(Human x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the following would result in a fatal run-time error?

A

Doing the division (x/y), where x and y are integers and y is 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In a class, the typical purpose of a destructor member function is…

A

To do any final clean-up tasks on an object before it is deallocated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following statements about operator overloading is true?

A

Operator overloading cannot be used to create new operator symbols.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following describes an implementation of the composition (‘has-a’) relationship?

A

An object of type Rabbit is declared as member data of class Forest.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Which of the following is not a valid operator overload prototype? (Phrase is a class)

A

bool operator!< (const Phrase& a, const Phrase& b);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which of the following is a function that will only allow an L-value to be passed as a parameter? (Assume that Icon is a class)

A

int Compute(Icon & i) const;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following is the most appropriate declaration of an accessor function for a class called Grade?

A

double GetValue() const;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is a correct way to declare a member function of a class so that it will be guaranteed to not change the member data of the calling object?

A

int Convert(float& x) const;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If a binary operator is overloaded and written as a member function of a class, the function takes one parameter

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The command “g++ -o employee.cpp” invokes the compile stage but not the linking stage of the compilation process.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

An L-value is an expression that represents a modifiable storage location.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A friend of a class has access only to the public section of that class.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A class may have more than one destructor.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Function calls are matched to their definitions during the compiling stage of a program build (not during the linking stage).

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

If a member data variable of a class is declared to be static, then there is only one copy of it that is shared by all objects of the class.

15
Q

A conversion constructor is a constructor that can be called with only one parameter passed in.

16
Q

A constant object may only make calls to const member functions.

17
Q

Every class has a default constructor

18
Q

If pList is an array of pointers to objects of type Politician, then which of the following is syntactically correct call to the Lie() function of the politician class?

A

pList[0]->Lie();

19
Q

Which of the following functions must always exist for a class? (i.e. if you do not create one, the compiler will create one automatically)

20
Q

Which of the following is a correct prototype for the assignment operator overload member function in a class called Book?

A

Book& operator=(const Book &);

21
Q

A function in a derived class that has the same prototype as a function in its base class is said to _____ the base class function

22
Given a pointer declared as voter* precinct; (where voter is a class). How does one dynamically allocate an array of 500 voter objects?
precinct = new voter[500];
23
Which of the following statements correctly de-allocates the dynamic array created in the last question?
delete [] precinct;
24
From inside a member function, the keyword "this" acts as...
A pointer to a calling object
25
If Penguin is a class and p1 and p2 are objects of type Penguin, in which of the following statements or situations is the class' copy constructor NOT invoked?
When p1 is passed into a function by const reference.
26
Given the declaration: double* dptr; Which of the following can be legally assigned into dptr?
The variable numbers, declared as follows: double numbers[10];
27
Suppose Pokemon is an abstract class, and Snorlax is a class that is derived from Pokemon. Which of the following declarations is illegal?
Pokemon pauly;
28
After the following code statements, what will print to the screen? char game[] = {'C', 'h', 'e', 's', 's'}; char buffer[10]; strcpy(buffer, game); cout << buffer;
The word Chess, and possibly some other random characters after.
29
Consider the declaration: virtual double Sing(int x) = 0; Assume this declaration is in a class called Tenor. The "= 0" on this declaration means?
The Sing function will not be defined for the Tenor class.
30
All arrays of type char are considered C-style string.
False
31
The shallow copy is sufficient for an object as long as the object does not have any object or arrays as member data
False
32
The keyword virtual is used to delay the binding of function call to definition so that it's done at run time, instead of compile time.
True
33
The keyword virtual is used to delay the binding of function call to definition so that it's done at run time, instead of compile time.
True
34
If class Z is derived from class D, a pointer of type (D *) can point to an object of type Z
True
35
A protected member function of class X is accessible from class X and from inside any class from which X is derived
False
36
A bit is the smallest unit of storage in a computer
True
37
If ptr is a pointer then *ptr refers to the target of that pointer
True
38
cstring library functions, like strcpy, will protect the caller from overflowing array boundaries on character arrays
False