Deck 7: Arrays

ملء الشاشة (f)
exit full mode
سؤال
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.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
The following array declaration is legal
double scores[]={0.1,0.2,0.3};
سؤال
The modifier that guarantees that an array argument will not be changed is called ______.
سؤال
If your index used to access the indexed variables of the array has the value of a non-existent index, this is called _________
سؤال
How many indexed variables does the following array have?
int myArray[12]={1,2,3,6,5,4,7,1,2};
سؤال
The following function declaration guarantees the values in the array argument are not changed.
void function1int array[], int numElements);
سؤال
If you use the const modifier in a function declaration, you do not include it in the function definition.
سؤال
Write the code to declare a two dimension array of integers with 10 rows and 20 columns.
سؤال
The locations of the various indexed variables in an array can be spread out all over the memory.
سؤال
Write the code to declare an array of 10 doubles named list;
سؤال
How many indexed variables does the following array have?
int myArray[]={1,2,3,6,5,4,7,1,2};
سؤال
Arrays can be passed to functions.
سؤال
If you put a value in the square brackets of a one-dimension array parameter, this value is _________ by the compiler.
سؤال
The computer remembers the address of which indexed variables) in an array? ______
سؤال
A computer's memory consists of numbered locations called __________.
سؤال
Arrays can be returned from a function.
سؤال
If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.
سؤال
The following function will work with any size integer array.
void function1int array[], int numElements);
سؤال
The indexed variables members) of an array must be integers.
سؤال
When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables with valid data.
سؤال
What is wrong with the following code fragment?
Const int SIZE =5;
Float scores[SIZE];
Forint 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) Array indexes must be less than the size of the array
D) Should be cin >> scores[0];
سؤال
What are the valid indexes for the array shown below?
Int myArray[25];

A) 0-25
B) 0-24
C) 1-25
D) 1-24
سؤال
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 searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}

A) Yes
B) No
C) Impossible to tell without looking at the values of the array
D) It depends on the value of target.
سؤال
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 searchconst int array, int target, int numElements);
B) void searchconst int array, int target);
C) int searchconst int array[], int numElements);
D) int searchconst int array[], int target, int numElements);
سؤال
In the expression
double score[10];
double is called the ___________ of the array
سؤال
Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?

A) It adds 3 to the base address of the array
B) It adds space for 3 integers to the base address of the array
C) It remembers where all the indexed variables of the array are located.
D) None of the above
سؤال
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 searchconst int array[], int target, int numElements);
Int array[SIZE], target, numberOfElements;

A) searcharray[0], target, numberOfElements);
B) result=searcharray[0], target, numberOfElements);
C) result=searcharray, target, numberOfElements);
D) result=searcharray, target, SIZE);
سؤال
In the expression
cout << score[i] << endl;
i is called the
سؤال
An _______ is used to process a collection of data all of which is the same type
سؤال
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?
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}

A) Add another parameter to indicate where to stop searching
B) Add another parameter to indicate where to start searching
C) This already can find all occurrences of a given target
D) Have the function return the whole array
سؤال
Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?

A) void f1int array[], int size) const;
B) void f1int array[], int size);
C) void f1int &array, int size);
D) void f1const int array[], int size);
E) void f1int array[], const int size);
سؤال
Given an array named scores with 25 elements, what is the correct way to access the 25th element?

A) scores+25
B) scores[24]
C) scores[25]
D) scores[last]
سؤال
Arrays are always passed to a function using

A) pass by value
B) pass by reference
C) pass by array
D) you cannot pass arrays to a function
سؤال
Indexes are numbered starting at _________
سؤال
Which of the following function declarations could be used to input data from the keyboard into the array?

A) void inputint array[], int &numElements, int MAX_SIZE);
B) void inputint array[], int numElements, int MAX_SIZE);
C) void inputint &array[], int numElements, int MAX_SIZE);
D) int array[] inputint array[], int &numElements, int MAX_SIZE);
سؤال
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) sequential
B) selection
C) bubble
D) swap
سؤال
The individual variables that comprise an array are called __________
سؤال
What is wrong with the following code?
Float scores[10], total;

A) Cannot declare regular and array variables together.
B) Arrays must be integers
C) The 10 should be replaced with a variable name, whose value is input from the user
D) Nothing.
سؤال
Why should you use a named constant for the size of an array?

A) Readability of code
B) Makes changes to the program easier
C) Helps reduce logic errors
D) All of the above
سؤال
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
B) garbage
C) 0.0
D) '0'
سؤال
If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets.

A) All the sizes
B) All sizes except the last dimension
C) All sizes except the first dimension
D) None of the sizes
سؤال
Which of the following correctly uses C++11's range-based for statement to iterate through every element of the array variable arr?

A) for auto x : arr)
B) foreach x in arr)
C) for auto x; x < arr.length; x++)
D) for x in arr
سؤال
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) array1=array2;
B) array1[]=array2;
C) fori=0;iD) fori=0;i
سؤال
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int &element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;

A) 1 2 3
B) 11 12 13
سؤال
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[];
C) cin >> array[SIZE];
D) fori=0;i> array[i];
سؤال
Which of the following function declarations will accept the following two-dimension array?
Int pages[10][30];

A) void f1int pages[][], int size);
B) void f1int pages[][30], int size);
C) void f1int pages[10][], int size);
D) void f1int& pages, int size);
سؤال
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;

A) 1 2 3
B) 11 12 13
سؤال
Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles?

A) int array[3],[5];
B) int array[3][5];
C) float array[3][5];
D) float array[3,5];
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/48
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 7: Arrays
1
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 funct1float myArray[], int numElements);
2
The following array declaration is legal
double scores[]={0.1,0.2,0.3};
True
3
The modifier that guarantees that an array argument will not be changed is called ______.
const
4
If your index used to access the indexed variables of the array has the value of a non-existent index, this is called _________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
5
How many indexed variables does the following array have?
int myArray[12]={1,2,3,6,5,4,7,1,2};
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
6
The following function declaration guarantees the values in the array argument are not changed.
void function1int array[], int numElements);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
7
If you use the const modifier in a function declaration, you do not include it in the function definition.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
8
Write the code to declare a two dimension array of integers with 10 rows and 20 columns.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
9
The locations of the various indexed variables in an array can be spread out all over the memory.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
10
Write the code to declare an array of 10 doubles named list;
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
11
How many indexed variables does the following array have?
int myArray[]={1,2,3,6,5,4,7,1,2};
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
12
Arrays can be passed to functions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
13
If you put a value in the square brackets of a one-dimension array parameter, this value is _________ by the compiler.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
14
The computer remembers the address of which indexed variables) in an array? ______
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
15
A computer's memory consists of numbered locations called __________.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
16
Arrays can be returned from a function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
17
If a function is expecting a pass by reference parameter, you can pass an index variable from an array of the same base type to that function.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
18
The following function will work with any size integer array.
void function1int array[], int numElements);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
19
The indexed variables members) of an array must be integers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
20
When you have a function that expects an array, it should also expect the size of the array or the number of indexed variables with valid data.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
21
What is wrong with the following code fragment?
Const int SIZE =5;
Float scores[SIZE];
Forint 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) Array indexes must be less than the size of the array
D) Should be cin >> scores[0];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
22
What are the valid indexes for the array shown below?
Int myArray[25];

A) 0-25
B) 0-24
C) 1-25
D) 1-24
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
23
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 searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}

A) Yes
B) No
C) Impossible to tell without looking at the values of the array
D) It depends on the value of target.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
24
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 searchconst int array, int target, int numElements);
B) void searchconst int array, int target);
C) int searchconst int array[], int numElements);
D) int searchconst int array[], int target, int numElements);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
25
In the expression
double score[10];
double is called the ___________ of the array
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
26
Given an array of integers of size 5, how does the computer know where the 3rd indexed variable is located?

A) It adds 3 to the base address of the array
B) It adds space for 3 integers to the base address of the array
C) It remembers where all the indexed variables of the array are located.
D) None of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
27
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 searchconst int array[], int target, int numElements);
Int array[SIZE], target, numberOfElements;

A) searcharray[0], target, numberOfElements);
B) result=searcharray[0], target, numberOfElements);
C) result=searcharray, target, numberOfElements);
D) result=searcharray, target, SIZE);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
28
In the expression
cout << score[i] << endl;
i is called the
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
29
An _______ is used to process a collection of data all of which is the same type
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
30
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?
Int searchconst int array[], int target, int numElements)
{
Int index=0;
Bool found=false;
While!found) && index < numElements))
{
Ifarray[index] == target)
Found=true;
Else
Index++;
}
Iffound==true)
Return index;
Else
Return -1;
}

A) Add another parameter to indicate where to stop searching
B) Add another parameter to indicate where to start searching
C) This already can find all occurrences of a given target
D) Have the function return the whole array
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
31
Which of the following function declarations correctly guarantee that the function will not change any values in the array argument?

A) void f1int array[], int size) const;
B) void f1int array[], int size);
C) void f1int &array, int size);
D) void f1const int array[], int size);
E) void f1int array[], const int size);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
32
Given an array named scores with 25 elements, what is the correct way to access the 25th element?

A) scores+25
B) scores[24]
C) scores[25]
D) scores[last]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
33
Arrays are always passed to a function using

A) pass by value
B) pass by reference
C) pass by array
D) you cannot pass arrays to a function
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
34
Indexes are numbered starting at _________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which of the following function declarations could be used to input data from the keyboard into the array?

A) void inputint array[], int &numElements, int MAX_SIZE);
B) void inputint array[], int numElements, int MAX_SIZE);
C) void inputint &array[], int numElements, int MAX_SIZE);
D) int array[] inputint array[], int &numElements, int MAX_SIZE);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
36
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) sequential
B) selection
C) bubble
D) swap
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
37
The individual variables that comprise an array are called __________
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
38
What is wrong with the following code?
Float scores[10], total;

A) Cannot declare regular and array variables together.
B) Arrays must be integers
C) The 10 should be replaced with a variable name, whose value is input from the user
D) Nothing.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
39
Why should you use a named constant for the size of an array?

A) Readability of code
B) Makes changes to the program easier
C) Helps reduce logic errors
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
40
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
B) garbage
C) 0.0
D) '0'
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
41
If you need a function that will handle multi-dimensional arrays, you must specify the following sizes inside the square brackets.

A) All the sizes
B) All sizes except the last dimension
C) All sizes except the first dimension
D) None of the sizes
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
42
Which of the following correctly uses C++11's range-based for statement to iterate through every element of the array variable arr?

A) for auto x : arr)
B) foreach x in arr)
C) for auto x; x < arr.length; x++)
D) for x in arr
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
43
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) array1=array2;
B) array1[]=array2;
C) fori=0;iD) fori=0;i
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
44
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int &element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;

A) 1 2 3
B) 11 12 13
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
45
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[];
C) cin >> array[SIZE];
D) fori=0;i> array[i];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
46
Which of the following function declarations will accept the following two-dimension array?
Int pages[10][30];

A) void f1int pages[][], int size);
B) void f1int pages[][30], int size);
C) void f1int pages[10][], int size);
D) void f1int& pages, int size);
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
47
What is the output of this code?
Int arr[] = { 1, 2, 3};
For int element : arr)
Element+=10;
For int element : arr)
Cout << element << endl;

A) 1 2 3
B) 11 12 13
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
48
Which of the following correctly declare an array that can hold up to 3 rows of 5 columns of doubles?

A) int array[3],[5];
B) int array[3][5];
C) float array[3][5];
D) float array[3,5];
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 48 في هذه المجموعة.