Question 1: What is the output of the following C++ code? int list[5] = {0, 5, 1
ID: 3557693 • Letter: Q
Question
Question 1: What is the output of the following C++ code?
int list[5] = {0, 5, 10, 15, 20};
int j;
for (j = 1; j <= 5; j++)
cout << list[j];
0 5 10 15 20
5 10 15 20 0
5 10 15 20 20
Code contains index out of bounds
Question 10: In a class, all function members
Question 2: What is the value of alpha[4] after the following code executes?int alpha[5] = {0};
int j;
alpha[0] = 2;
for (j = 1; j < 5; j++)
alpha[j] = alpha[j - 1] + 3; 5
8
11
14
Explanation / Answer
1.(d) Code contains index out of bounds
Expl:- List Size is 5 and list[0] to list[4] is valid, list[5] is invalid
2.(d) 14
3.(d) 10
Expl:- when j=3 then alpha[3]=3+8
but when j=2 then alpha[2+1]=2+5+3=10 (as 2%2=0) so the if condition gets satisfied
4.(b) cin >> alpha[0] >> alpha[1] >> alpha[2];
Expl. Array always starts with an zero index
5.(b) 50
Expl:- Number of rows*number of columns=Number of components
6.(a) list has 10 rows and eight columns.
7.(d) 0 1 2
2 3 4
4 5 6
6 7 8
8.(a) sum = 0;
for(j = 0; j < 10; j++)
sum = sum + sale[j][3];
Expl. sale[j][3] means all the rows of fourth column
9.(b) an object type.
10.(a) must be public and all member variables must be private
Expl:- member functions should be public so that the class object can access them
member variables should be private so that only member functions should access them and not class objects.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.