Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 07 Starting out with C++ Arrays


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Seven

MULTIPLE CHOICE

1. Unlike regular variables, these can hold multiple values.
a. constants
b. named constants
c. arrays
d. floating-point variables
e. None of these

 

2. The individual values contained in array are known as
a. parts
b. elements
c. numbers
d. constants
e. None of these

 

3. To access an array element, use the array name and the element’s
a. data type
b. subscript
c. name
d. value
e. None of these

 

4. Which of the following is a valid C++ array definition?
a. int array[0];
b. float $payments[10];
c. void numbers[5];
d. int array[10];
e. None of these

 

5. The statement

int grades[ ] = { 100, 90, 99, 80};

shows an example of
a. default arguments
b. an illegal array declaration
c. an illegal array initialization
d. implicit array sizing
e. None of these

 

6. By using the same ________ you can build relationships between data stored in two or more arrays.
a. array name
b. data
c. subscript
d. arguments
e. None of these

 

7. The name of an array stores the __________ of the first array element.
a. memory address
b. value
c. element number
d. data type
e. None of these

 

8. A two-dimensional array is like ______________ put together.
a. an array and a function
b. several identical arrays
c. two functions
d. two arrays of different types
e. None of these

 

9. A two-dimensional array can be viewed as ___________ and _____________.
a. rows, columns
b. arguments, parameters
c. increments, decrements
d. All of these
e. None of these

 

10. 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 the array elements
c. all array elements default to zero values
d. your array will contain no elements

 

11. Which of the following is a valid C++ array definition?
a. int scores[0];
b. float $payments[10];
c. int readings[4.5];
d. int scores [10];
e. None of these

 

12. An element of a two-dimensional array is referred to by __________ followed by ___________.
a. the array name, the column number of element
b. the row subscript of the element, the column subscript of the element
c. a comma, a semicolon
d. the row subscript of element, the array name
e. None of these

 

13. 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

 

14. An array can store a group of values, but the values must be
a. the same data type
b. each of a different data type
c. constants
d. integers
e. None of these

 

15. An array’s size declarator must be a(n)_________ with a value greater than _________.
a. number, one
b. number, zero
c. constant integer expression, zero
d. variable, -1
e. None of these

 

16. Subscript numbering in C++
a. can be set at runtime
b. can begin with a programmer-defined value
c. varies from program to program
d. begins with zero
e. None of these

 

17. Arrays may be ___________ at the time they are __________.
a. resized, executed
b. re-scoped, deleted
c. initialized, declared
d. pre-compiled, typecast
e. None of these

 

18. Given the following declaration, where is 77 stored in the scores array?

int scores[]={83, 62, 77, 97};

a. scores[0]
b. scores[1]
c. scores[2]
d. scores[4]

 

19. An array can easily be stepped through by using a
a. for loop
b. reference variable
c. named constant
d. null value
e. None of these

 

20. 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

 

21. 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

 

22. A two-dimensional array can have elements of _________ data type(s).
a. one
b. two
c. four
d. Any of these
e. None of these

 

23. 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

 

24. 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

 

25. 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

 

26. An array with no elements is
a. legal in C++
b. illegal in C++
c. automatically furnished one element, with a value of zero
d. automatically furnished one value — the null terminator
e. None of these

 

27. An array of string objects that will hold 5 names would be declared using which statement?
a. string names[5];
b. string names(5);
c. string names5;
d. String[5] names;
e. None of these will work

 

28. It is __________ to pass an argument to a function that contains an individual array element, such as numbers[3].
a. illegal in C++
b. legal in C++
c. not recommended by the ANSI committee
d. not good programming practice
e. None of these

 

29. What is the last legal subscript that can be used with the following array?

int values[5];

a. 0 c. 6
b. 5 d. 4

 

30. How many elements does the following array have?

int bugs[1000];

a. 1000 c. 1001
b. 999 d. Cannot tell from the code

 

31. What will the following code display?

int numbers[] = {99, 87, 66, 55, 101 };
cout << numbers[3] << endl;

a. 55
c. 101

b. 66
d. 87

 

32. What will the following code display?

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

a. 99
87
66
55
101
c. 87
66
55

b. 87
66
55
101
d. Nothing. This code has an error.

 

33. What will the following code display?

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

a. 87 c. garbage
b. 0 d. This code will not compile

 

34. What will 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 the last, is initialized to 0.0
d. An error will occur when the code runs

 

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

a. vector v; c. int v;
b. int vector v; d. vector v;

 

36. What does the following statement do?

vector v(10);

a. It creates a vector object and initializes all of its elements to the value 10.
c. It creates a vector object and initializes the first element with the value 10.

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

 

37. What does the following statement do?

vector v(10, 2);

a. It creates a vector object and initializes all the first two elements with the values 10 and 2.
c. It creates a vector object with a starting size of 10 and the first element initialized with the value 2.
b. It creates a vector object with a starting size of 2 and the first element initialized with the value 10.
d. It creates a vector object with a starting size of 10 and all elements are initialized with the value 2.

 

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

a. insert_item c. store
b. add_item d. push_back

 

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

a. size c. elements
b. num_elements d. length

 

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

a. remove_item c. erase
b. delete_item d. pop_back

 

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

a. has_no_elements c. empty
b. null_size d. is_empty

 

TRUE/FALSE

1. True/False: The amount of memory used by an array depends upon the array’s data type and the number of elements in the array.

2. True/False: The statement

double money[25.00];

is a valid C++ array definition.

3. True/False: An array initialization list must be placed on one single line.

4. True/False: Assume array1 and array2 are the names of arrays. To assign the contents of array2 to array1, you would use the following statement.

array1 = array2;

5. True/False: When you pass an array as an argument to a function, the function can modify the contents of the array.

6. True/False: C++ limits the number of array dimensions to two.

7. True/False: If you attempt to store data past an array’s boundaries, it is guaranteed that the compiler will issue an error.

8. True/False: An individual array element can be processed like any other type of C++ variable.

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

10. True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript.

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

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

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!