CS111 Quiz 10

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Started on Sunday, 12 June 2022, 10:04 PM

State Finished
Completed on Sunday, 12 June 2022, 10:10 PM
Time taken 5 mins 52 secs
Mark 1.00 out of 1.00 (100%)
Question 1
Correct
Mark 0.10 out of 0.10

Flag question
Question text
How to declare an array values of type double with 7 elements?

double values[7];
Answer: 
Feedback
The correct answer is: double values[7];

Question 2
Correct
Mark 0.10 out of 0.10

Flag question
Question text
Suppose you want to change the 5th element of array values to value 37. Please
complete the following code:

values[Answer

]=37;

Question 3
Correct
Mark 0.10 out of 0.10

Flag question
Question text
What number will the following code snippet print?
int numbers[8] = { 34, 42, 6, 11, 29, 1, 89, 62};
cout << numbers[7];

62
Answer:
Feedback
The correct answer is: 62

Question 4
Correct
Mark 0.10 out of 0.10

Flag question
Question text
Consider the following code snippet:
const int CAPACITY = 100;
double values[CAPACITY];
int size = 0;
double input;
while (cin >> input){
if (size < CAPACITY){
values[size] = input;
size++;
}
}
Suppose the user enters the values 23, 32, 17, 18, 9, 9, before he enters 'q'
What will be te value of size?

6
Answer:
Feedback
The correct answer is: 6

Question 5
Correct
Mark 0.40 out of 0.40

Flag question
Question text
Which of the following is true or false?
All elements of an array are of the same type. true
Answer 1

Arrays cannot have elements of type char false


Answer 2

Arrays always have at least one element false


Answer 3

An array always has to be initialised.


Answer 4

The size  of an array must be constant. true


Answer 5

The size of an array can be a double. false


Answer 6

The thrid element of an


false
array values is values[3] Answer 7

The elements in an array are always sorted. false


Answer 8
Feedback
The correct answer is: All elements of an array are of the same type. →
true, Arrays cannot have elements of type char → false, Arrays always have at
least one element → false, An array always has to be initialised. → false, The size
of an array must be constant. → true, The size of an array can be a double. →
false, The thrid element of an array values is values[3] → false, The elements in
an array are always sorted. → false

Question 6
Correct
Mark 0.20 out of 0.20

Flag question
Question text
Consider the following code snippet
1 const int N = 5;
2 double pops[N] = {23,12};
3 for(int i=0; i<=N;i++){
4 cout << pops[i] << endl;
5 }
Which of the following statements is true about line 2 and line 3?
Line 2 is correct
Answer 1

Line 3 has an array bounds error. Counter i should be strictly less than N.
Answer 2
Feedback
The correct answer is: Line 2 → is correct, Line 3 → has an array bounds error.
Counter i should be strictly less than N.

You might also like