CSCI CH 8-11, 13-14 final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

3) True/False: In C++ 11, the nullptr key word was introduced to represent the address 0.

TRUE

3) True/False: In the average case, an item is just as likely to be found near the beginning of an array as near the end.

TRUE

16) What will the following statement output? cout << &num1; A) The value stored in the variable called num1 B) The memory address of the variable called num1 C) The number 1 D) The string "&num1" E) None of these

B

20) This type of member function may be called only from a function that is a member of the same class. A) public B) private C) global D) local E) None of these

B

21) A structure ________ contain members of the same data type. A) cannot B) can C) shouldn't D) None of these

B

27) Every byte in the computer's memory is assigned a unique ________. A) pointer B) address C) dynamic allocation D) name E) None of these

B

14) Before a structure can be used, it must be ________. A) declared B) dereferenced C) initialized D) All of these E) None of these

A

17) A function ________ return a structure. A) may B) may not C) will always D) cannot possibly E) None of these

A

18) A structure pointer contains ________. A) the address of a structure variable B) the dereferenced address of a structure tag C) the name and address of the structure tag D) the address of a structure tag E) None of these

A

19) Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr; A) The value stored in the variable whose address is contained in ptr. B) The string "*ptr". C) The address of the variable stored in ptr. D) The address of the variable whose address is stored in ptr. E) None of these

A

19) When you dereference an object pointer, use the ________. A) -> operator B) <> operator C) dot operator D) & operator E) None of these

A

20) If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do? cout << *a.p; A) Output the dereferenced value pointed to by p. B) Result in a compiler error. C) Output the address stored in p. D) Output the value stored in a. E) None of these

A

21) Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer. A) multiply, divide B) add, subtract C) +=, -= D) increment, decrement E) None of these

A

24) A good reason to pass a structure as a constant reference is ________. A) to prevent changes to the structure members B) to ensure changes to the structure members C) to slow down the function's execution, preventing errors D) to speed up the function's modification of the structure members E) None of these

A

24) Objects in an array are accessed with ________, just like any other data type in an array. A) subscripts B) parentheses C) #include statements D) output format manipulators E) None of these

A

7) Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared. A) 20,000 B) only the first C) only half D) 2000 E) None of these

A

9) Data that is sorted in ascending order is ordered ________. A) from lowest to highest value B) from highest to lowest value C) always with a binary sort algorithm D) always with a linear sort algorithm E) None of these

A

4) A binary search begins with the ________ element of an array. A) first B) last C) largest D) middle E) None of these

D

8) What does the following statement do? double *num2; A) Declares a double variable named num2. B) Declares and initializes an pointer variable named num2. C) Initializes a variable named *num2. D) Declares a pointer variable named num2. E) None of these

D

11) True/False: It is possible for a structure variable to be a member of another structure variable.

TRUE

11.2 True/False Questions 1) True/False: A struct can contain members with varying data types.

TRUE

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

TRUE

14) True/False: An anonymous union declaration actually creates the member variables in memory.

TRUE

17) True/False: You cannot directly assign an integer value to an enum variable.

TRUE

19) True/False: When you use a strongly typed enumerator in C++ 11, you must prefix the enumerator with the name of the enum, followed by the :: operator.

TRUE

2) True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.

TRUE

2) True/False: Any mathematical operations that can be performed on regular C++ variables can be performed on structure members.

TRUE

2) True/False: The number of comparisons made by a binary search is expressed in powers of two.

TRUE

20) True/False: In C++ 11, if you want to retrieve a strongly typed enumerator's underlying integer value, you must use a cast operator.

TRUE

4) True/False: The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.

TRUE

5) True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.

TRUE

5) True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.

TRUE

6) True/False: A pointer can be used as a function argument, giving the function access to the original argument.

TRUE

9) True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.

TRUE

7) 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. A) #include B) #guard C) #ifndef D) #endif E) None of these

C

8) A(n) ________ search uses a loop to sequentially step through an array. A) binary B) unary C) linear D) relative E) None of these

C

21) Look at the following structure declaration. struct Circle { double centerX; double centerY; double radius; }; Assume that circle1 and circle2 are variables of the Circle type, and their members have been initialized. True/False: The following if statement correctly determines whether the two variables' members contain the same data: if (circle1 == circle2)

FALSE

10) True/False: It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable.

FALSE

15) True/False: A union can only have one member.

FALSE

18) True/False: You cannot directly assign an enumerator to an int variable.

FALSE

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

FALSE

22) The following union declaration appears on a system uses 4-byte ints and 8-byte doubles. union Numbers { int integerNumber; double doubleNumber; }; Numbers myNumber; myNumber.integerNumber = 1; True/False: After this code executes, the myNumber variable will occupy 4 bytes of memory.

FALSE

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

FALSE

10) True/False: To use any of the smart pointers in C++ 11, you must #include the memory header file with the following directive: #include <memory>

TRUE

4) True/False: It is legal to subtract a pointer variable from another pointer variable.

TRUE

7) True/False: If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type.

TRUE

8) True/False: Assuming myValues is an array of int values, and index is an int variable, both of the following statements do the same thing. cout << myValues[index] << endl; cout << *(myValues + index) << endl;

TRUE

31) Look at the following structure declaration. struct Employee { string name; int idNum; }; In this declaration, idNum is: A) a member B) an array C) a tag D) None of these

A

27) With an enumerated data type, the enumerators are stored in memory as ________. A) strings B) integers C) characters D) doubles

B

12) If an anonymous union is declared globally (outside all functions), it must be ________. A) empty B) declared static C) explicitly declared "global" D) initialized and used outside any function E) None of these

B

12) The ________ is adequate for searching through small arrays. A) binary search B) linear search C) unary search D) bubble sort E) None of these

B

12) When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________. A) empty constructor B) default constructor C) stand-alone function D) arbitrator function E) None of these

B

32) 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; } A) The program runs, but with no output. B) 77 C) 0 D) The program will not compile.

D

11) The destructor function's return type is ________. A) tilde B) int C) float D) Nothing. Destructors have no return type. E) None of the above

D

31) What will the following code output? int number = 22; int *var = &number; cout << *var << endl; A) The address of the number variable B) 22 C) An asterisk followed by 22 D) An asterisk followed by the address of the number variable

B

35) To help prevent memory leaks from occurring in C++ 11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used. A) null pointer B) smart pointer C) dereferenced pointer D) A and C only E) None of these

B

6) Passing a structure as a constant reference parameter to a function ________. A) can potentially result in changes to the structure's members B) guarantees not to result in changes to the structure's members C) will always change the structure's members D) All of these E) None of these

B

7) This is like a structure, except all members occupy the same memory area. A) array B) union C) structure pointer D) array of pointers E) None of these

B

9) If Circle is a structure tag, the statement: Circle doSomething(Circle c2) can be the header line for a function that ________. A) determines and returns the area of a circle B) takes a Circle structure as a parameter, does something, and returns a Circle structure C) operates on a constant reference to a Circle structure D) takes two Circle parameters and does something E) None of these

B

Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 13 Introduction to Classes 13.1 Multiple Choice Questions 1) Objects are created from abstract data types that encapsulate ________ and ________ together. A) numbers, characters B) data, functions C) addresses, pointers D) integers, floats E) None of these

B

Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 8 Searching and Sorting Arrays 8.1 Multiple Choice Questions 1) A ________ algorithm is a method of locating a specific item of information in a larger collection of data. A) sort B) search C) standard D) linear E) None of these

B

Starting Out with C++ from Control Structures to Objects, 8e (Gaddis) Chapter 9 Pointers 9.1 Multiple Choice Questions 1) The ________, also known as the address operator, returns the memory address of a variable. A) asterisk ( * ) B) ampersand ( & ) C) percent sign (%) D) exclamation point ( ! ) E) None of these

B

10) Look at the following statement: sum += *array++; This statement ________. A) is illegal in C++ B) will always result in a compiler error C) assigns the dereferenced pointer's value, then increments the pointer's address D) increments the dereferenced pointer's value by one, then assigns that value E) None of these

C

15) When this is placed in front of a variable name, it returns the address of that variable. A) asterisk ( * ) B) conditional operator C) ampersand ( & ) D) semicolon ( ; ) E) None of these

C

22) This is automatically called when an object is destroyed. A) constructor function B) specification deallocator C) destructor function D) coroner function E) None of these

C

22) Which of the following statements outputs the value of the gpa member of element 1 of the student array? A) cout << student1.gpa; B) cout << firstStudent.gpa; C) cout << student[1].gpa; D) cout << student1->gpa; E) None of these

C

30) 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; } A) The program runs, but with no output. B) 0 C) Hello! D) The program will not compile.

C

34) Look at the following code: int numbers[] = {0, 1, 2, 3, 4 }; int *ptr = numbers; ptr++; After this code executes, which of the following statements is true? A) ptr will hold the address of numbers[0]. B) ptr will hold the address of the 2nd byte within the element numbers[0]. C) ptr will hold the address of numbers[1]. D) This code will not compile.

C

6) Array elements must be ________ before a binary search can be performed. A) summed B) set to zero C) sorted D) positive numbers E) None of these

C

11) When an array is sorted from highest to lowest, it is said to be in ________ order. A) reverse B) forward C) descending D) ascending E) None of these

C

13) ________ algorithms are used to arrange random data into some order. A) Standard search B) Linear C) Sorting D) Binary search E) None of these

C

14) Which of the following statements deletes memory that has been dynamically allocated for an array? A) int array = delete memory; B) int delete[ ]; C) delete [] array; D) new array = delete; E) None of these

C

19) To dereference a structure pointer, the appropriate operator is ________. A) the ampersand, & B) an asterisk, * C) the structure pointer operator, -> D) the dereference operator, <- E) None of these

C

2) The advantage of a linear search is its ________. A) complexity B) efficiency C) simplicity D) speed E) None of these

C

20) The ________ and ________ operators can be used to increment or decrement a pointer variable. A) addition, subtraction B) modulus, division C) ++, -- D) All of these E) None of these

C

26) A declaration for an enumerated type begins with the ________ key word. A) enumerated B) enum_type C) enum D) ENUM

C

29) 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? A) Car->accelerate(); B) myCar::accelerate(); C) myCar.accelerate(); D) myCar:accelerate();

C

3) A(n) ________ search is more efficient than a ________ search. A) character, string B) integer, double C) binary, linear D) linear, binary E) None of these

C

3) This is required after the closing brace of the structure declaration. A) square bracket B) period C) semicolon D) colon E) None of these

C

4) Examples of access specifiers are the key words: A) near and far B) opened and closed C) private and public D) table and row E) None of these

C

4) Look at the following statement. bookList[2].publisher[3] = 't'; This statement ________. A) is illegal in C++ B) will change the publisher's name of the second book in bookList to 't' C) will store the character 't' in the fourth element of the publisher member of booklist[2] D) will ultimately result in a runtime error E) None of these

C

5) The ________ sort usually performs fewer exchanges than the ________ sort. A) bubble, selection B) binary, linear C) selection, bubble D) ANSI, ASCII E) None of these

C

6) The contents of pointer variables may be changed with mathematical statements that perform ________. A) all mathematical operations that are legal in C++ B) multiplication and division C) addition and subtraction D) B and C E) None of these

C

9) When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________. A) the value pointed to by the first is less than the value pointed to by the second B) the value pointed to by the first is greater than the value pointed to by the second C) the address of the first variable comes before the address of the second variable in the computer's memory D) the first variable was declared before the second variable E) None of these

C

3) The statement: int *ptr = nullptr; has the same meaning as ________. A) int ptr = nullptr; B) *int ptr = nullptr; C) int ptr* = nullptr; D) int* ptr = nullptr; E) None of these

D

10) Which of the following assigns a value to the hourlyWage member of employee[2]? A) employee[2]->hourlyWage = 50.00; B) employee2.hourlyWage = 7.50; C) hourlyWage[2].employee = 29.75 D) employee[2].hourlyWage = 100.00; E) None of these

D

15) In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data. A) numbers, arguments B) parameters, arguments C) strings, operators D) data, functions E) None of these

D

2) In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________. A) values, morals B) data, activities C) attributes, activities D) attributes, methods E) None of these

D

22) Which statement displays the address of the variable num1? A) cout << num1; B) cout << *num1; C) cin >> &num1; D) cout << &num1; E) None of these

D

23) The following statement: cin >> *num3; A) stores the keyboard input into the variable num3 B) stores the keyboard input into the pointer called num3 C) is illegal in C++ D) stores the keyboard input into the variable pointed to by num3 E) None of these

D

25) In C++ 11 you can use a new type of enum, known as a(n) ________, (also known as an enum class) to have multiple enumerators with the same name, within the same scope. A) universal enum B) auto enum C) multi-cast enum D) strongly typed enum E) None of these

D

3) A C++ class is similar to one of these. A) inline function B) header file C) library function D) structure E) None of these

D

10) Regardless of the algorithm being used, a search through an array is always performed ________. A) from lowest to highest element B) from highest to lowest element C) beginning with the middle element D) using a binary search E) None of these

E

28) When you pass a pointer as an argument to a function, you must ________. A) declare the pointer variable again in the function call B) dereference the pointer variable in the function prototype C) use the #include<func_ptr.h> statement D) not dereference the pointer in the function's body E) None of these

E

4) True/False: A linear search can only be implemented with integer values.

FALSE

5) True/False: Before you can perform a selection sort, the data must be stored in ascending order.

FALSE

6) True/False: Before you can perform a bubble sort, the data must be stored in descending order.

FALSE

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

FALSE

7) True/False: Using a binary search, you are more likely to find an item than if you use a linear search.

FALSE

8.2 True/False Questions 1) True/False: The bubble sort is an easy way to arrange data into ascending order, but it cannot arrange data into descending order.

FALSE

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

FALSE


संबंधित स्टडी सेट्स

Forms + HW's Review (Igneous Rocks)

View Set

Unit #1 - Regulation of Investment Advisers, Including State-Registered and Federal Covered Advisers

View Set