Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Programming Fundamentals Exit Exam (2)

The document is a sample exit exam for a programming fundamentals course, containing multiple-choice questions related to programming concepts, C++ syntax, and array operations. Each question is followed by the correct answer and a brief explanation. Topics covered include array indexing, program output, loop behavior, data types, and preprocessor directives.

Uploaded by

Alemseged Mammo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Programming Fundamentals Exit Exam (2)

The document is a sample exit exam for a programming fundamentals course, containing multiple-choice questions related to programming concepts, C++ syntax, and array operations. Each question is followed by the correct answer and a brief explanation. Topics covered include array indexing, program output, loop behavior, data types, and preprocessor directives.

Uploaded by

Alemseged Mammo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

CPU Business and Information Technology College

Department of Computer Science


Fundamentals of Programming
Sample Exit Exam
_____1 If we stored five elements or data items in an array, what will be the index address or the
index number of the array's last data item?
a. 3 b.5 c.4 d.6
______2.What is the output of this program?
1. #include <iostream.h>

2. int main()
3. {
4. int a = 10,i=0 ;
5. if (a < 10) {
6. for (; i < 10; i++)
7. cout << i;
8. }
9. else {
10. cout << i;
11. }
12. return 0;
13. }
a. 0123456789 b. 123456789 c.0 d. None of the above
______3.What is the output of this program?
1. #include <iostream.h>
2. int main ()
3. {
4. int n;
5. for (n = 5; n > 0; n--)
6. {
7. cout << n;
8. if (n == 3)
9. break;
10. }
11. return 0;
12. }
a) 543 b) 54 c) 5432 d) 53
______4.What is the output of this program?
1. #include <iostream>
2. int main()
3. {
4. int a;
5. int b,g;
6. b = 20;
7. a = 35;
8. g = 65;
9. cout << ++b << a<<g;
10. a = 50;
11. cout << ++a << g++;
12. return 0;
13. }
a) 2135655165 b) 2035655035 c) 2035635065 d) None
_____5.A do-loop is different from a while loop because
a) Do-loops have a preset number of cycles for looping.
b) The code in a do-loop is executed at least one time.
c) While loops will only check the condition after each pass.
d) The break statement works in while-loops but not in do-loops
______6.You wants to display "too short" if height is less than 4 and "okay" otherwise. Your
best choice is to use a(n)
a) for-loop b) switch-statement c) if/else-statement d)array
Use the sales array to answer review questions 6 through 10. The array was declared using
int sales [2][5] = {{10000,12000,900,500,20000},{350,600,700,800,100}}; statement.

___7. The statement sales[1][3] = sales[1][3] + 10; will replace the number ________
a.900 with 910
b. 500 with 510
c.700 with 710
d. 800 with 810
___8.The statement sales [0][4] = sales [0][4-2]; will replace the number ___________
a.20000 with 900
b. 20000 with 19998
c.20000 with 19100
d. 500 with 12000
___9. The statement cout<<sales [0][3] + sales[1][3]<<endl; will ______
a. Display 1300
b. Display 1600
c. Display sales[0][3] + sales[1][3]
d. Result in an error
___10.Which of the following if clause verifies that the array subscripts stored in the row and col
variables are valid for the sales array?
a. if sales[row][col]>=0 && sales[row][col] < 5)
b. if (sales[row][col] >=0 && sales[row][col] <=5)
c. if(row>=0 && row<=3 && col>=0 && col<6)
d. if(row >=0 && row<=1 && col>=0 && col<=4)
___11. Which of the following is a correct identifier in C++?
a. VAR_1234
b. $var_name
c. 7VARNAME
d. 7var_name
___12. Which of the following correctly declares an array in C++?
a. array{10};
b. array array[10];
c. int array;
d. int array[10];
___13. Which of the following symbol is used to declare the preprocessor directives in C++?
a. $ b. ^ c. # d. *
___14. What will be the output of the following C++ code snippet?
1. #include<iostream>
2. using namespace std;
3. int main ()
4. {
5. int array[] = {0, 2, 4, 6, 7, 5, 3};
6. int n, result = 0;
7. for (n = 0; n < 6; n++)
8. {
9. result += array[n];
10. }
11. cout << result;
12. return 0;
13. }
a.21 b. 27 c. 26 d. 25
____15. How many times will the computer process the cout<<numtimes<<endl; statement in
the following code?
int numtimes = 0;
while (numtimes <=9)
{
cout<<numtimes<<endl;
numtimes = numtimes + 1;
}
a. 9 b. 10 c. 3 d.4
____16. How many times will the computer process the cout<<numtimes<<endl; statement in
the following code?
for (int numtimes = 1; numtimes < 6 ; numtimes = numtimes +2)
cout<<numtimes<<endl;
a. 0 b.1 c.3 d.4
______17. The value 132.54 can represented using which data type?
a. double b. void c. int d. bool
______18. Evaluate the following
(true && true) || false || false
a. 0 b. 1 c. false d. none of the mentioned
_______19. What will be output of this program?
1. #include <iostream.h>
2. int main()
3. {
4. int i = 4;
5. int l = i / 2;
6. int k = i % 9;
7. cout << l << k;
8. return 0;
9. }
a. no output b. 2 4 c. 1 0 d. None of the above
______20.What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int a, b, c;
6. a = 2;
7. b = 7;
8. c = (a > b) ? a : b;
9. cout << c;
10. return 0;
11. }

a.12 b. 14 c. 6 d. 7
______21.What is a array?
a. An array is a series of elements of the same type in contiguous memory locations
b. An array is a series of element of the different type in contiguous memory
locations
c. An array is a series of elements of the same type placed in non-contiguous memory
locations
d. None of the mentioned
____22.What number will the following code display on the computer screen?
int sum = 0, y = 0;
do
{
sum = 0;
for (int x = 1; x<=5;x = x +1)
sum = sum + x;
y= y + 1;
} while(y < 3);
a. 5 b.8 c.15 d.30
_____23. 90 % 10 evaluates to
a. 0 b.9 c.2 d. 3
_____24.Which of the following statements will not affect the value of x?
a. X++
b. X += X --;
c. X = X++;
d. X = --X+1;

Here are the answers to each of the multiple-choice questions:


1. If we stored five elements or data items in an array, what will be the index address or the index
number of the array's last data item?

 Answer: c. 4
(Array indices are zero-based, so for an array of 5 elements, the last index is 4.)

2. What is the output of this program?

cpp
CopyEdit
#include <iostream.h>

int main() {
int a = 10, i = 0;
if (a < 10) {
for (; i < 10; i++)
cout << i;
}
else {
cout << i;
}
return 0;
}

 Answer: c. 0
(Since a is 10, which is not less than 10, the else block is executed, printing the value of
i, which is 0.)

3. What is the output of this program?

cpp
CopyEdit
#include <iostream.h>
int main() {
int n;
for (n = 5; n > 0; n--) {
cout << n;
if (n == 3)
break;
}
return 0;
}

 Answer: d. 53
(The loop will print 5 and 4, and when n becomes 3, the break statement is executed,
printing 3 and stopping the loop.)
4. What is the output of this program?

cpp
CopyEdit
#include <iostream>
int main() {
int a;
int b, g;
b = 20;
a = 35;
g = 65;
cout << ++b << a << g;
a = 50;
cout << ++a << g++;
return 0;
}

 Answer: b) 2035655035
(The program outputs ++b (21), a (35), and g (65). Then, a is updated to 51, and g++
increments g to 66 after printing.)

5. A do-loop is different from a while loop because:

 Answer: b) The code in a do-loop is executed at least one time.


(In a do-loop, the condition is checked after the loop body, ensuring the code is executed
at least once.)

6. You want to display "too short" if height is less than 4 and "okay" otherwise. Your best choice
is to use a(n):

 Answer: c) if/else-statement
(An if/else statement is ideal for this condition.)

7. The statement sales[1][3] = sales[1][3] + 10; will replace the number:

 Answer: d. 800 with 810


(sales[1][3] refers to the number 800, and adding 10 gives 810.)

8. The statement sales[0][4] = sales[0][4-2]; will replace the number:


 Answer: a. 20000 with 900
(sales[0][4-2] refers to sales[0][2], which is 900, and it replaces 20000.)

9. The statement cout << sales[0][3] + sales[1][3] << endl; will:

 Answer: b. Display 1600


(sales[0][3] is 500, and sales[1][3] is 800, so the sum is 500 + 800 = 1600.)

10. Which of the following if clause verifies that the array subscripts stored in the row and col
variables are valid for the sales array?

 Answer: d. if(row >= 0 && row <= 1 && col >= 0 && col <= 4)
(The sales array is a 2x5 array, so valid row values are 0 or 1, and valid col values are 0
through 4.)

11. Which of the following is a correct identifier in C++?

 Answer: a. VAR_1234
(VAR_1234 is a valid identifier in C++.)

12. Which of the following correctly declares an array in C++?

 Answer: d. int array[10];


(This is the correct syntax for declaring an array of 10 integers in C++.)

13. Which of the following symbol is used to declare the preprocessor directives in C++?

 Answer: c. #
(The # symbol is used to declare preprocessor directives like #include.)

14. What will be the output of the following C++ code snippet?

cpp
CopyEdit
#include<iostream>
using namespace std;
int main() {
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0; n < 6; n++) {
result += array[n];
}
cout << result;
return 0;
}

 Answer: c. 26
(The sum of the first 6 elements in the array is 0 + 2 + 4 + 6 + 7 + 5 = 26.)

15. How many times will the computer process the cout << numtimes << endl; statement in
the following code?

cpp
CopyEdit
int numtimes = 0;
while (numtimes <= 9) {
cout << numtimes << endl;
numtimes = numtimes + 1;
}

 Answer: b. 10
(The numtimes variable starts at 0 and is incremented until it reaches 10, so the loop will
run 10 times.)

16. How many times will the computer process the cout << numtimes << endl; statement in
the following code?

cpp
CopyEdit
for (int numtimes = 1; numtimes < 6; numtimes = numtimes + 2)
cout << numtimes << endl;

 Answer: c. 3
(The loop will process numtimes as 1, 3, and 5, so it will run 3 times.)

17. The value 132.54 can be represented using which data type?

 Answer: a. double
(The double data type can represent floating-point numbers like 132.54.)
18. Evaluate the following:

cpp
CopyEdit
(true && true) || false || false

 Answer: b. 1
(The expression evaluates to true, which is equivalent to 1.)

19. What will be output of this program?

cpp
CopyEdit
#include <iostream.h>
int main() {
int i = 4;
int l = i / 2;
int k = i % 9;
cout << l << k;
return 0;
}

 Answer: b. 2 4
(i / 2 is 2 and i % 9 is 4, so the output is 2 and 4.)

20. What will be the output of the following C++ code?

cpp
CopyEdit
#include <iostream>
using namespace std;
int main() {
int a, b, c;
a = 2;
b = 7;
c = (a > b) ? a : b;
cout << c;
return 0;
}

 Answer: d. 7
(The condition (a > b) is false, so c is assigned the value of b, which is 7.)
21. What is an array?

 Answer: a. An array is a series of elements of the same type in contiguous memory


locations
(An array stores elements of the same type in contiguous memory locations.)

22. What number will the following code display on the computer screen?

cpp
CopyEdit
int sum = 0, y = 0;
do {
sum = 0;
for (int x = 1; x <= 5; x = x + 1)
sum = sum + x;
y = y + 1;
} while (y < 3);

 Answer: d. 30
(The inner for loop calculates the sum of numbers from 1 to 5, which is 15. This is
repeated 3 times due to the do-while loop.)

23. 90 % 10 evaluates to:

 Answer: a. 0
(The modulus operator % gives the remainder of the division, and 90 % 10 gives a
remainder of 0.)

24. Which of the following statements will not affect the value of x?

 Answer: c. X = X++;
(The X = X++ statement assigns the value of X to itself after incrementing, so the value of
X does not change.)

Answer Key

1.C 11.A 21.A


2.C 12.D 22.C
3.A 13.C 23.A
4.A 14.B 24.D
5.B 15.B
6.C 16.C
7.A 17.A
8.A 18.B
9.D 19.B
10.D 20.D

You might also like