Computing Lab 6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Indexes are numbered starting at ________.

0

How many indexed variables does the following array have? int myArray[12] = {1,2,3,6,5,4,7,1,2};

12

How many indexed variables does the following array have? int myArray[ ] = {1,2,3,6,5,4,7,1,2};

9

Given an array named scores with 25 elements, what is the correct way to access the 25th element? A) scores[24] B) scores[last] C) scores[25] D) scores+25

A

Given an array of integers of size 5, how does the computer know where the variable indexed by [3] is located? A) It adds space for 3 integers to the base address of the array. B) It remembers where all the indexed variables of the array are located. C) It adds 3 to the base address of the array. D) none of the above

A

If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets. A) all sizes except the first dimension B) none of the sizes C) all the sizes D) all sizes except the last dimension

A

Which of the following function declarations could be used to input data from the keyboard into the array? A) void input(int array[ ], int &numValidElements, int MAX_SIZE); B) int array[ ] input(int array[ ], int &numValidElements, int MAX_SIZE); C) void input(int array[ ], int numValidElements, int MAX_SIZE); D) void input(int &array[ ], int numValidElements, int MAX_SIZE);

A

Which of the following will correctly assign all the values in one array to the other array (Assume both arrays are of the same type and have SIZE elements) A) for(i = 0;i < SIZE;i ++) array1[i] = array2[i]; B) array1 = array2; C) array1[ ] = array2; D) for(i = 0;i < SIZE;i ++) array1[ ] = array2[ ];

A

Arrays are always passed to a function using A) pass by reference. B) pass by array. C) pass by value. D) You cannot pass arrays to a function.

B

What are the valid indexes for the array shown below? int myArray[25]; A) 0-25 B) 0-24 C) 1-24 D) 1-25

B

Which of the following function declarations will accept the following two-dimension array? int pages[10][30]; A) void f1(int pages[ ][ ], int size); B) void f1(int pages[ ][30], int size); C) void f1(int& pages, int size); D) void f1(int pages[10][ ], int size);

B

Given the following class and array declaration, how would you print out the age of the 10th person in the array? class personClass{ public: void setAge(int newAge); void setGender( char newGender); void setSalary(float newSalary); int getAge( ); char getGender( ); float getSalary( ); private: int age; char gender; float salary; } ; personClass people[100]; A) cout < < people[9]; B) cout < < people[9].age; C) cout < < people[9].getAge( ); D) cout < < people[10];

C

Given the following function definition for a search function, and the following variable declarations, which of the following are appropriate function invocations? const int SIZE = 1000; int search(const int array[ ], int target, int numElements); int array[SIZE], target, numberOfElements; A) result = search(array[0], target, numberOfElements); B) search(array[0], target, numberOfElements); C) result = search(array, target, numberOfElements); D) result = search(array, target, SIZE);

C

If we want a search function to search an array for some value and return either the index where the value was found, or -1 if not found, which of the following prototypes would be appropriate? A) void search(const int array, int target); B) int search(const int array[ ], int numElements); C) int search(const int array[ ], int target, int numElements); D) void search(const int array, int target, int numElements);

C

What is the output of the following code fragment? int array[4][4], index1, index2; for(index1 = 0;index1 < 4;index1 ++) for(index2 = 0;index2 < 4;index2 ++) array[index1][index2]=index1 + index2; for(index1 = 0;index1 < 4;index1 ++) { for(index2 = 0;index2 < 4;index2 ++) cout < < array[index1][index2] < < " "; cout < < endl; } A) 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 B) 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 C) 0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 D) 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9

C

What is wrong with the following code? float scores[10], total; A) The 10 should be replaced with a variable name, whose value is input from the user. B) Arrays must be integers. C) nothing D) Cannot declare regular and array variables together.

C

Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles? A) double array[3,5]; B) int array[3],[5]; C) double array[3][5]; D) int array[3][5];

C

Which of the following statements are true? A) Array elements may be user-defined types (structs or classes). B) If a function is expecting a variable of the base type of the array, then you can pass an element of the array to the function. C) all of the above D) none of the above

C

Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array with repeated calls? int search(const int array[ ], int target, int numElements){ int index = 0; bool found = false; while((!found) && (index < numElements)) { if(array[index] = = target) found = true; else index ++; } if(found = = true) return index; else return -1 ; } A) This already can find all occurrences of a given target. B) Add another parameter to indicate where to stop searching. C) Have the function return the whole array. D) Add another parameter to indicate where to start searching.

D

Given the following function definition, will repeated calls to the search function for the same target find all occurrences of that target in the array? int search(const int array[ ], int target, int numElements){ int index = 0; bool found = false; while((!found) && (index < numElements)) { if(array[index] = = target) found = true; else index ++; } if(found = = true) return index; else return -1 ; } A) yes B) impossible to tell without looking at the values of the array C) It depends on the value of target. D) no

D

If you declare and initialize an integer array of size 10, but only list 5 values, what values are stored in the remaining 5 indexed variables? A) 0.0 B) '0' C) garbage D) 0

D

What is wrong with the following code fragment? const int SIZE = 5; float scores[SIZE]; for(int i = 0; i < = SIZE;i ++) { cout < < "Enter a score\n"; cin > > scores[i]; } A) Array indexes start at 1 not 0. B) Arrays must be integers. C) should be cin > > scores[0]; D) Array indexes must be less than the size of the array.

D

Which of the following function declarations correctly guarantee that the function will not change any values in the array argument? A) void f1(int &array, int size); B) void f1(int array[ ], int size); C) void f1(int array[ ], const int size); D) void f1(const int array[ ], int size); E) void f1(int array[ ], int size) const;

D

Which of the following will read values from the keyboard into the array? (Assume the size of the array is SIZE). A) cin > > array; B) cin > > array[SIZE]; C) cin > > array[ ]; D) for(i = 0;i < SIZE;i ++) cin > > array[i];

D

Which sort algorithm does the following outline define? for i between 0 and number_used-1 inclusive put the ith smallest element at array[i] A) bubble B) swap C) sequential D) selection

D

Why should you use a named constant for the size of an array? A) readability of code B) helps reduce logic errors C) makes changes to the program easier D) all of the above

D

A two dimension array can also be thought of as A) table. B) array of arrays. C) a file. D) none of the above E) A and B

E

Given the following declarations, which of the following is a legal call to this function? int myFunction(int myValue); int myArray[1000]; A) myArray = myFunction(myArray); B) cout < < myFunction(myArray[0]); C) cout < < myFunction(myArray); D) myArray[1] = myFunction(myArray[0]); E) B and D

E

The following function definition has an error in it. What line is this error on? 0. void f1(const double array[ ], int size) 1. { 2 . int i = 0; 3 . while(i < size) 4 . { 5 . array[i] += 2; 6 . cout < < array[i]; 7 . i ++; 8 . } 9. } A) 0 B) 2 C) 6 D) 7 E) 5

E

Which of the following array declarations are legal? A) int array[ ] = {0,0,0}; B) int size; cin > > size; int array[size]; C) const int size = 9; int array [size]; D) int array[10]; E) all but B

E

Which of the following declare an array of 5 characters, and initializes them to some known values? A) char array[5] = {'a','b','c','d','e'}; B) char array[4] = {'a','b','c','d','e'}; C) char array[5] = { }; D) char array[ ] = {'a','b','d','e'}; E) A and C

E

Which of the following function declarations can be passed the following array? char myArray[6][8]; A) void f1(char& a, int sizeOfFirst); B) void f1(char a[ ][8], int sizeOfFirst); C) void f1(char a[ ][ ], int sizeOfFirst); D) void f1(char a[6][8], int sizeOfFirst); E) B and D

E

Which of the following function declarations correctly expect an array as the first argument? A) void f1(int& array, int size); B) void f1(int array, int size); C) void f1(int array[100], int size); D) void f1(float array[ ], int size); E) C and D

E

(T/F) Arrays can be returned from a function.

False

(T/F) If you use the const modifier in a function declaration, you do not include it in the function definition.

False

(T/F) The following function declaration guarantees the values in the array argument are not changed. void function1(int array[ ], int numElements);

False

(T/F) The indexed variables (elements) of an array must be integers.

False

(T/F) The locations of the various indexed variables in an array can be spread out all over the memory.

False

If your index used to access the indexed variables of the array has the value of a non-existent index, this is called ________.

Index out of bounds

(T/F) Arrays can be passed to functions.

True

(T/F) If a function is expecting a pass by reference parameter, you can pass an index variable (element) from an array of the same base type to that function.

True

(T/F) The following array declaration is legal double scores[ ] = {0.1,0.2,0.3};

True

(T/F) The following function will work with any size integer array. void function1(int array[ ], int numElements);

True

(T/F) When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables (elements) with valid data.

True

Write the code to declare a two dimension array of integers with 10 rows and 20 columns. (The row index comes first)

int array[10][20];

An ________ is used to process a collection of data all of which is the same type.

array

In the expression double score[10]; double is called the ________ of the array.

base type

A computer's memory consists of numbered locations called ________.

bytes

The modifier that guarantees that an array argument will not be changed is called ________.

const

Write the code to declare an array of 10 doubles named list.

double list[10];

The individual variables that comprise an array are called ________.

elements

If you put a value in the square brackets of a one-dimension array parameter, this value is ________ by the compiler.

ignored

In the expression cout < < score[i] < < endl; i is called the ________.

index

The computer remembers the address of which indexed variable(s) in an array?

the first

Write the declaration for a function named funct1 that expects an array of floats, the number of elements in the array and does not return any value.

void funct1(float array[], int numOfElements);


Kaugnay na mga set ng pag-aaral

EVRN 148 ch 13 renewable energy questions

View Set