Full download Starting out with c++ from control structures through objects brief version 9th editio

Page 1


More products digital (pdf, epub, mobi) instant download maybe you interests ...

Starting Out with C++ From Control Structures through Objects Brief Version 9th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-through-objects-brief-version-9th-edition-gaddissolutions-manual/

Starting Out with C++ From Control Structures through Objects Brief Version 8th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-through-objects-brief-version-8th-edition-gaddis-testbank/

Starting Out With C++ From Control Structures Through Objects 7th Edition Tony Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-through-objects-7th-edition-tony-gaddis-test-bank/

Starting Out With C++ From Control Structures To Objects 9th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-to-objects-9th-edition-gaddis-solutions-manual/

Starting Out

with

C++ from Control Structures to Objects 8th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-to-objects-8th-edition-gaddis-test-bank/

Starting Out with Java From Control Structures through Objects

6th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-fromcontrol-structures-through-objects-6th-edition-gaddis-test-bank/

Starting

Out with Java From

Control Structures through Objects 7th Edition Gaddis Test Bank

https://testbankfan.com/product/starting-out-with-java-fromcontrol-structures-through-objects-7th-edition-gaddis-test-bank/

Starting Out

with

C++ from Control Structures to Objects 8th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-to-objects-8th-edition-gaddis-solutions-manual/

Starting

Out With

C++ From Control Structures To Objects 7th Edition Gaddis Solutions Manual

https://testbankfan.com/product/starting-out-with-c-from-controlstructures-to-objects-7th-edition-gaddis-solutions-manual/

Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)

Chapter 7 Arrays and Vectors

TRUE/FALSE

1. The amount of memory used by an array depends on the array's data type and the number of elements in the array.

ANS: T

2. An array initialization must be all on one line.

ANS: F

3. When you pass an array as an argument to a function, the function can modify the contents of the array.

ANS: T

4. C++ limits the number of array dimensions to two.

ANS: F

5. If you attempt to store data past an array's boundaries, it is guaranteed to cause a compiler error.

ANS: F

6. An individual array element can be processed like any other type of C++ variable.

ANS: T

7. In C++11 you cannot use a range-based for loop to modify the contents of an array unless you declare the range variable as a reference variable.

ANS: T

8. In C++11 the range-based for loop is best used in situations where you need the element subscript for some purpose.

ANS: F

9. Although two-dimensional arrays are a novel idea, there is no known way to pass one to a function.

ANS: F

10. Each individual element of an array can be accessed by the array name and the element subscript.

T

11. If an array is partially initialized, the uninitialized elements will be set to zero.

ANS: T

12. The following statement is a valid C++ definition: double money[25.00];

ANS: F

13. Assume array1 and array2 are the names of two arrays. To assign the contents of array2 to array1, you would use the following statement: array1 = array2;

ANS: F

14. A vector object automatically expands in size to accommodate the items stored in it.

ANS: T

MULTIPLE CHOICE

1. Unlike regular variables, __________ can hold multiple values.

a. constants

b. named constants

c. arrays

d. floats

e. None of these

ANS: C

2. The individual values contained in an array are known as

a. parts

b. items

c. constants

d. elements

e. None of these

ANS: D

3. To access an array element, use the array name and the element's ___________.

a. data type

b. subscript

c. value

d. name

e. None of these

ANS: B

4. By using the same ___________ you can build relationships between data stored in two or more arrays.

a. array name

b. data types

c. subscript

d. arguments

e. None of these

ANS: C

5. The name of an array stores the __________ of the first array element.

a. value

b. memory address

c. element number

d. data type

e. None of these

ANS: B

6. Which of the following is a valid C++ array definition?

a. int nums[0];

b. float $payments[10];

c. void numbers[5];

d. int sizes[10];

e. None of these

ANS: D

7. Which of the following is a valid C++ array definition?

a. int array[0];

b. float $payments[10.23];

c. int numbers[5.6];

d. int scores[25];

e. None of these

ANS: D

8. If you leave out the size declarator in an array definition

a. you must furnish an initialization list

b. you are not required to initialize array elements

c. all array elements default to zero values

d. your array will contain no elements

e. None of these

ANS: A

9. An array can store a group of values, but the values must be

a. the same data type

b. integers and floating-point numbers

c. integers

d. constants

e. None of these

10. An array's size declarator must be a __________ with a value greater than __________.

a. number, one

b. number, zero

c. constant integer expression, zero

d. variable, -1

e. None of these

ANS: C

11. Subscript numbering in C++

a. can be set at runtime

b. can begin with a value defined by the programmer

c. varies from program to program

d. begins with zero

e. None of these

ANS: D

12. Arrays must be __________ at the time they are __________.

a. sized, executed

b. re-scoped, deleted

c. initialized, declared

d. compiled, typed

e. None of these

ANS: C

13. This following statement shows an example of ___________. int grades][ ] = {100, 90, 99, 80};

a. default arguments

b. an illegal array declaration

c. an illegal array initialization

d. implicit array sizing

e. None of these

ANS: D

14. Given the following declaration, where is the value 77 stored in the scores array? int scores[] = {83, 62, 77, 97, 86}

a. scores[0]

b. scores[1]

c. scores[2]

d. scores[3]

e. scores[5]

ANS: C

15. An array can easily be stepped through by using a a. a for loop

b. a reference variable

c. an array prototype

d. a null value

e. None of these

ANS: A

16. The range-based for loop in C++11 is designed to work with a built-in variable known as

a. the counter

b. the i variable

c. an iterator

d. the range variable

e. None of these

ANS: D

17. A(n) __________ can be used to specify the starting values of an array.

a. initialization list

b. array name

c. subscript

d. element

e. None of these

ANS: A

18. An array with no elements is

a. legal in C++

b. illegal in C++

c. automatically furnished with one element whose value is set to zero

d. automatically furnished with one element, the null terminator

e. None of these

ANS: B

19. It is _________ to pass an argument to a function that contains an individual array element, such as scores[3]

a. illegal in C++11

b. legal in C++

c. not recommended by the ANSI committee

d. not good programming practice

e. None of these

ANS: B

20. What is the last legal subscript that can be used with the following array? int values[5];

a. 0

b. 5

c. 6

d. 4

e. 1

21. How many elements does the following array have? int values[1000];

a. 1000

b. 999

c. 1001

d. cannot tell from the code

ANS: A

22. To assign the contents of one array to another, you must use

a. the assignment operator with the array names

b. the equality operator with the array names

c. a loop to assign the elements of one array to the other array

d. Any of these

e. None of these

ANS: C

23. To pass an array as an argument to a function, pass the __________ of the array.

a. contents

b. size, expressed as an integer

c. name

d. value of the first element

e. None of these

ANS: C

24. The __________ is automatically appended to a character array when it is initialized with a string constant.

a. array name

b. number of elements

c. value of the first element

d. null terminator

e. None of these

ANS: D

25. An array of string objects that will hold five names would be declared with which of the following statements?

a. string names[5];

b. string names(5);

c. string names 5;

d. String[5] = names;

ANS: A

26. A two-dimensional array can be viewed as

a. rows and columns

b. arguments and parameters

c. increments and decrements

d. All of these

e. None of these

ANS: A

27. An element of a two-dimensional array is referred to by

a. the array name followed by the column number of the element

b. the row subscript of the element followed by the column subscript of the element

c. a comma followed by a semicolon

d. the row subscript of the element followed by the array name

e. None of these

ANS: B

28. When writing functions that accept multi-dimensional arrays as arguments, __________ must be explicitly stated in the parameter list.

a. all dimensions

b. all but the first dimension

c. the size declarator of the first dimension

d. all element values

e. None of these

ANS: B

29. A two-dimensional array can have elements of __________ data type(s).

a. one

b. two

c. four

d. any number of

e. None of these

ANS: A

30. A two-dimensional array of characters can contain

a. strings of the same length

b. strings of different lengths

c. uninitialized elements

d. All of these

e. None of these

ANS: D

31. What will the following code display? int numbers[] = {99, 87, 66, 55, 101}; cout << numbers[3] << endl;

a. 55

b. 66

c. 101

d. 87

ANS: A

32. What will the following code display?

int numbers[] = {99, 87, 66, 55, 101}; for (int i = 1; i < 4; i++)

cout << numbers[i] << " ";

a. 99 87 66 55 101

b. 87 66 55 101

c. 87 66 55

d. Nothing. This code has an error.

ANS: C

33. What will the following code display?

int numbers[4] = {99, 87}; cout << numbers[3] << endl;

a. 87

b. 0

c. 99

d. garbage

e. This code will not compile

ANS: B

34. What does the following code do?

const int SIZE = 5; double x[SIZE]; for (int i = 2; i <= SIZE; i++) { x[i] = 0.0; }

a. Each element in the array is initialized to 0.0

b. Each element in the array except the first is initialized to 0.0

c. Each element in the array except the first and last is initialized to 0.0.

d. An error will occur when the code runs.

ANS: D

35. Which statement correctly defines a vector object for holding integers?

a. vector v<int>;

b. int vector v;

c. int<vector> v;

d. vector<int> v;

ANS: D

36. Which statement correctly uses C++11 to initalize a vector of ints named n with the values 10 and 20?

a. vector n<int>(10, 20);

b. vector<int> n = {10, 20};

c. vector<int> n {10, 20};

d. int vector n ({10}, {20});

ANS: C

37. What does the following statement do?

vector<int> v(10);

a. It creates a vector object and initializes all its elements to the value 10.

b. It creates a vector object with a starting size of 10

c. It creates a vector object and initializes the first element with the value 10

d. It creates a vector object that can only store values of 10 or less.

ANS: B

38. What does the following statement do?

vector<int> v(10, 2);

a. It creates a vector object and initializes the first two elements with the values 10 and 2.

b. It creates a vector object with a starting size of 2 and initializes the first element with the value 10

c. It creates a vector object with a starting size of 10 and initializes the first element with the value 2

d. It creates a vector object with a starting size of 10 and initializes all the elements with the value 2.

ANS: D

39. This vector function is used to insert an item into a vector.

a. insert_item

b. add_item

c. store

d. push_back

ANS: D

40. This vector function removes an item from a vector.

a. remove_item

b. delete_item

c. erase

d. pop_back

ANS: D

41. This vector function returns the number of elements in a vector

a. size

b. num_elements

c. elements

d. length

ANS: A

42. This vector function returns true if the vector has no elements.

a. has_no_elements

b. null_size

c. empty

d. is_empty

ANS: C

43. What will the following C++11 code display? vector<int> numbers {3, 5}; for (int val : numbers) cout << val << endl; a. 5 5 5 b. 3 3 3 3 3 c. 3 5

d. Nothing. This code has an error.

ANS: C

Another random document with no related content on Scribd:

Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.