cisc181 introduction to computer science dr. mccoy lecture 19 clicker questions november 3, 2009

38
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Upload: sheena

Post on 09-Jan-2016

13 views

Category:

Documents


0 download

DESCRIPTION

CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009. If a class is named MyClass , what must theconstructors be named? Initializer MyClass Any name the programmer wishes except the name of the class ~ MyClass None of the above. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

1

CISC181 Introduction to Computer Science

Dr. McCoy

Lecture 19Clicker QuestionsNovember 3, 2009

Page 2: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

If a class is named MyClass, what must theconstructors be named?

(a) Initializer

(b) MyClass

(c)Any name the programmer wishes except the name of the class

(d)~MyClass

(e)None of the above.

2

Page 3: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Referencing elements outside the array bounds

(a) can result in changes to the value of an unrelated variable

(b) is impossible because C++ checks to make sure it does not happen

(c) is a syntax error

(d) enlarges the size of the array

3

Page 4: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/False

Pointer variables are just memory addresses and can be assigned to one another without regard to type.

4

Page 5: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/False

Pointer variables are just memory addresses and can be assigned to one another without regard to type.

Answer: False

Explanation: A pointer variables, like everything else in C++ is typed, and that typing is enforced strongly. A pointer variable of type double* cannot normally hold a pointer value of type int* for example.

5

Page 6: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Strings cannot

(a) be initialized using string literals

(b) grow or shrink dynamically

(c) be initialized with initializer lists

(d) be treated as arrays of characters

6

Page 7: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Three of the following expressions have the same value. Which of the following’s

value is different from the others?

(a) *&Ptr

(b) &*Ptr

(c) *Ptr

(d) Ptr

7

Page 8: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

An array name is

(a) a nonconstant pointer to nonconstant data

(b) a nonconstant pointer to constant data

(c) a constant pointer to nonconstant data

(d) a constant pointer to constant data

8

Page 9: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

A class may contain multiple constructors if

(a) they have different names.

(b) they have different argument lists.

(c) they have the same argument list.

(d) they have different return types.

9

Page 10: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Classes do not have the property of

(a) encapsulating data.

(b) information hiding.

(c) containing both data and functions.

(d) usually knowing how other classes are implemented.

10

Page 11: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Assuming that t is an array and tPtr is a pointer to that array, what expression

refers to the address of the fourth element?

(a) *( tPtr + 3 )

(b) tPtr[ 3 ]

(c) &t[ 3 ]

(d) *( t + 3 )

11

Page 12: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following is not true of a constructor and destructor of the same class?

(a) they both have same name aside from the tilde (~) character.

(b) they are both called once per object (in general).

(c) they both are able to accept default arguments.

(d) both are called automatically, even if not defined in the class.

12

Page 13: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following is not a valid way to pass arguments to a function in C++?

(a) call-by-reference with reference arguments

(b) call-by-value

(c) call-by-reference with pointer arguments

(d) call-by-value with pointer arguments

13

Page 14: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

In the following program segment

#ifndef X

rest of program

#endif

(a) will evaluate the rest of the program if X is already defined.

(b) will evaluate the rest of the program if X is not already defined.

(c) will evaluate the rest of the program regardless of whether X is defined.

(d) will cause a syntax error.14

Page 15: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

The get and set functions of a class

(a) are implicitly defined in the class.

(b) are private member functions.

(c) cannot modify private data.

(d) must be implemented by the programmer.

15

Page 16: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Member access specifiers (public and private) can appear

(a) in any order and multiple times.

(b) in any order (public first or private first) but not multiple times.

(c) in any order and multiple times, if they have brackets separating each type.

(d) outside a class definition.

16

Page 17: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following is false about a function being passed an array?

(a) it knows the size of the array it was passed

(b) it is passed the address of the first element in the array

(c) it is able to modify the values stored in the array

(d) the array name is passed as an argument

17

Page 18: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following operations does not produce a string?

(a) char string1[] = “test”;

(b) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’, ‘\0’ };

(c) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’ };

(d) char string1[] = “ ”;

18

Page 19: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Comparing pointers and performing arithmetic on them is meaningless unless

(a) they point to members of the same array

(b) you are trying to compare and perform arithmetic on the values to which they point

(c) they point to arrays of equal size

(d) they point to different locations

19

Page 20: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

A default constructor

(a) is a constructor with all default arguments

(b) is the constructor generated by the compiler when one is not provided by the programmer

(c) does not perform any initialization

(d) both (b) and (c)

20

Page 21: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

What value does function mystery return when called with a value of 4?

int mystery ( int number ) {

if ( number <= 1 )

return 1;

else

return number * mystery( number – 1 );

}

(a) 1

(b) 24

(c) 0

(d) 421

Page 22: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/False

There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new.

22

Page 23: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/FalseThere should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new.

Answer: True

Explanation: Pointer variables are usually local variables. Memory allocated on the free store using the new operator remains allocated whether you use it or even have a pointer pointing to it. If the pointer that points to the allocated memory dies with the end of a function or a block, the memory allocated is locked away so that no one can use it until the program terminates.

23

Page 24: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

All of the following could cause a fatal execution-time error except

(a) dereferencing a pointer that has not been assigned to point to a specific address

(b) dereferencing a pointer that has not been initialized properly

(c) dereferencing a 0 pointer

(d) dereferencing a nonpointer

24

Page 25: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Classes cannot

(a) be derived from other classes.

(b) initialize data members in the class definition.

(c) be used to model attributes and behaviors of objects.

(d) include objects from other classes as members.

25

Page 26: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following is not a property of structs?

(a) structs reserve space in memory when they are defined.

(b) structs are built using elements of other data types.

(c) Members of a struct must have unique names.

(d) Structure variables are declared like other variables, except the structure name is used

as the type.

26

Page 27: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

• Member function definitions• (a) always require the binary scope operator (::).• (b) only require the binary scope operator when

being defined outside of the scope of• their class.• (c) can use the binary scope operator anywhere,

but become public functions.• (d) must use the binary scope operator in their

function prototype.

27

Page 28: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to

(a) int a

(b) int &a

(c) int * a

(d) int * const a

28

Page 29: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

By default, class variables declared without an access modifier

(a) can be modified by functions outside the class.

(b) cannot be modified except by private functions of other classes.

(c) can only be modified by private functions inside that class.

(d) can be modified by any function inside that class or by friends of the class.

29

Page 30: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

A recursive function is a function that

(a) returns a double

(b) takes 3 arguments

(c) calls itself

(d) is inside of another function

30

Page 31: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to?

(a) 2003

(b) 2006

(c) 2012

(d) 202431

Page 32: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

The type of function a client would use to check the balance of his bank account would be

(a) an access function.

(b) a predicate function.

(c) a utility function.

(d) a constructor.

32

Page 33: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Which of the following can have a pointer as an operand?

(a) ++

(b) *=

(c) %

(d) /

33

Page 34: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/False

The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*)double* p1, p2, p3;

34

Page 35: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

True/FalseThe declaration below declares three pointer

variables of type pointer to double that is, a pointer of type (double*)double* p1, p2, p3;

Answer: False

Explanation: This declares one pointer variable, p1, and two double variables, p2 and p3. The * binds more closely to the variable, not to the type. In spite of this, the usually style puts the asterisk against the type.

35

Page 36: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Pointers may be assigned to which of the following?

(a) all integer values

(b) an address

(c) NULL

(d) both (b) and (c)

36

Page 37: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

Constructors are not

(a) required to be explicitly defined.

(b) called automatically when an object is initialized.

(c) able to be overloaded.

(d) member functions.

37

Page 38: CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

A pointer can not be assigned to

(a) another pointer of the same type

(b) a pointer to void

(c) a pointer of a type other than its own type and void

(d) any other pointer by using the cast operator

38